Skip to content

Commit a4bc8cc

Browse files
committed
fix(pkg): allow locking relative path outside the workspace
Signed-off-by: Shun Ueda <me@shu.nu>
1 parent d2120ac commit a4bc8cc

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/dune_pkg/opamUrl0.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let is_supported_archive t = Option.is_some (Archive_driver.choose_for_filename
3333

3434
let classify url loc =
3535
match (url : t).backend with
36-
| `rsync when is_local url -> `Path (Path.of_string url.path)
36+
| `rsync when is_local url -> `Path (Path.of_string_allow_outside_workspace url.path)
3737
| `git -> `Git
3838
| `http when is_supported_archive url -> `Archive
3939
| `rsync | `http | `darcs | `hg ->

src/dune_rules/lock_dir.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,11 @@ let source_kind (source : Dune_pkg.Source.t) =
308308
let loc, url = source.url in
309309
if OpamUrl.is_local url && url.backend = `rsync
310310
then (
311-
let path = Path.External.of_string url.path in
311+
let path =
312+
Path.of_string_allow_outside_workspace url.path
313+
|> Path.to_absolute_filename
314+
|> Path.External.of_string
315+
in
312316
Fs_memo.path_kind (External path)
313317
>>| function
314318
| Error (ENOENT, _, _) ->

test/blackbox-tests/test-cases/pkg/pin-stanza/relative-path-outside-workspace.t

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
Demonstrate that you can't use a relative path referring outside the workspace
2-
in the pin stanza:
1+
Demonstrate that relative paths outside the workspace work in pin stanzas:
32

43
Make a package containing a library:
54
$ mkdir foo
@@ -49,7 +48,7 @@ Lock and build the second package to demonstrate that everything works so far:
4948
$ dune exec ./bar.exe
5049
foo
5150

52-
Now change the pin to use a relative path:
51+
Now change the pin to use a relative path (this should also work):
5352
$ cat > dune-project <<EOF
5453
> (lang dune 3.14)
5554
> (pin
@@ -60,10 +59,10 @@ Now change the pin to use a relative path:
6059
> (depends foo))
6160
> EOF
6261

63-
Solving the project now results in an error, though it's still possible to build the project:
62+
Solving the project works with relative paths outside the workspace:
6463
$ dune clean
6564
$ dune_pkg_lock_normalized
66-
Error: path outside the workspace: ../foo from .
67-
[1]
65+
Solution for dune.lock:
66+
- foo.dev
6867
$ dune exec ./bar.exe
6968
foo

0 commit comments

Comments
 (0)