-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1259 from rgrinberg/build-default-alias-dir-target
When the target is a directory use the default alias in it
- Loading branch information
Showing
15 changed files
with
139 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
open Stdune | ||
|
||
let die = Dune.Import.die | ||
|
||
type t = | ||
{ name : string | ||
; recursive : bool | ||
; dir : Path.t | ||
; contexts : Dune.Context.t list | ||
} | ||
|
||
let to_log_string { name ; recursive; dir ; contexts = _ } = | ||
sprintf "- %s alias %s%s/%s" | ||
(if recursive then "recursive " else "") | ||
(if recursive then "@@" else "@") | ||
(Path.to_string_maybe_quoted dir) | ||
name | ||
|
||
let in_dir ~name ~recursive ~contexts dir = | ||
Util.check_path contexts dir; | ||
match Path.extract_build_context dir with | ||
| None -> | ||
{ dir | ||
; recursive | ||
; name | ||
; contexts | ||
} | ||
| Some ("install", _) -> | ||
die "Invalid alias: %s.\n\ | ||
There are no aliases in %s." | ||
(Path.to_string_maybe_quoted Path.(relative build_dir "install")) | ||
(Path.to_string_maybe_quoted dir) | ||
| Some (ctx, dir) -> | ||
{ dir | ||
; recursive | ||
; name | ||
; contexts = | ||
[List.find_exn contexts ~f:(fun c -> Dune.Context.name c = ctx)] | ||
} | ||
|
||
let of_string common s ~contexts = | ||
if not (String.is_prefix s ~prefix:"@") then | ||
None | ||
else | ||
let pos, recursive = | ||
if String.length s >= 2 && s.[1] = '@' then | ||
(2, false) | ||
else | ||
(1, true) | ||
in | ||
let s = String.drop s pos in | ||
let path = Path.relative Path.root (Common.prefix_target common s) in | ||
if Path.is_root path then | ||
die "@@ on the command line must be followed by a valid alias name" | ||
else if not (Path.is_managed path) then | ||
die "@@ on the command line must be followed by a relative path" | ||
else | ||
let dir = Path.parent_exn path in | ||
let name = Path.basename path in | ||
Some (in_dir ~name ~recursive ~contexts dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
open Stdune | ||
|
||
type t = private | ||
{ name : string | ||
; recursive : bool | ||
; dir : Path.t | ||
; contexts : Dune.Context.t list | ||
} | ||
|
||
val in_dir | ||
: name:string | ||
-> recursive:bool | ||
-> contexts:Dune.Context.t list | ||
-> Path.t | ||
-> t | ||
|
||
val of_string : Common.t -> string -> contexts:Dune.Context.t list -> t option | ||
|
||
val to_log_string : t -> string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
open Stdune | ||
open Dune | ||
|
||
val parse_alias | ||
: Path.t | ||
-> contexts:string list | ||
-> string list * Path.t * string | ||
|
||
val check_path : Context.t list -> Path.t -> unit | ||
|
||
val find_root : unit -> string * string list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -585,3 +585,5 @@ let cc_g (ctx : t) = | |
["-g"] | ||
else | ||
[] | ||
|
||
let name t = t.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/blackbox-tests/test-cases/target-dir-alias/dir-target-works/dune-project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(lang dune 1.2) |
3 changes: 3 additions & 0 deletions
3
test/blackbox-tests/test-cases/target-dir-alias/dir-target-works/foo/dune
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(alias | ||
(name default) | ||
(action (echo "default target works"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Building a directory results in the default target being built | ||
|
||
$ dune build foo --root dir-target-works | ||
Entering directory 'dir-target-works' | ||
default target works |