diff --git a/Makefile b/Makefile index 0661c554e1a..37c751acfde 100644 --- a/Makefile +++ b/Makefile @@ -147,9 +147,13 @@ libuninstall: $(OPAMLIBS:%=uninstalllib-%) uninstall: opam-actual.install $(OPAMINSTALLER) -u $(OPAMINSTALLER_FLAGS) $< +checker: + $(JBUILDER) build src/tools/opam_check.exe + .PHONY: tests tests-local tests-git tests: $(JBUILDER_DEP) - $(JBUILDER) runtest $(JBUILDER_ARGS) src/ tests/ + $(JBUILDER) build opam.install src/tools/opam_check.exe + $(JBUILDER) runtest --force --no-buffer $(JBUILDER_ARGS) src/ tests/ # tests-local, tests-git tests-%: diff --git a/configure b/configure index 04835f3b597..00eaaa432f9 100755 --- a/configure +++ b/configure @@ -4945,7 +4945,7 @@ if test "x${enable_checks}" != "xno" && { test "x$OCAML_PKG_cppo" = "xno" || test "x$OCAML_PKG_mccs$MCCS_ENABLED$MCCS_DEFAULT" = "xnotrue"; }; then : - if test "x$MCCS_ENABLED" = "xtrue"; then : + if test "x$MCCS_ENABLED" = "xtrue" -a "x${CCOMP_TYPE}" != "xmsvc"; then : ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' diff --git a/configure.ac b/configure.ac index 122b0807e79..9b8f008b9af 100644 --- a/configure.ac +++ b/configure.ac @@ -307,7 +307,7 @@ AS_IF([test "x${enable_checks}" != "xno" && { test "x$OCAML_PKG_opam_file_format" = "xno" || test "x$OCAML_PKG_cppo" = "xno" || test "x$OCAML_PKG_mccs$MCCS_ENABLED$MCCS_DEFAULT" = "xnotrue"; }],[ - AS_IF([test "x$MCCS_ENABLED" = "xtrue"],[ + AS_IF([test "x$MCCS_ENABLED" = "xtrue" -a "x${CCOMP_TYPE}" != "xmsvc"],[ AC_PROG_CXX # Curiously, CXX=g++ && GXX= seems to be how autoconf "signals" that no C++ # compiler was found. diff --git a/src/core/opamCompat.ml b/src/core/opamCompat.ml index b36865d6248..d3ba4b74c21 100644 --- a/src/core/opamCompat.ml +++ b/src/core/opamCompat.ml @@ -92,3 +92,20 @@ struct | _ -> assert false end #endif + +module Filename = +#if OCAML_VERSION >= (4, 4, 0) + Filename +#else +struct + include Filename + + let extension fn = + match Filename.chop_extension fn with + | base -> + let l = String.length base in + String.sub fn l (String.length fn - l) + | exception Invalid_argument _ -> + "" +end +#endif diff --git a/src/core/opamCompat.mli b/src/core/opamCompat.mli index a20d749a262..2e6a51ae49a 100644 --- a/src/core/opamCompat.mli +++ b/src/core/opamCompat.mli @@ -78,3 +78,14 @@ module Buffer val add_utf_8_uchar : t -> Uchar.t -> unit end #endif + +module Filename +#if OCAML_VERSION >= (4, 4, 0) += Filename +#else +: sig + include module type of struct include Filename end + + val extension : string -> string +end +#endif diff --git a/src/core/opamConsole.ml b/src/core/opamConsole.ml index 3b4aaf385e7..477193eea54 100644 --- a/src/core/opamConsole.ml +++ b/src/core/opamConsole.ml @@ -209,11 +209,11 @@ let style_code (c: text_style) = match c with (* not nestable *) let colorise style s = if not (color ()) then s else - Printf.sprintf "\027[%sm%s\027[m" (style_code style) s + Printf.sprintf "\027[%sm%s\027[0m" (style_code style) s let colorise' styles s = if not (color ()) then s else - Printf.sprintf "\027[%sm%s\027[m" + Printf.sprintf "\027[%sm%s\027[0m" (String.concat ";" (List.map style_code styles)) s diff --git a/src/core/opamFilename.ml b/src/core/opamFilename.ml index f003ec5f9ec..0e37ba25bf2 100644 --- a/src/core/opamFilename.ml +++ b/src/core/opamFilename.ml @@ -9,7 +9,15 @@ (* *) (**************************************************************************) -module Base = OpamStd.AbstractString +module Base = struct + include OpamStd.AbstractString + + let check_suffix filename s = + Filename.check_suffix filename s + + let add_extension filename suffix = + filename ^ "." ^ suffix +end let log fmt = OpamConsole.log "FILENAME" fmt let slog = OpamConsole.slog diff --git a/src/core/opamFilename.mli b/src/core/opamFilename.mli index c65c8bdfe8f..d216b7bfd0c 100644 --- a/src/core/opamFilename.mli +++ b/src/core/opamFilename.mli @@ -13,7 +13,15 @@ wrappers on OpamSystem using the filename type *) (** Basenames *) -module Base: OpamStd.ABSTRACT +module Base: sig + include OpamStd.ABSTRACT + + (** Check whether a basename has a given suffix *) + val check_suffix: t -> string -> bool + + (** Add a file extension *) + val add_extension: t -> string -> t +end (** Directory names *) module Dir: OpamStd.ABSTRACT diff --git a/src/core/opamStd.ml b/src/core/opamStd.ml index 522a5abb256..16229317b05 100644 --- a/src/core/opamStd.ml +++ b/src/core/opamStd.ml @@ -351,6 +351,10 @@ module Option = struct | None -> None | Some x -> f x + let map_default f dft = function + | None -> dft + | Some x -> f x + let compare cmp o1 o2 = match o1,o2 with | None, None -> 0 | Some _, None -> 1 diff --git a/src/core/opamStd.mli b/src/core/opamStd.mli index 65a89ee3c91..86b8e40048d 100644 --- a/src/core/opamStd.mli +++ b/src/core/opamStd.mli @@ -129,6 +129,8 @@ module Option: sig val replace : ('a -> 'b option) -> 'a option -> 'b option + val map_default: ('a -> 'b) -> 'b -> 'a option -> 'b + val compare: ('a -> 'a -> int) -> 'a option -> 'a option -> int val to_string: ?none:string -> ('a -> string) -> 'a option -> string diff --git a/src/core/opamSystem.ml b/src/core/opamSystem.ml index 0cb46909d49..8385ad321ae 100644 --- a/src/core/opamSystem.ml +++ b/src/core/opamSystem.ml @@ -313,10 +313,23 @@ let env_var env var = in aux 0 +let forward_to_back = + if Sys.win32 then + String.map (function '/' -> '\\' | c -> c) + else + fun x -> x + +let back_to_forward = + if Sys.win32 then + String.map (function '\\' -> '/' | c -> c) + else + fun x -> x + (* OCaml 4.05.0 no longer follows the updated PATH to resolve commands. This makes unqualified commands absolute as a workaround. *) let resolve_command = let is_external_cmd name = + let name = forward_to_back name in OpamStd.String.contains_char name Filename.dir_sep.[0] in let check_perms = @@ -349,9 +362,9 @@ let resolve_command = let name = if Filename.check_suffix name ".exe" then name else name ^ ".exe" in - OpamStd.List.find_opt (fun path -> + OpamStd.(List.find_opt (fun path -> check_perms (Filename.concat path name)) - path + path |> Option.map (fun path -> Filename.concat path name)) else let cmd, args = "/bin/sh", ["-c"; Printf.sprintf "command -v %s" name] in let r = diff --git a/src/core/opamSystem.mli b/src/core/opamSystem.mli index 8bfea4ba4f3..b3020133196 100644 --- a/src/core/opamSystem.mli +++ b/src/core/opamSystem.mli @@ -268,3 +268,9 @@ val register_printer: unit -> unit lib may not perform properly without this if [Sys.catch_break] isn't set and SIGPIPE isn't handled (with a no-op) *) val init: unit -> unit + +(** On Unix, a no-op. On Windows, convert / to \ *) +val forward_to_back : string -> string + +(** On Unix, a no-op. On Windows, convert \ to / *) +val back_to_forward : string -> string diff --git a/src/core/opamUrl.ml b/src/core/opamUrl.ml index 4778e5b0951..d2e2115dfa0 100644 --- a/src/core/opamUrl.ml +++ b/src/core/opamUrl.ml @@ -141,7 +141,7 @@ let parse ?backend ?(handle_suffix=true) s = | _, (None | Some ("git"|"hg"|"darcs")), Some path -> "ssh", path | _, (None | Some ("hg"|"darcs")), None -> - "file", OpamSystem.real_path path + "file", OpamSystem.real_path path |> OpamSystem.back_to_forward | _, Some tr, _ -> tr, path in @@ -222,7 +222,14 @@ let basename = let root = let re = Re.(compile @@ seq [char '/'; rep any]) in fun t -> - { t with path = Re.replace_string re ~by:"" t.path } + let path = + (* The special-casing of "file" is needed for Windows *) + if t.transport = "file" then + "" + else + Re.replace_string re ~by:"" t.path + in + { t with path} let has_trailing_slash url = OpamStd.String.ends_with ~suffix:"/" url.path @@ -247,13 +254,16 @@ module Op = struct (** appending to an url path *) let ( / ) url dir = let url = - if OpamStd.String.starts_with ~prefix:"/" dir then + if Filename.is_relative dir then + url + else root url - else url in + (* Even on Windows, a file:// _should_ use slash *) + let dir = OpamSystem.back_to_forward dir in let path = - if has_trailing_slash url then url.path ^ dir - else String.concat "/" [url.path; dir] + if has_trailing_slash url || url.path = "" then url.path ^ dir + else url.path ^ "/" ^ dir in {url with path } diff --git a/src/tools/jbuild b/src/tools/jbuild index d20d995f7f9..f3bd1b6327c 100644 --- a/src/tools/jbuild +++ b/src/tools/jbuild @@ -15,7 +15,7 @@ ((name opam_check) (modules (opam_check)) (flags (:standard (:include ../ocaml-flags-standard.sexp) (:include ../ocaml-context-flags.sexp))) - (libraries (opam-client)))) + (libraries (opam-state)))) (include opam-putenv.inc) diff --git a/src/tools/opam_check.ml b/src/tools/opam_check.ml index e1df59ac701..b20ff65753d 100644 --- a/src/tools/opam_check.ml +++ b/src/tools/opam_check.ml @@ -34,7 +34,6 @@ let () = OpamStd.Config.init(); OpamFormatConfig.init(); OpamRepositoryConfig.init(); - OpamSolverConfig.init(); OpamStateConfig.init ?root_dir () diff --git a/tests/Makefile b/tests/Makefile index 9c11ef28185..e788cf40cdc 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -14,7 +14,7 @@ PACKAGES = P1-0 P1-1 P1-2 P2 P3 P4 P5 unexport OCAMLLIB ifndef OPAM - OPAM = $(firstword $(realpath ../src/client/opamMain.exe ../_build/default/src/client/opamMain.exe)) + OPAM = $(firstword $(realpath ../../install/default/bin/opam$(EXE) ../_build/install/default/bin/opamMain.exe)) endif ENV = PATH=$(PATH) $(DEBUG) OPAMKEEPBUILDDIR=1 OPAMROOT=$(OPAM_ROOT) OPAMSWITCH= OPAMNOBASEPACKAGES=1 OPAMYES=1 OPAM=$(OPAM) OPAMBIN = $(ENV) $(OPAM) @@ -43,14 +43,14 @@ printf = /usr/bin/printf define RUN @COUNT=$$(ls -1 $(REPOKIND)-*.log 2>/dev/null | wc -l); \ LOG=$$($(printf) "$(REPOKIND)-%02d-$(1).log" $$COUNT); \ -$(printf) " %02d \e[1m%-20s\e[m ..................................... " \ +$(printf) " %02d \e[1m%-20s\e[0m ..................................... " \ $$COUNT $(1); \ if $(MAKE) $(1) >$$LOG 2>&1; then \ - $(printf) "\e[32m[ OK ]\e[m\n"; \ + $(printf) "\e[32m[ OK ]\e[0m\n"; \ else \ - $(printf) "\e[31m$(1) FAILED\e[m\n\n" >>$$LOG; \ - $(printf) "\e[31m[FAIL]\e[m\n"; \ - { $(printf) "\e[31m>> %s FAILED <<\e[m\n" $(1); cat $$LOG; } \ + $(printf) "\e[31m$(1) FAILED\e[0m\n\n" >>$$LOG; \ + $(printf) "\e[31m[FAIL]\e[0m\n"; \ + { $(printf) "\e[31m>> %s FAILED <<\e[0m\n" $(1); cat $$LOG; } \ >> failed-$(REPOKIND).log; \ fi; \ cat $$LOG >> fulltest-$(REPOKIND).log @@ -85,20 +85,23 @@ run: else echo "SUCCESS!"; fi local: - $(MAKE) clean - $(MAKE) REPOKIND=local run + @$(MAKE) --silent --no-print-directory clean + $(MAKE) --no-print-directory REPOKIND=local run git: - $(MAKE) clean - $(MAKE) REPOKIND=git run + @$(MAKE) --silent --no-print-directory clean + $(MAKE) --no-print-directory REPOKIND=git run + +define GIT_INIT + git init && echo '*.sh text eol=lf'> .gitattributes && $(if $1,touch $1 && )\ + git add -A && git commit -m "Initial commit" +endef init: rm -rf $(OPAM_REPO) mkdir -p $(OPAM_REPO) ifeq ($(REPOKIND), git) - cd $(OPAM_REPO) && git init && \ - touch README && git add README && \ - git commit -a -m "Initial commit" + cd $(OPAM_REPO) && $(call GIT_INIT,README) endif $(OPAMBIN) init --bare --no-setup $(REPO) $(OPAM_REPO) -k $(REPOKIND) @@ -133,21 +136,21 @@ upload: $(ARCHIVES) cp packages/P5/README $(OPAM_REPO)/packages/P5.1/descr $(call mkurl,P5.1,P5.tar.gz) ifeq ($(REPOKIND), git) - cd $(OPAM_REPO)/packages/ocaml.system && git add * && git commit -a -m "Adding ocaml.system" - cd $(OPAM_REPO)/packages/ocaml.20 && git add * && git commit -a -m "Adding ocaml.20" - cd $(OPAM_REPO)/packages/ocaml.10+a+b && git add * && git commit -a -m "Adding ocaml.10+a+b" + cd $(OPAM_REPO)/packages/ocaml.system && git add * && git commit -m "Adding ocaml.system" + cd $(OPAM_REPO)/packages/ocaml.20 && git add * && git commit -m "Adding ocaml.20" + cd $(OPAM_REPO)/packages/ocaml.10+a+b && git add * && git commit -m "Adding ocaml.10+a+b" echo 'git: "$(OPAM_GIT)/P1-0"' > $(OPAM_REPO)/packages/P1.0/url - cd $(OPAM_REPO)/packages/P1.0/ && git add * && git commit -a -m "Adding P0" + cd $(OPAM_REPO)/packages/P1.0/ && git add * && git commit -m "Adding P0" echo 'git: "$(OPAM_GIT)/P1-1"' > $(OPAM_REPO)/packages/P1.1/url - cd $(OPAM_REPO)/packages/P1.1/ && git add * && git commit -a -m "Adding P1" + cd $(OPAM_REPO)/packages/P1.1/ && git add * && git commit -m "Adding P1" echo 'git: "$(OPAM_GIT)/P2"' > $(OPAM_REPO)/packages/P2.1/url - cd $(OPAM_REPO)/packages/P2.1/ && git add * && git commit -a -m "Adding P2" + cd $(OPAM_REPO)/packages/P2.1/ && git add * && git commit -m "Adding P2" echo 'git: "$(OPAM_GIT)/P3"' > $(OPAM_REPO)/packages/P3.1~weird-version.test/url - cd $(OPAM_REPO)/packages/P3.1~weird-version.test/ && git add * && git commit -a -m "Adding P3" + cd $(OPAM_REPO)/packages/P3.1~weird-version.test/ && git add * && git commit -m "Adding P3" echo 'git: "$(OPAM_GIT)/P4"' > $(OPAM_REPO)/packages/P4.1/url - cd $(OPAM_REPO)/packages/P4.1/ && git add * && git commit -a -m "Adding P4" + cd $(OPAM_REPO)/packages/P4.1/ && git add * && git commit -m "Adding P4" echo 'git: "$(OPAM_GIT)/P5"' > $(OPAM_REPO)/packages/P5.1/url - cd $(OPAM_REPO)/packages/P5.1/ && git add * && git commit -a -m "Adding P5" + cd $(OPAM_REPO)/packages/P5.1/ && git add * && git commit -m "Adding P5" rm -rf $(OPAM_GIT) && mkdir -p $(OPAM_GIT) mkdir $(OPAM_GIT)/P1-0 && cp packages/P1-0/* $(OPAM_GIT)/P1-0/ mkdir $(OPAM_GIT)/P1-1 && cp packages/P1-1/* $(OPAM_GIT)/P1-1/ @@ -155,12 +158,12 @@ ifeq ($(REPOKIND), git) mkdir $(OPAM_GIT)/P3 && cp packages/P3/* $(OPAM_GIT)/P3/ mkdir $(OPAM_GIT)/P4 && cp packages/P4/* $(OPAM_GIT)/P4/ mkdir $(OPAM_GIT)/P5 && cp packages/P5/* $(OPAM_GIT)/P5/ - cd $(OPAM_GIT)/P1-0 && git init && git add * && git commit -a -m "initial commit" - cd $(OPAM_GIT)/P1-1 && git init && git add * && git commit -a -m "initial commit" - cd $(OPAM_GIT)/P2 && git init && git add * && git commit -a -m "initial commit" - cd $(OPAM_GIT)/P3 && git init && git add * && git commit -a -m "initial commit" - cd $(OPAM_GIT)/P4 && git init && git add * && git commit -a -m "initial commit" - cd $(OPAM_GIT)/P5 && git init && git add * && git commit -a -m "initial commit" + cd $(OPAM_GIT)/P1-0 && $(call GIT_INIT) + cd $(OPAM_GIT)/P1-1 && $(call GIT_INIT) + cd $(OPAM_GIT)/P2 && $(call GIT_INIT) + cd $(OPAM_GIT)/P3 && $(call GIT_INIT) + cd $(OPAM_GIT)/P4 && $(call GIT_INIT) + cd $(OPAM_GIT)/P5 && $(call GIT_INIT) else mkdir -p $(OPAM_REPO)/cache for p in P1-0 P1-1 P1-2 P2 P3 P4 P5; do \ @@ -244,7 +247,7 @@ ifeq ($(REPOKIND), git) cd $(OPAM_GIT)/P1-1 && git commit -a -m "a small change" echo 'git: "$(OPAM_GIT)/P4"' > $(OPAM_REPO)/packages/P4.2/url echo 'git: "$(OPAM_GIT)/P4"' > $(OPAM_REPO)/packages/P4.3/url - cd $(OPAM_REPO) && git add * && git commit -a -m "Adding P4.2 and P4.3" + cd $(OPAM_REPO) && git add * && git commit -m "Adding P4.2 and P4.3" else mkdir $(OPAM_REPO)/packages/P1.2 cp packages/P1-2.opam $(OPAM_REPO)/packages/P1.2/opam diff --git a/tests/packages/P1-1/P1.config.in b/tests/packages/P1-1/P1.config.in index d03f93eee3f..b2631b7dc15 100644 --- a/tests/packages/P1-1/P1.config.in +++ b/tests/packages/P1-1/P1.config.in @@ -1,8 +1,11 @@ -asmcomp: "-I %{lib}%/P1" -bytecomp: "-I %{lib}%/P1" -asmlink: "-I %{lib}%/P1 p1.cmxa" -bytelink: "-I %{lib}%/P1 p1.cma" -LOCAL: "local" -l: "L" -FOO: "foo" -bar: true +opam-version: "1.3" +variables { + asmcomp: "-I %{lib}%/P1" + bytecomp: "-I %{lib}%/P1" + asmlink: "-I %{lib}%/P1 p1.cmxa" + bytelink: "-I %{lib}%/P1 p1.cma" + LOCAL: "local" + l: "L" + FOO: "foo" + bar: true +} diff --git a/tests/packages/P1-2/P1.config.in b/tests/packages/P1-2/P1.config.in index 156e8332eb0..b2631b7dc15 100644 --- a/tests/packages/P1-2/P1.config.in +++ b/tests/packages/P1-2/P1.config.in @@ -1,8 +1,11 @@ -asmcomp: "-I %{lib}%/P1" -bytecomp: "-I %{lib}%/P1" -asmlink: "-I %{lib}%/P1 p1.cmxa" -bytelink: "-I %{lib}%/P1 p1.cma" -LOCAL: "local" -l: "L" -FOO: "foo" -bar: true \ No newline at end of file +opam-version: "1.3" +variables { + asmcomp: "-I %{lib}%/P1" + bytecomp: "-I %{lib}%/P1" + asmlink: "-I %{lib}%/P1 p1.cmxa" + bytelink: "-I %{lib}%/P1 p1.cma" + LOCAL: "local" + l: "L" + FOO: "foo" + bar: true +} diff --git a/tests/packages/P2/P2.config.in b/tests/packages/P2/P2.config.in index 2989fe7837f..c1eee4a3398 100644 --- a/tests/packages/P2/P2.config.in +++ b/tests/packages/P2/P2.config.in @@ -1,5 +1,8 @@ -asmcomp: "-I %{lib}%/P2" -bytecomp: "-I %{lib}%/P2" -asmlink: "-I %{lib}%/P2 p2.cmxa" -bytelink: "-I %{lib}%/P2 p2.cma" -requires: "p1" +opam-version: "1.3" +variables { + asmcomp: "-I %{lib}%/P2" + bytecomp: "-I %{lib}%/P2" + asmlink: "-I %{lib}%/P2 p2.cmxa" + bytelink: "-I %{lib}%/P2 p2.cma" + requires: "p1" +} diff --git a/tests/packages/P3/P3.config.in b/tests/packages/P3/P3.config.in index d09e8dade8c..e764425d2df 100644 --- a/tests/packages/P3/P3.config.in +++ b/tests/packages/P3/P3.config.in @@ -1,5 +1,8 @@ -asmcomp : "-I %{lib}%/P3" -bytecomp: "-I %{lib}%/P3" -asmlink : "-I %{lib}%/P3 p3.cmxa p3_bar.cmxa" -bytelink: "-I %{lib}%/P3 p3.cma p3_bar.cma" -requires: "p1" +opam-version: "1.3" +variables { + asmcomp : "-I %{lib}%/P3" + bytecomp: "-I %{lib}%/P3" + asmlink : "-I %{lib}%/P3 p3.cmxa p3_bar.cmxa" + bytelink: "-I %{lib}%/P3 p3.cma p3_bar.cma" + requires: "p1" +}