-
-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
overrides
field to shell_sources
, shunit2_sources
, and `pro…
…tobuf_sources` (#13298) See #13270. This does not yet add the field to `java_sources` and `junit_tests`, tracked by #13297. I'm not sure if we should add this mechanism to `files` and `resources`? I'm having a hard time thinking of when you would want to override the metadata for a single file. But, we might want to do it for the sake of consistency? This also does not hook up `python_requirements` and `poetry_requirements` because those use the old CAOF macro system, rather than the Target API. [ci skip-rust]
- Loading branch information
1 parent
4ea1480
commit fe09522
Showing
4 changed files
with
290 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/python/pants/backend/codegen/protobuf/target_types_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
from textwrap import dedent | ||
|
||
from pants.backend.codegen.protobuf import target_types | ||
from pants.backend.codegen.protobuf.target_types import ( | ||
GenerateTargetsFromProtobufSources, | ||
ProtobufSourcesGeneratorTarget, | ||
ProtobufSourceTarget, | ||
) | ||
from pants.engine.addresses import Address | ||
from pants.engine.target import GeneratedTargets, SingleSourceField, Tags | ||
from pants.testutil.rule_runner import QueryRule, RuleRunner | ||
|
||
|
||
def test_generate_source_and_test_targets() -> None: | ||
rule_runner = RuleRunner( | ||
rules=[ | ||
*target_types.rules(), | ||
QueryRule(GeneratedTargets, [GenerateTargetsFromProtobufSources]), | ||
], | ||
target_types=[ProtobufSourcesGeneratorTarget], | ||
) | ||
rule_runner.write_files( | ||
{ | ||
"src/proto/BUILD": dedent( | ||
"""\ | ||
protobuf_sources( | ||
name='lib', | ||
sources=['**/*.proto'], | ||
overrides={'f1.proto': {'tags': ['overridden']}}, | ||
) | ||
""" | ||
), | ||
"src/proto/f1.proto": "", | ||
"src/proto/f2.proto": "", | ||
"src/proto/subdir/f.proto": "", | ||
} | ||
) | ||
|
||
generator = rule_runner.get_target(Address("src/proto", target_name="lib")) | ||
|
||
def gen_tgt(rel_fp: str, tags: list[str] | None = None) -> ProtobufSourceTarget: | ||
return ProtobufSourceTarget( | ||
{SingleSourceField.alias: rel_fp, Tags.alias: tags}, | ||
Address("src/proto", target_name="lib", relative_file_path=rel_fp), | ||
residence_dir=os.path.dirname(os.path.join("src/proto", rel_fp)), | ||
) | ||
|
||
generated = rule_runner.request( | ||
GeneratedTargets, [GenerateTargetsFromProtobufSources(generator)] | ||
) | ||
assert generated == GeneratedTargets( | ||
generator, | ||
{ | ||
gen_tgt("f1.proto", tags=["overridden"]), | ||
gen_tgt("f2.proto"), | ||
gen_tgt("subdir/f.proto"), | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.