-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move 'targets' into 'show' command and add 'show alias'
Signed-off-by: Ali Caglayan <alizter@gmail.com>
- Loading branch information
Showing
15 changed files
with
209 additions
and
71 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,67 @@ | ||
open Import | ||
open Stdune | ||
|
||
let doc = "Print aliases in a given directory. Works similalry to ls." | ||
|
||
let pp_aliases ~(contexts : Context.t list) path = | ||
let dir = Path.of_string path in | ||
let root = | ||
match (dir : Path.t) with | ||
| External e -> | ||
Code_error.raise "target_hint: external path" | ||
[ ("path", Path.External.to_dyn e) ] | ||
| In_source_tree d -> d | ||
| In_build_dir d -> ( | ||
match Path.Build.drop_build_context d with | ||
| Some d -> d | ||
| None -> Path.Source.root) | ||
in | ||
let open Action_builder.O in | ||
let+ alias_targets = | ||
let+ load_dir = | ||
Action_builder.List.map contexts ~f:(fun ctx -> | ||
let dir = | ||
Path.Build.append_source | ||
(Dune_engine.Context_name.build_dir (Context.name ctx)) | ||
root | ||
|> Path.build | ||
in | ||
Action_builder.of_memo (Load_rules.load_dir ~dir)) | ||
in | ||
List.fold_left load_dir ~init:Dune_engine.Alias.Name.Map.empty | ||
~f:(fun acc x -> | ||
match (x : Load_rules.Loaded.t) with | ||
| Build build -> | ||
Dune_engine.Alias.Name.Map.union | ||
~f:(fun _ a _ -> Some a) | ||
acc build.aliases | ||
| _ -> acc) | ||
|> Dune_engine.Alias.Name.Map.to_list_map ~f:(fun name _ -> | ||
Dune_engine.Alias.Name.to_string name) | ||
in | ||
[ Pp.textf "%s:" (Path.to_string dir) | ||
; Pp.concat_map alias_targets ~f:Pp.text ~sep:Pp.newline | ||
] | ||
|> Pp.concat ~sep:Pp.newline | ||
|
||
let term = | ||
let+ common = Common.term | ||
and+ paths = Arg.(value & pos_all string [ "." ] & info [] ~docv:"DIR") in | ||
let config = Common.init common in | ||
let request (setup : Dune_rules.Main.build_system) = | ||
let open Action_builder.O in | ||
let+ paragraphs = | ||
Action_builder.List.map paths ~f:(pp_aliases ~contexts:setup.contexts) | ||
in | ||
paragraphs | ||
|> Pp.concat ~sep:(Pp.seq Pp.newline Pp.newline) | ||
|> List.singleton |> User_message.make |> User_message.print | ||
in | ||
Scheduler.go ~common ~config @@ fun () -> | ||
let open Fiber.O in | ||
let+ res = Build_cmd.run_build_system ~common ~request in | ||
match res with | ||
| Error `Already_reported -> raise Dune_util.Report_error.Already_reported | ||
| Ok () -> () | ||
|
||
let command = Cmd.v (Cmd.info "aliases" ~doc ~envs:Common.envs) term |
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 @@ | ||
open Import | ||
|
||
(** The aliases command lists all the aliases available in the given directory, | ||
defaulting to the current working direcctory. *) | ||
val command : unit Cmd.t |
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,6 @@ | ||
open Import | ||
|
||
let doc = "Command group for showing information about the workspace" | ||
|
||
let group = | ||
Cmd.group (Cmd.info ~doc "show") [ Targets_cmd.command; Aliases_cmd.command ] |
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,4 @@ | ||
open Import | ||
|
||
(** The dune show command group *) | ||
val group : unit Cmd.t |
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
File renamed without changes.
1 change: 1 addition & 0 deletions
1
test/blackbox-tests/test-cases/show/dune-aliases.t/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 3.8) |
113 changes: 113 additions & 0 deletions
113
test/blackbox-tests/test-cases/show/dune-aliases.t/run.t
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,113 @@ | ||
Testing the "dune show aliases" command. This command shows the aliases in the | ||
current directory. It acts similarly to ls. It will not show aliases that appear | ||
in subdirectories although this could be changed in the future. | ||
|
||
In an empty dune project, the following aliases are available. | ||
|
||
$ dune show aliases | ||
.: | ||
all | ||
default | ||
fmt | ||
|
||
User defined aliases can be added to a dune file. These should be picked up by | ||
the command. | ||
|
||
$ cat > dune << EOF | ||
> (alias | ||
> (name foo)) | ||
> EOF | ||
|
||
$ dune show aliases | ||
.: | ||
all | ||
default | ||
fmt | ||
foo | ||
|
||
Aliases in subdirectories should not be picked up. | ||
|
||
$ mkdir subdir | ||
$ cat > subdir/dune << EOF | ||
> (alias | ||
> (name bar)) | ||
> EOF | ||
|
||
$ dune show aliases | ||
.: | ||
all | ||
default | ||
fmt | ||
foo | ||
|
||
But checking the subdirectory it should be available. | ||
|
||
$ dune show aliases subdir | ||
subdir: | ||
all | ||
bar | ||
default | ||
fmt | ||
|
||
Adding an OCaml library will introduce OCaml specific aliases: | ||
|
||
$ cat > dune << EOF | ||
> (library | ||
> (name foo)) | ||
> EOF | ||
|
||
$ dune show aliases | ||
.: | ||
all | ||
check | ||
default | ||
doc-private | ||
fmt | ||
|
||
Adding a cram test will introduce an alias with the name of the test and also | ||
introduce the runtest alias: | ||
bbb | ||
$ rm dune | ||
$ cat > mytest.t | ||
|
||
$ dune show aliases | ||
.: | ||
all | ||
default | ||
fmt | ||
mytest | ||
runtest | ||
|
||
We can also show aliases in multiple directories at once: | ||
|
||
$ dune show aliases . subdir | ||
.: | ||
all | ||
default | ||
fmt | ||
mytest | ||
runtest | ||
|
||
subdir: | ||
all | ||
bar | ||
default | ||
fmt | ||
|
||
Including those in the _build/ directory: | ||
|
||
$ dune build | ||
$ dune show aliases . _build/default | ||
.: | ||
all | ||
default | ||
fmt | ||
mytest | ||
runtest | ||
|
||
_build/default: | ||
all | ||
default | ||
fmt | ||
mytest | ||
runtest |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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