Skip to content

Commit 5a31b93

Browse files
authored
Merge pull request #997 from rgrinberg/fix-workspace-lookup
Fix workspace lookup in conjunction with --root
2 parents 083b261 + b4b7dde commit 5a31b93

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
next
2+
----
3+
4+
- Fix lookup of command line specified files when `--root` is given. Previously,
5+
passing in `--root` in conjunction with `--workspace` or `--config` would not
6+
work correctly (#997, @rgrinberg)
7+
18
1.0.0 (10/07/2018)
29
------------------
310

bin/main.ml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,39 @@ open Fiber.O
77
bootstrap, so we set this reference here *)
88
let () = suggest_function := Cmdliner_suggest.value
99

10+
module Arg = struct
11+
include Arg
12+
13+
let package_name =
14+
Arg.conv ((fun p -> Ok (Package.Name.of_string p)), Package.Name.pp)
15+
16+
module Path : sig
17+
type t
18+
val path : t -> Path.t
19+
val arg : t -> string
20+
21+
val conv : t conv
22+
end = struct
23+
type t = string
24+
25+
let path p = Path.of_filename_relative_to_initial_cwd p
26+
let arg s = s
27+
28+
let conv = Arg.conv ((fun p -> Ok p), Format.pp_print_string)
29+
end
30+
31+
let path = Path.conv
32+
33+
[@@@ocaml.warning "-32"]
34+
let file = path
35+
end
36+
1037
type common =
1138
{ debug_dep_path : bool
1239
; debug_findlib : bool
1340
; debug_backtraces : bool
1441
; profile : string option
15-
; workspace_file : string option
42+
; workspace_file : Arg.Path.t option
1643
; root : string
1744
; target_prefix : string
1845
; only_packages : Package.Name.Set.t option
@@ -83,8 +110,7 @@ module Main = struct
83110
let setup ~log ?external_lib_deps_mode common =
84111
setup
85112
~log
86-
?workspace_file:(
87-
Option.map common.workspace_file ~f:Path.of_string)
113+
?workspace_file:(Option.map ~f:Arg.Path.path common.workspace_file)
88114
?only_packages:common.only_packages
89115
?external_lib_deps_mode
90116
?x:common.x
@@ -186,9 +212,6 @@ let find_root () =
186212
in
187213
(dir, to_cwd)
188214

189-
let package_name =
190-
Arg.conv ((fun p -> Ok (Package.Name.of_string p)), Package.Name.pp)
191-
192215
let common_footer =
193216
`Blocks
194217
[ `S "BUGS"
@@ -255,7 +278,7 @@ let common =
255278
let orig_args =
256279
List.concat
257280
[ dump_opt "--profile" profile
258-
; dump_opt "--workspace" workspace_file
281+
; dump_opt "--workspace" (Option.map ~f:Arg.Path.arg workspace_file)
259282
; orig
260283
]
261284
in
@@ -432,7 +455,7 @@ let common =
432455
in
433456
let workspace_file =
434457
Arg.(value
435-
& opt (some file) None
458+
& opt (some path) None
436459
& info ["workspace"] ~docs ~docv:"FILE"
437460
~doc:"Use this specific workspace file instead of looking it up.")
438461
in
@@ -469,7 +492,7 @@ let common =
469492
let config_file =
470493
let config_file =
471494
Arg.(value
472-
& opt (some file) None
495+
& opt (some path) None
473496
& info ["config-file"] ~docs ~docv:"FILE"
474497
~doc:"Load this configuration file instead of the default one.")
475498
in
@@ -482,7 +505,7 @@ let common =
482505
let merge config_file no_config =
483506
match config_file, no_config with
484507
| None , false -> `Ok (None , Default)
485-
| Some fn, false -> `Ok (Some "--config-file", This (Path.of_string fn))
508+
| Some fn, false -> `Ok (Some "--config-file", This (Arg.Path.path fn))
486509
| None , true -> `Ok (Some "--no-config" , No_config)
487510
| Some _ , true -> incompatible "--no-config" "--config-file"
488511
in
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(lang dune 1.0)
22

3-
(context (does-not-exist))
3+
(context (default))

test/blackbox-tests/test-cases/workspaces/run.t

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ analogously, jbuilder will ignore it
2525
specifying the workspace file is possible:
2626

2727
$ dune build --root custom-workspace --workspace custom-workspace/dune-workspace.dev
28-
Error: workspace file custom-workspace/dune-workspace.dev does not exist
29-
[1]
28+
Entering directory 'custom-workspace'
3029

3130
Workspaces let you set custom profiles
3231

0 commit comments

Comments
 (0)