From 3133df476df3e609702f250afdbf16d5679c0d2d Mon Sep 17 00:00:00 2001 From: na4zagin3 Date: Sun, 10 Apr 2022 15:27:11 +0900 Subject: [PATCH] Try read OPAM switch from the current directory --- bin/setup.ml | 7 +++++++ src/command/build.ml | 11 +++++------ src/opamWrapper.ml | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/bin/setup.ml b/bin/setup.ml index ae5017b..4d79214 100644 --- a/bin/setup.ml +++ b/bin/setup.ml @@ -15,6 +15,13 @@ let default_target_dir = let read_environment ?opam_switch () = let outf = Format.std_formatter in + let opam_switch = match opam_switch with + | Some _ -> opam_switch + | None -> + let dir = OpamFilename.cwd () in + (* TODO Read switch relative to Satyristes *) + Option.some_if (OpamWrapper.exists_switch_at_dir dir) (OpamSwitch.of_dirname dir) + in let env = EnvironmentStatus.read_opam_environment ~outf ?opam_switch () in SatysfiDirs.read_satysfi_env ~outf env diff --git a/src/command/build.ml b/src/command/build.ml index a7dcf70..3310fea 100644 --- a/src/command/build.ml +++ b/src/command/build.ml @@ -99,7 +99,7 @@ let build ~outf ~build_dir ~verbose ~build_module ~buildscript_path ~system_font end -let opam_pin_project ~(buildscript: BuildScript.t) ~buildscript_path = +let opam_pin_project ~(env: Environment.t) ~verbose ~(buildscript: BuildScript.t) ~buildscript_path = let open P.Infix in let workdir cwd = FilePath.make_absolute cwd buildscript_path @@ -122,10 +122,9 @@ let opam_pin_project ~(buildscript: BuildScript.t) ~buildscript_path = let opam_name = Lint.get_opam_name ~opam ~opam_path in - P.run "opam" ["pin"; "add"; "--no-action"; "--yes"; opam_name; "file://" ^ workdir cwd] - >> P.set_env "OPAMSOLVERTIMEOUT" "0" ( - P.run "opam" ["reinstall"; "--verbose"; "--yes"; "--"; workdir cwd] - ) + let proj_dir = workdir cwd in + OpamWrapper.opam_add_pin_com ~env ~verbose opam_name proj_dir + >> OpamWrapper.opam_rebuild_com ~env ~verbose proj_dir ) ) @@ -153,7 +152,7 @@ let build_command ~outf ~buildscript_path ~names ~verbose ~env = |> List.map ~f:BuildScript.get_name in P.echo ("= Pin projects") - >> opam_pin_project ~buildscript ~buildscript_path + >> opam_pin_project ~env ~verbose ~buildscript ~buildscript_path >> P.echo (Printf.sprintf !"\n= Build modules: %{sexp: string list}" module_names) >> P.List.iter build_modules ~f:(fun build_module -> begin match build_module with diff --git a/src/opamWrapper.ml b/src/opamWrapper.ml index ff310da..49eb52f 100644 --- a/src/opamWrapper.ml +++ b/src/opamWrapper.ml @@ -19,6 +19,12 @@ end let opam_package_name_satysfi = OpamPackage.Name.(of_string "satysfi") +let exists_switch_at_dir dir = + let switch = OpamSwitch.of_dirname dir in + let root = OpamStateConfig.(!r.root_dir) in + let switch_config_file = OpamPath.Switch.switch_config root switch in + OpamFile.exists switch_config_file + let get_satysfi_opam_registry switch = let get_reg_from_root switch = let root = OpamStateConfig.(!r.root_dir) in @@ -221,3 +227,13 @@ let exec_run ~(env: Environment.t) com args = "--"; ] @ [com] @ args |> P.run "opam" + +let opam_add_pin_com ~(env: Environment.t) ~verbose:_ package proj_dir = + ignore env; + P.run "opam" ["pin"; "add"; "--no-action"; "--yes"; package; "file://" ^ proj_dir] + +let opam_rebuild_com ~(env: Environment.t) ~verbose:_ proj_dir = + ignore env; + P.set_env "OPAMSOLVERTIMEOUT" "0" ( + P.run "opam" ["reinstall"; "--verbose"; "--yes"; "--"; proj_dir] + )