Skip to content

Commit

Permalink
go: filter out vendor directories in tailor (#14259)
Browse files Browse the repository at this point in the history
As described in #14255, `./pants tailor` is generating targets for Go code in `vendor` directories. The Go backend does not currently support `vendor` directories, and the likely implementation will use target generation to put those sources into the build graph, so there is no reason for tailor to create explicit targets.

Closes #14255.

[ci skip-rust]

[ci skip-build-wheels]
  • Loading branch information
Tom Dyas committed Jan 26, 2022
1 parent 3f5f4d2 commit 7844830
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/python/pants/backend/go/goals/tailor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ async def find_putative_go_targets(
# Add `go_package` targets.
unowned_go_files = set(all_go_files.files) - set(all_owned_sources)
for dirname, filenames in group_by_dir(unowned_go_files).items():
if "testdata" in PurePath(dirname).parts:
# Ignore paths that have `testdata` or `vendor` in them.
# From `go help packages`: Note, however, that a directory named vendor that itself contains code
# is not a vendored package: cmd/vendor would be a command named vendor.
dirname_parts = PurePath(dirname).parts
if "testdata" in dirname_parts or "vendor" in dirname_parts[0:-1]:
continue
putative_targets.append(
PutativeTarget.for_target_type(
Expand Down
13 changes: 11 additions & 2 deletions src/python/pants/backend/go/goals/tailor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ def test_find_go_package_targets(rule_runner: RuleRunner) -> None:
"unowned/f1.go": "",
"owned/f.go": "",
"owned/BUILD": "go_package()",
# Any `.go` files under a `testdata` folder should be ignored.
# Any `.go` files under a `testdata` or `vendor` folder should be ignored.
"unowned/testdata/f.go": "",
"unowned/testdata/subdir/f.go": "",
"unowned/vendor/example.com/foo/bar.go": "",
# Except if `vendor` is the last directory.
"unowned/cmd/vendor/main.go": "",
}
)
putative_targets = rule_runner.request(
Expand All @@ -95,7 +98,13 @@ def test_find_go_package_targets(rule_runner: RuleRunner) -> None:
path="unowned",
name=None,
triggering_sources=["f.go", "f1.go"],
)
),
PutativeTarget.for_target_type(
GoPackageTarget,
path="unowned/cmd/vendor",
name=None,
triggering_sources=["main.go"],
),
]
)

Expand Down

0 comments on commit 7844830

Please sign in to comment.