Skip to content

Support and require disambiguated file addresses#10535

Merged
stuhood merged 11 commits intopantsbuild:masterfrom
stuhood:stuhood/normalize-file-addresses
Aug 4, 2020
Merged

Support and require disambiguated file addresses#10535
stuhood merged 11 commits intopantsbuild:masterfrom
stuhood:stuhood/normalize-file-addresses

Conversation

@stuhood
Copy link
Copy Markdown
Member

@stuhood stuhood commented Aug 3, 2020

This adds a new syntax for generated subtargets / file deps to specify which original base target they come from: a/b/c.txt:original, with the following characteristics:

  • If the original target has a "default name", meaning the name field is left off, then there is no need for the disambiguation.
  • As before, a base target can live in an ancestor directory, e.g. a/b/c.txt:../../original.

Thanks to this new syntax, we no longer look for the Owners of explicit file dependencies. We require the values to be unambiguous, which improves performance and removes an edge case where we would error if there were multiple owners of the file.

We use the engine now to parse an AddressInput into an Address. This is necessary so that we can properly determine if a path is a file or a directory, as a/b/c could technically be a file or a directory.

In followups, we can extend this syntax to file specs. It also will allow us to consistently use generated subtargets when using file specs, which will simplify lots of that code and resolve #10455.

@stuhood stuhood changed the title Support and required disambiguiated file addresses Support and require disambiguated file addresses Aug 3, 2020
@stuhood stuhood force-pushed the stuhood/normalize-file-addresses branch from 7a799e9 to a633560 Compare August 3, 2020 19:29
Eric-Arellano pushed a commit that referenced this pull request Aug 3, 2020
### Problem

#10535 normalizes specs to not include the trailing name when it will default. In order to fix tests, many instances of `src/example/test:test` in _output_ (the form is still supported and normalized in input) will be converted to `src/example/test`. To avoid needing to differentiate input from output though, and allow for a cleaner find-replace, I'm going to change all instances.

While doing so, I noticed that the `ArgSplitter` operates relative to the current directory rather than the buildroot, which meant that `GoalRuleTestBase` was not recognizing file args or defaulted directory specs correctly.

### Solution

Adjust `ArgSplitter` to operate relative to the buildroot.

[ci skip-rust]
[ci skip-build-wheels]
stuhood added 6 commits August 3, 2020 13:04
[ci skip-rust]

[ci skip-build-wheels]
…o an AddressInput which can be resolved into an Address by the engine.

[ci skip-rust]

[ci skip-build-wheels]
[ci skip-rust]

[ci skip-build-wheels]
[ci skip-build-wheels]

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]
[ci skip-build-wheels]

[ci skip-rust]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@stuhood stuhood force-pushed the stuhood/normalize-file-addresses branch from a633560 to a7cbd1c Compare August 3, 2020 20:04
* Add back parsing of relative file dependencies via `./`
* Fix validation of `../` in the `target_component`. Thanks Stu!
* Enforce that top-level file deps must have a target attached to them
* Fix ! ignores not working with file deps

This also adds many new tests.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
stuhood added a commit to stuhood/pants that referenced this pull request Aug 4, 2020
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@stuhood stuhood marked this pull request as ready for review August 4, 2020 04:49
@stuhood stuhood requested review from Eric-Arellano and benjyw August 4, 2020 04:49
Also simplify the graph_test.py test for parsing dependencies. The parsing in graph.py is now extremely simple and there is no need for redundancy with address_test.py and build_files_test.py.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Copy link
Copy Markdown
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a PR description explaining the changes.

I recommend starting with address.py and address_test.py to see the model changes, then perhaps go to build_files.py and build_files_test.py to see how we now resolve the ambiguity between a file vs. a directory via the engine. The last major change is in graph.py for the dependencies rule.

@@ -2,109 +2,209 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is probably not useful. I recommend looking at it cleanly.

@@ -1,213 +1,294 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on the diff not being very helpful.

@coveralls
Copy link
Copy Markdown

coveralls commented Aug 4, 2020

Coverage Status

Coverage remained the same at 0.0% when pulling 9885cf9 on stuhood:stuhood/normalize-file-addresses into 52c7c26 on pantsbuild:master.

Copy link
Copy Markdown
Member Author

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

def test_address_input_from_file() -> None:
assert AddressInput("a/b/c.txt", target_component=None).file_to_address() == Address(
"a/b", relative_file_path="c.txt"
)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for adding these, and for the fixes!

stuhood added a commit to stuhood/pants that referenced this pull request Aug 4, 2020
[ci skip-rust]

[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
…malize-file-addresses

[ci skip-rust]

[ci skip-build-wheels]
@stuhood stuhood merged commit 6fd4dbb into pantsbuild:master Aug 4, 2020
@stuhood stuhood deleted the stuhood/normalize-file-addresses branch August 4, 2020 17:44
@stuhood
Copy link
Copy Markdown
Member Author

stuhood commented Aug 4, 2020

@Eric-Arellano : Thanks again!

stuhood added a commit to stuhood/pants that referenced this pull request Aug 4, 2020
[ci skip-rust]

[ci skip-build-wheels]
stuhood added a commit to stuhood/pants that referenced this pull request Aug 4, 2020
[ci skip-rust]

[ci skip-build-wheels]
stuhood added a commit to stuhood/pants that referenced this pull request Aug 5, 2020
[ci skip-rust]

[ci skip-build-wheels]
Eric-Arellano pushed a commit to Eric-Arellano/pants that referenced this pull request Aug 5, 2020
[ci skip-rust]

[ci skip-build-wheels]
Eric-Arellano added a commit that referenced this pull request Aug 5, 2020
The old validation for `BUILD` in the spec path would incorrectly error for a generated subtarget with `BUILD` as its file. We only want to error if `BUILD` is in the `spec_path`, but it's okay if it's in the `relative_file_path` or `target_name`.

Our `spec` logic was also incorrect for generated subtargets which live in a directory below the original target, where the original target is the default name.

[ci skip-rust]
[ci skip-build-wheels]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Always use generated subtargets

3 participants