Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a way to execute tests and build documentation.

it's:
* OPAMBUILDTEST=1 or --build-test
* OPAMBUILDOC=1 or --build-doc

OPAM will run:
1/ the commands in build
2/ the commands in test (if the right flag is enabled)
3/ the commands in doc (if the right flag is enabled)
4/ will copy the files specified in <package>.install in the right place

So this means that the doc command need to either install the pages itself, or the .install file should be correct.

This should fix #249
  • Loading branch information...
commit ca879991342db87ec2adb07cf795f139ce4bdf72 1 parent f117106
@samoht samoht authored
View
18 src/client/opamMain.ml
@@ -43,14 +43,18 @@ type build_options = {
keep_build_dir: bool;
make : string option;
no_checksums : bool;
+ build_test : bool;
+ build_doc : bool;
}
-let create_build_options keep_build_dir make no_checksums =
- { keep_build_dir; make; no_checksums }
+let create_build_options keep_build_dir make no_checksums build_test build_doc =
+ { keep_build_dir; make; no_checksums; build_test; build_doc }
let set_build_options b =
OpamGlobals.keep_build_dir := !OpamGlobals.keep_build_dir || b.keep_build_dir;
OpamGlobals.no_checksums := !OpamGlobals.no_checksums || b.no_checksums;
+ OpamGlobals.build_test := !OpamGlobals.build_test || b.build_test;
+ OpamGlobals.build_doc := !OpamGlobals.build_doc || b.build_doc;
match b.make with
| None -> ()
| Some s -> OpamGlobals.makecmd := lazy s
@@ -247,11 +251,19 @@ let build_options =
mk_flag ["n";"no-checksums"]
"Do not verify the checksum of downloaded archives. \
This is equivalent to setting $(b,\\$OPAMNOCHECKSUMS) to a non-empty string." in
+ let build_test =
+ mk_flag ["t";"build-test"]
+ "Build and $(b,run) the package unit-tests.
+ This is equivalent to setting $(b,\\$OPAMBUILDTEST) to a non-empty string." in
+ let build_doc =
+ mk_flag ["d";"build-doc"]
+ "Build the package documentation.
+ This is equivalent to setting $(b,\\$OPAMBUILDDOC) to a non-empty string." in
let make =
mk_opt ["m";"make"] "MAKE"
"Use $(docv) as the default 'make' command."
Arg.(some string) None in
- Term.(pure create_build_options $keep_build_dir $make $no_checksums)
+ Term.(pure create_build_options $keep_build_dir $make $no_checksums $build_test $build_doc)
let guess_repository_kind kind address =
match kind with
View
33 src/client/opamSolution.ml
@@ -367,20 +367,33 @@ let proceed_to_change t nv_old nv =
let env_f = OpamPath.Switch.build_env t.root t.switch nv in
OpamFile.Env.write env_f env.new_env;
- (* Call the build script and copy the output files *)
- let commands = OpamState.filter_commands t (OpamFile.OPAM.build opam) in
- let commands_s = List.map (fun cmd -> String.concat " " cmd) commands in
- if commands_s <> [] then
- OpamGlobals.msg "Build commands:\n %s\n" (String.concat "\n " commands_s)
- else
- OpamGlobals.msg "Nothing to do.\n";
- try
+ (* Exec the given commands. *)
+ let exec name f =
+ let commands = OpamState.filter_commands t (f opam) in
+ let commands_s = List.map (fun cmd -> String.concat " " cmd) commands in
+ if commands_s <> [] then
+ OpamGlobals.msg "%s:\n %s\n" name (String.concat "\n " commands_s)
+ else
+ OpamGlobals.msg "Nothing to do.\n";
OpamFilename.exec
~add_to_env:env.add_to_env
~add_to_path:[env.add_to_path]
p_build
- commands;
- proceed_to_install t nv;
+ commands in
+ try
+ (* First, we build the package. *)
+ exec "Building the package" OpamFile.OPAM.build;
+
+ (* If necessary, build and run the test. *)
+ if !OpamGlobals.build_test then
+ exec "Building and running the test" OpamFile.OPAM.build_test;
+
+ (* If necessary, build the documentation. *)
+ if !OpamGlobals.build_doc then
+ exec "Generating the documentation" OpamFile.OPAM.build_doc;
+
+ (* If everyting went fine, finally install the package. *)
+ proceed_to_install t nv;
with e ->
(* We keep the build dir to help debugging *)
proceed_to_delete ~rm_build:false t nv;
View
18 src/core/opamFile.ml
@@ -562,6 +562,8 @@ module OPAM = struct
authors : string list;
license : string option;
doc : string option;
+ build_test : command list;
+ build_doc : command list;
}
let empty = {
@@ -585,6 +587,8 @@ module OPAM = struct
authors = [];
license = None;
doc = None;
+ build_test = [];
+ build_doc = [];
}
let create nv =
@@ -612,6 +616,8 @@ module OPAM = struct
let s_authors = "authors"
let s_license = "license"
let s_doc = "doc"
+ let s_build_test = "build-test"
+ let s_build_doc = "build-doc"
let useful_fields = [
s_opam_version;
@@ -632,6 +638,8 @@ module OPAM = struct
s_authors;
s_homepage;
s_doc;
+ s_build_test;
+ s_build_doc;
]
let valid_fields =
@@ -660,6 +668,8 @@ module OPAM = struct
let authors t = t.authors
let license t = t.license
let doc t = t.doc
+ let build_doc t = t.build_doc
+ let build_test t = t.build_test
let with_depends t depends = { t with depends }
let with_depopts t depopts = { t with depopts }
@@ -706,6 +716,8 @@ module OPAM = struct
@ list t.patches s_patches (OpamFormat.make_list make_file)
@ option t.ocaml_version s_ocaml_version OpamFormat.make_compiler_constraint
@ formula t.os s_os OpamFormat.make_os_constraint
+ @ listm t.build_test s_build_test OpamFormat.make_command
+ @ listm t.build_doc s_build_doc OpamFormat.make_command
@ List.map (fun (s, v) -> Variable (s, v)) t.others;
} in
Syntax.to_string
@@ -768,6 +780,8 @@ module OPAM = struct
let authors = OpamFormat.assoc_list s s_authors (OpamFormat.parse_list OpamFormat.parse_string) in
let license = OpamFormat.assoc_option s s_license OpamFormat.parse_string in
let doc = OpamFormat.assoc_option s s_doc OpamFormat.parse_string in
+ let build_test = OpamFormat.assoc_list s s_build_test OpamFormat.parse_commands in
+ let build_doc = OpamFormat.assoc_list s s_build_doc OpamFormat.parse_commands in
let others =
OpamMisc.filter_map (function
| Variable (x,v) -> if List.mem x useful_fields then None else Some (x,v)
@@ -776,7 +790,9 @@ module OPAM = struct
{ name; version; maintainer; substs; build; remove;
depends; depopts; conflicts; libraries; syntax; others;
patches; ocaml_version; os; build_env;
- homepage; authors; license; doc }
+ homepage; authors; license; doc;
+ build_test; build_doc;
+ }
end
module Dot_install_raw = struct
View
6 src/core/opamFile.mli
@@ -138,6 +138,12 @@ module OPAM: sig
(** API documentation *)
val doc: t -> string option
+ (** Commands to build and run the tests *)
+ val build_test: t -> command list
+
+ (** Commands to build the documentation *)
+ val build_doc: t -> command list
+
(** Construct as [depends] *)
val with_depends : t -> formula -> t
View
2  src/core/opamGlobals.ml
@@ -35,6 +35,8 @@ let keep_build_dir = check "KEEPBUILDDIR"
let no_base_packages = check "NOBASEPACKAGES"
let no_checksums = check "NOCHECKSUMS"
let yes = check "YES"
+let build_test = check "BUILDTEST"
+let build_doc = check "BUILDDOC"
let default_repository_name = "default"
let default_repository_address = "http://opam.ocamlpro.com"
Please sign in to comment.
Something went wrong with that request. Please try again.