Skip to content

Commit

Permalink
[internal] tailor doesn't add go_package for testdata folder (#…
Browse files Browse the repository at this point in the history
…13783)

Go tooling ignores the `testdata` folder. While it's uncommon to have `.go` files in this folder, we should not ever generate `go_package` targets inside it. Users can manually create targets if they so desire.

Note that we ignore Go files in subdirectories of `testdata`, which mirrors Go's handling.

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano authored Dec 2, 2021
1 parent 54f72e8 commit 5b55a3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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 @@ -6,6 +6,7 @@
import os
import re
from dataclasses import dataclass
from pathlib import PurePath

from pants.backend.go.target_types import (
GoBinaryMainPackage,
Expand Down Expand Up @@ -69,11 +70,14 @@ 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():
dir_path = PurePath(dirname)
if "testdata" in dir_path.parts:
continue
putative_targets.append(
PutativeTarget.for_target_type(
GoPackageTarget,
path=dirname,
name=os.path.basename(dirname),
name=dir_path.name,
triggering_sources=sorted(filenames),
)
)
Expand Down
3 changes: 3 additions & 0 deletions src/python/pants/backend/go/goals/tailor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ 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.
"unowned/testdata/f.go": "",
"unowned/testdata/subdir/f.go": "",
}
)
putative_targets = rule_runner.request(
Expand Down

0 comments on commit 5b55a3a

Please sign in to comment.