-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Allow directory as inputs, i.e. input paths ending in / #2815
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1176,6 +1176,28 @@ express the implicit dependency.) | |
| File paths are compared as is, which means that an absolute path and a | ||
| relative path, pointing to the same file, are considered different by Ninja. | ||
|
|
||
| [[dir_inputs]] | ||
| Directory inputs | ||
| ~~~~~~~~~~~~~~~~ | ||
|
|
||
| _Available since Ninja 1.14._ | ||
|
|
||
| If an input path on a build line ends with a path separator (`/`), the input is | ||
| treated as a directory rather than a regular file. When Ninja checks whether the | ||
| build edge is up-to-date, it stats the directory itself and compares its | ||
| modification time against the outputs. | ||
|
|
||
| Most filesystems update a directory's modification time whenever entries are | ||
| added to or removed from it, so a directory input is a convenient way to | ||
| re-run a command when the *set* of files in a directory changes (for example, | ||
| to regenerate an index when new source files are added). Changes to the | ||
| contents of individual files inside the directory do not normally update the | ||
| directory's modification time, so they will not by themselves trigger a rebuild | ||
| - list the affected files explicitly (or via a depfile) if that is desired. | ||
|
|
||
| A path with a trailing separator that exists but is not a directory is treated | ||
| as missing. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to correspond to the implementation. If the path points to a file, it will be reported as an error ?? |
||
|
|
||
| [[validations]] | ||
| Validations | ||
| ~~~~~~~~~~~ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,12 @@ struct Node { | |
| generated_by_dep_loader_ = value; | ||
| } | ||
|
|
||
| /// True if this node refers to a directory (path was given with a trailing | ||
| /// slash in the manifest). When stat()ed, the directory's mtime is used to | ||
| /// determine whether dependents are out-of-date. | ||
| bool is_directory() const { return is_directory_; } | ||
| void set_directory(bool value) { is_directory_ = value; } | ||
|
|
||
| int id() const { return id_; } | ||
| void set_id(int id) { id_ = id; } | ||
|
|
||
|
|
@@ -159,6 +165,11 @@ struct Node { | |
| /// can be loaded before the manifest. | ||
| bool generated_by_dep_loader_ = true; | ||
|
|
||
| /// True if this node refers to a directory rather than a regular file. | ||
| /// Set when a manifest input/output path ends with a trailing slash. When | ||
| /// stat()ing, the path is treated as a directory and its mtime is used. | ||
| bool is_directory_ = false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: there is no need for a boolean flag. Just use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually scratch that, it depends if you want to treat This is quite subtle, and also doesn't happen if It would probably make more sense to just check for the trailing separator when adding a new Node instead to cover all cases, otherwise this will lead to very hard-to-debug inconsistencies. |
||
|
|
||
| /// A dense integer id for the node, assigned and used by DepsLog. | ||
| int id_ = -1; | ||
|
|
||
|
|
||
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.
I think this phrase is confusing because Ninja already stats directory paths if there is no trailing slash. And I am sure that someone is using this in their build system, even if it is a fragile thing to do, so this behavior cannot be changed lightly.
A better phrasing might explain what the trailing slash does, e.g.:
"""
An input path with a trailing separator (e.g.
foo/bar/) must always point to a valid directory, otherwise Ninja will complain with an error. By contrast, paths without it (e.g.foo/bar) can point to either a file or a directory.In both cases, the timestamp used by Ninja corresponds to the file-system's directory entry itself (which does not change when the files within it are modified).
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.
I must say that I fail to see the benefit of this PR. I assumed it is to prepare for glob support but that would require another non-trivial change of logic in Ninja, so why introduce it here and not as a preliminary commit in a PR that does that?