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

Rename "repo" to "root" #218

Merged
merged 2 commits into from
Oct 22, 2021
Merged
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Only warn users about missing dune-ports repo in OPAM switch if no solution
can be found due to packages not building with dune (#210, @Leonidas-from-XIV)
- Rename the `--repo` option to `--root` to make it more
straightforward that this is referring to the project root (#218, @samoht)

### Deprecated

Expand Down
11 changes: 7 additions & 4 deletions cli/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ module Arg = struct

let fpath = Cmdliner.Arg.conv ~docv:"PATH" (Fpath.of_string, Fpath.pp)

let repo =
let doc = "Path to Git repository to store vendored code in." in
let root =
let doc =
"Use this directory as the project root instead of the current working \
directory."
in
named
(fun x -> `Repo x)
(fun x -> `Root x)
Cmdliner.Arg.(
value
& opt fpath (Fpath.v (Sys.getcwd ()))
& info [ "r"; "repo" ] ~docv:"TARGET_REPO" ~doc)
& info [ "r"; "root" ] ~docv:"DIR" ~doc)

let lockfile =
let doc =
Expand Down
2 changes: 1 addition & 1 deletion cli/common.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Arg : sig

val fpath : Fpath.t Cmdliner.Arg.converter

val repo : [ `Repo of Fpath.t ] Cmdliner.Term.t
val root : [ `Root of Fpath.t ] Cmdliner.Term.t
(** CLI option to specify the root directory of the project. Used to find root packages,
duniverse files and directories. Defaults to the current directory. *)

Expand Down
6 changes: 3 additions & 3 deletions cli/depext.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
open Import

let run (`Repo repo) (`Lockfile explicit_lockfile) dry_run (`Yes yes) () =
let run (`Root root) (`Lockfile explicit_lockfile) dry_run (`Yes yes) () =
let open Result.O in
if yes then OpamCoreConfig.update ~confirm_level:`unsafe_yes ();
Common.find_lockfile ~explicit_lockfile repo >>= fun lockfile ->
Common.find_lockfile ~explicit_lockfile root >>= fun lockfile ->
let depexts = Lockfile.depexts lockfile in
OpamGlobalState.with_ `Lock_none (fun global_state ->
let env = OpamPackageVar.resolve_global global_state in
Expand Down Expand Up @@ -51,7 +51,7 @@ let dry_run =
let term =
let open Term in
term_result
(const run $ Common.Arg.repo $ Common.Arg.lockfile $ dry_run
(const run $ Common.Arg.root $ Common.Arg.lockfile $ dry_run
$ Common.Arg.yes $ Common.Arg.setup_logs ())

let cmd = (term, info)
8 changes: 4 additions & 4 deletions cli/lock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,19 @@ let calculate_opam ~build_only ~allow_jbuilder ~local_opam_files ~ocaml_version
~pin_depends ?ocaml_version switch_state
|> Result.map_error ~f:(interpret_solver_error ~switch_state)))

let run (`Repo repo) (`Recurse_opam recurse) (`Build_only build_only)
let run (`Root root) (`Recurse_opam recurse) (`Build_only build_only)
(`Allow_jbuilder allow_jbuilder) (`Ocaml_version ocaml_version)
(`Local_packages lp) (`Lockfile explicit_lockfile) () =
let open Rresult.R.Infix in
local_packages ~recurse ~explicit_list:lp repo >>= fun local_paths ->
local_packages ~recurse ~explicit_list:lp root >>= fun local_paths ->
let local_packages =
List.map
~f:(fun (name, (version, _)) -> Package_argument.make ~name ~version)
(String.Map.bindings local_paths)
in
check_root_packages ~local_packages >>= fun () ->
local_paths_to_opam_map local_paths >>= fun local_opam_files ->
lockfile_path ~explicit_lockfile ~local_packages repo >>= fun lockfile_path ->
lockfile_path ~explicit_lockfile ~local_packages root >>= fun lockfile_path ->
calculate_opam ~build_only ~allow_jbuilder ~ocaml_version ~local_opam_files
>>= fun package_summaries ->
Common.Logs.app (fun l -> l "Calculating exact pins for each of them.");
Expand Down Expand Up @@ -349,7 +349,7 @@ let info =
let term =
let open Term in
term_result
(const run $ Common.Arg.repo $ recurse_opam $ build_only $ allow_jbuilder
(const run $ Common.Arg.root $ recurse_opam $ build_only $ allow_jbuilder
$ ocaml_version $ packages $ Common.Arg.lockfile $ Common.Arg.setup_logs ())

let cmd = (term, info)
14 changes: 7 additions & 7 deletions cli/pull.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ let suggest_updating_version ~yes ~version ~dune_project_path ~content =
Bos.OS.File.write dune_project_path updated)
else Ok ()

let check_dune_lang_version ~yes ~repo =
let check_dune_lang_version ~yes ~root =
let open Result.O in
let dune_project_path = Fpath.(repo / "dune-project") in
let dune_project_path = Fpath.(root / "dune-project") in
Logs.debug (fun l ->
l "Looking for dune-project file in %a" Pp.Styled.path dune_project_path);
Bos.OS.File.exists dune_project_path >>= fun found_dune_project ->
Expand All @@ -49,10 +49,10 @@ let check_dune_lang_version ~yes ~repo =
Logs.debug (fun l -> l "No dune-project found");
Ok ())

let run (`Yes yes) (`Repo repo) (`Lockfile explicit_lockfile)
let run (`Yes yes) (`Root root) (`Lockfile explicit_lockfile)
(`Keep_git_dir keep_git_dir) (`Duniverse_repos duniverse_repos) () =
let open Result.O in
Common.find_lockfile ~explicit_lockfile repo >>= fun lockfile ->
Common.find_lockfile ~explicit_lockfile root >>= fun lockfile ->
Lockfile.to_duniverse lockfile >>= function
| [] ->
Common.Logs.app (fun l ->
Expand All @@ -62,9 +62,9 @@ let run (`Yes yes) (`Repo repo) (`Lockfile explicit_lockfile)
let full = match duniverse_repos with None -> true | _ -> false in
Common.filter_duniverse ~to_consider:duniverse_repos duniverse
>>= fun duniverse ->
check_dune_lang_version ~yes ~repo >>= fun () ->
check_dune_lang_version ~yes ~root >>= fun () ->
OpamGlobalState.with_ `Lock_none (fun global_state ->
Pull.duniverse ~global_state ~repo ~full
Pull.duniverse ~global_state ~root ~full
~trim_clone:(not keep_git_dir) duniverse)

let info =
Expand All @@ -90,7 +90,7 @@ let info =
let term =
Cmdliner.Term.(
term_result
(const run $ Common.Arg.yes $ Common.Arg.repo $ Common.Arg.lockfile
(const run $ Common.Arg.yes $ Common.Arg.root $ Common.Arg.lockfile
$ Common.Arg.keep_git_dir $ Common.Arg.duniverse_repos
$ Common.Arg.setup_logs ()))

Expand Down
4 changes: 2 additions & 2 deletions lib/pull.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ let pre_pull_clean_up ~full ~duniverse_dir duniverse =
Bos.OS.Dir.delete ~must_exist:false ~recurse:true
Fpath.(duniverse_dir / dir))

let duniverse ~full ~repo ~global_state ~trim_clone duniverse =
let duniverse ~full ~root ~global_state ~trim_clone duniverse =
if List.is_empty duniverse then Ok ()
else
let open Result.O in
let duniverse_dir = Fpath.(repo // Config.vendor_dir) in
let duniverse_dir = Fpath.(root // Config.vendor_dir) in
pre_pull_clean_up ~full ~duniverse_dir duniverse >>= fun () ->
Bos.OS.Dir.create duniverse_dir >>= fun _created ->
mark_duniverse_content_as_vendored ~duniverse_dir >>= fun () ->
Expand Down
6 changes: 3 additions & 3 deletions lib/pull.mli
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
val duniverse :
full:bool ->
repo:Fpath.t ->
root:Fpath.t ->
global_state:OpamStateTypes.unlocked OpamStateTypes.global_state ->
trim_clone:bool ->
Duniverse.t ->
(unit, [> Rresult.R.msg ]) result
(** [duniverse ~full ~repo ~global_state duniverse]
pulls duniverse repositories into the [Config.vendor_dir] of the given [repo].
(** [duniverse ~full ~root ~global_state duniverse]
pulls duniverse repositories into the [Config.vendor_dir] of the given project [root].
If [full] is [true] then the vendor_dir is entirely deleted before pulling, otherwise
only the subfolder corresponding to the repos in [duniverse] are. *)