-
Notifications
You must be signed in to change notification settings - Fork 412
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
Add a default alias #926
Add a default alias #926
Conversation
This behavior is only enable for |
CHANGES.md
Outdated
@@ -93,6 +93,13 @@ next | |||
|
|||
- Make `dev` the default build profile (#920, @diml) | |||
|
|||
- Add the ability to build an alias non-recursively from the command | |||
line by writing `@@alias` (#926, @diml) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the syntax: I wonder if instead (or in addition to) this @@alias
syntax, we could use a directory-based syntax like @./alias
. Maybe that could be extended to other directories to support #771?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can already write a directory after @
(and @@
in this PR). For instance @foo/runtest
means alias runtest
recursively from foo
and @@foo/runtest
means alias runtest only in foo
.
match Path.extract_build_context dir with | ||
| None -> (contexts, dir, name) | ||
| Some ("install", _) -> | ||
die "Invalid alias: %s.\n\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to pass a loc
to have a nicer error message? (or return a result
from here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from the command line, so we don't have a loc for it.
let no_targets_allowed () = | ||
Exn.code_error "No targets allowed under a [Build.lazy_no_targets] \ | ||
or [Build.if_file_exists]" [] | ||
[@@inline never] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, what is the purpose of that annotation? is it just an optimization or is it required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just an optimization, so that the error case code is not inlined in the main function. It's kind of a cold annotation.
let find_dir_specified_on_command_line ~dir ~file_tree = | ||
match File_tree.find_dir file_tree dir with | ||
| None -> | ||
die "From the command line:\n\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark about die
- can we inject a loc here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from the command line as well, so we don't have a more precise location either
Was it possible to define an alias name with a |
let is_standard = function | ||
| "runtest" | "install" | "doc" | "doc-private" | "lint" -> true | ||
| "runtest" | "install" | "doc" | "doc-private" | "lint" | "default" -> true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a breaking change for jbuild projects? IIRC, some users defined their own default aliases. In any case, I'm not sure this will make a big difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not if you use the jbuilder
binary, but possibly if you use the dune
one. Which seems acceptable to me.
src/build_system.ml
Outdated
name (Path.to_string_maybe_quoted src_dir) | ||
|
||
let default = make "DEFAULT" | ||
@{<error>Error@}: Alias %s is empty.\n\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To print things consistently, let' use %S
for the alias name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
@emillon yes. It is still possible to refer to it with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I'm a bit curious as to how much benefit that optimization brings us. IIRC, you've asked me to try something similar before and I remember not really gaining much. But I think this construct might be applicable elsewhere as well.
fail fn | ||
else | ||
let fn = Path.append (Path.relative Path.build_dir ctx) fn' in | ||
die "Trying to build alias %s but build context %s doesn't exist.%s" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this case possible? I'm actually not sure if we can exercise it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can happen if you request an alias in _build explicitely from the command line.
Oh, and please accept the corrections before merging. |
Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
- if "default" is specified by the user explicitely, use this definition - otherwise assume the following definition: (alias (name default) (deps (alias_rec install))) Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This is useful for (alias_rec ...) since at definition site we recurse through all sub-directories. This is especially relevant now that we have the default alias which defaults to (alias_rec install). Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
Maybe this optimization doesn't buy us that much. I just got into the habbit of doing it... Ideally the compiler would do this optimization itself |
Jérémie Dimino <notifications@github.com> writes:
+ | Alias (ctx, fn') ->
+ if String.Map.mem t.contexts ctx then
+ fail fn
+ else
+ let fn = Path.append (Path.relative Path.build_dir ctx) fn' in
+ die "Trying to build alias %s but build context %s doesn't exist.%s"
It can happen if you request an alias in _build explicitely from the command line.
I actually gave this a try, and there's earlier validation that seems to
catch this. Perhaps a test case would be helpful here? I don't think
this is so important, but it's nice not to add dead code. Perhaps we can
even remove earlier validation and just keep this one.
|
There is a validation on the command line. We should be able to hit this case by writing something like this in a toplevel dune file:
|
This PR adds a special
default
alias which become the new default target.Definition
When the
default
alias is not explictely defined in a directory, it is implicitely defined as follow:Otherwise the user definition is used.
Default target
The default target is changed from building recursively the alias
install
to building thedefault
only in the current directory. This allows to redefine whatdune build
in different directories.In order to represent that, a new syntax is added to the command line:
@@x
means building aliasx
in the current directory. In the enddune build
is equivalent todune build @@default
.dune build -p x
still meansdune build -p x @install
. This is done by adding a command line option--default-target
and making-p
imply--default-target @install
.Future work
It'd be nice to allow to define what the default target means in any directory of a project. A nice way to do that would be to allow a
copy_in_subdirs
field to alias stanza that would cause the the alias stanza to be copied in all directories of the project, so that a user may write in the dune-project file:Implementation details
(alias_rec ...)
requires recursive throught the file tree. Since it is now uses for every single directory through the default alias, a bit of laziness was added toBuild.t
.