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

Set log dir as temporary directory on safe mode #6403

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/client/opamArg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ let environment_variables =
backups. This skips some finalisers and may also help to get more \
reliable backtraces.";
"LOGS", cli_original, (fun v -> LOGS (env_string v)),
("$(i,logdir) sets log directory, default is a temporary directory in \
" ^ (if Sys.win32 then "%TEMP%" else "/tmp"));
(Printf.sprintf
"$(i,logdir) sets log directory, default 'log' directory in opam root\
if opam is initialise, temporary directory in %s otherwise"
(if Sys.win32 then "%TEMP%" else "/tmp"));
"MERGEOUT", cli_original, (fun v -> MERGEOUT (env_bool v)),
"merge process outputs, stderr on stdout.";
"NO", cli_original, (fun v -> NO (env_bool v)),
Expand Down
9 changes: 6 additions & 3 deletions src/client/opamClientConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ let search_files = ["findlib"]

open OpamStd.Op

let opam_init ?root_dir ?strict ?solver =
let opam_init ?root_dir ?safe_mode ?strict ?solver =
let open OpamStd.Option.Op in

(* (i) get root dir *)
Expand Down Expand Up @@ -262,14 +262,17 @@ let opam_init ?root_dir ?strict ?solver =
let log_dir =
OpamStd.Option.map OpamFilename.Dir.to_string @@
if log_dir = None && initialised
&& OpamCoreConfig.E.logs () = None then
&& OpamCoreConfig.E.logs () = None
&& not ((OpamCoreConfig.E.safe () = Some true)
|| (safe_mode = Some true))
then
(* fixme: in order to not revert [OPAMLOGS] value,
we need to check it here *)
Some (OpamPath.log root)
else log_dir
in
(fun () -> ()) |>
OpamCoreConfig.initk ?log_dir |>
OpamCoreConfig.initk ?safe_mode ?log_dir |>
OpamRepositoryConfig.initk |>
OpamSolverConfig.initk ?solver |>
OpamStateConfig.initk ~root_dir:root ~root_from |>
Expand Down
2 changes: 1 addition & 1 deletion src/client/opamClientConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ val search_files: string list
sub-libraries, overriding the given arguments *)
val opam_init:
?root_dir:OpamTypes.dirname ->
?safe_mode:bool ->
?strict:bool ->
?solver:(module OpamCudfSolver.S) Lazy.t ->
?skip_version_checks:bool ->
Expand Down Expand Up @@ -165,7 +166,6 @@ val opam_init:
?disp_status_line:OpamStd.Config.when_ ->
?confirm_level:OpamStd.Config.answer ->
?yes:bool option ->
?safe_mode:bool ->
?keep_log_dir:bool ->
?errlog_length:int ->
?merged_output:bool ->
Expand Down
1 change: 1 addition & 0 deletions src/core/opamCoreConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module E : sig
val confirmlevel: unit -> OpamStd.Config.answer option
val debug: unit -> int option
val logs: unit -> string option
val safe: unit -> bool option
val yes: unit -> bool option
end

Expand Down
21 changes: 21 additions & 0 deletions tests/reftests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,27 @@
%{targets}
(run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:resolve-variables.test} %{read-lines:testing-env}))))

(rule
(alias reftest-safe)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(action
(diff safe.test safe.out)))

(alias
(name reftest)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(deps (alias reftest-safe)))

(rule
(targets safe.out)
(deps root-N0REP0)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(package opam)
(action
(with-stdout-to
%{targets}
(run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:safe.test} %{read-lines:testing-env}))))

(rule
(alias reftest-shared-fetch)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
Expand Down
47 changes: 47 additions & 0 deletions tests/reftests/safe.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
N0REP0
### OPAMYES=1
### :I: opam log dir and safe mode
### <pin:varos/varos.opam>
opam-version: "2.0"
build: [
[make "all"]
[make "test"] {with-test}
]
### <cat-makefile.sh>
f=$1
cat > $f << EOF
all:
echo \$(shell ${OPAM} var os-version --safe)
${OPAM} var os-version --safe
echo done
EOF
### sh cat-makefile.sh varos/Makefile
### opam switch create varos --empty
### # opam install foo bar
### opam pin ./varos -n
[NOTE] Package varos does not exist in opam repositories registered in the current switch.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previsou version (not fixed) is not portable

varos is now pinned to file://${BASEDIR}/varos (version dev)
### opam install varos -v | sed-cmd make

<><> Synchronising pinned packages ><><><><><><><><><><><><><><><><><><><><><><>
Processing 1/1: [varos.dev: rsync]
[varos.dev] synchronised (no changes)

The following actions will be performed:
=== install 1 package
- install varos dev (pinned)

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Processing 1/3: [varos.dev: rsync]
-> retrieved varos.dev (file://${BASEDIR}/varos)
Processing 2/3: [varos: make all]
+ make "all" (CWD=${BASEDIR}/OPAM/varos/.opam-switch/build/varos.dev)
- echo n/a
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This output is not portable

- n/a
- ${OPAM} var os-version --safe
- n/a
- echo done
- done
-> compiled varos.dev
-> installed varos.dev
Done.
Loading