Skip to content

Commit

Permalink
Add a way to execute tests and build documentation.
Browse files Browse the repository at this point in the history
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 ocaml#249
  • Loading branch information
samoht committed Dec 21, 2012
1 parent f117106 commit ca87999
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 14 deletions.
18 changes: 15 additions & 3 deletions src/client/opamMain.ml
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
33 changes: 23 additions & 10 deletions src/client/opamSolution.ml
Expand Up @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion src/core/opamFile.ml
Expand Up @@ -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 = {
Expand All @@ -585,6 +587,8 @@ module OPAM = struct
authors = [];
license = None;
doc = None;
build_test = [];
build_doc = [];
}
let create nv =
Expand Down Expand Up @@ -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;
Expand All @@ -632,6 +638,8 @@ module OPAM = struct
s_authors;
s_homepage;
s_doc;
s_build_test;
s_build_doc;
]
let valid_fields =
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/core/opamFile.mli
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/core/opamGlobals.ml
Expand Up @@ -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"
Expand Down

0 comments on commit ca87999

Please sign in to comment.