Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various bits 'n bobs #3346

Merged
merged 13 commits into from
May 15, 2018
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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-%:
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions src/core/opamCompat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions src/core/opamCompat.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/core/opamConsole.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion src/core/opamFilename.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/core/opamFilename.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/core/opamStd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/core/opamStd.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions src/core/opamSystem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down
6 changes: 6 additions & 0 deletions src/core/opamSystem.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 16 additions & 6 deletions src/core/opamUrl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion src/tools/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion src/tools/opam_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ let () =
OpamStd.Config.init();
OpamFormatConfig.init();
OpamRepositoryConfig.init();
OpamSolverConfig.init();
OpamStateConfig.init
?root_dir
()
Expand Down
61 changes: 32 additions & 29 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -133,34 +136,34 @@ 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/
mkdir $(OPAM_GIT)/P2 && cp packages/P2/* $(OPAM_GIT)/P2/
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 \
Expand Down Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions tests/packages/P1-1/P1.config.in
Original file line number Diff line number Diff line change
@@ -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
}
Loading