-
-
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.
# 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]
- Loading branch information
1 parent
239b695
commit 1cd9a53
Showing
5 changed files
with
135 additions
and
3 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
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
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,52 @@ | ||
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from dataclasses import dataclass | ||
|
||
from pants.backend.go.target_types import GoFirstPartyPackageSourcesField | ||
from pants.backend.go.util_rules.build_pkg import ( | ||
BuildGoPackageTargetRequest, | ||
FallibleBuiltGoPackage, | ||
) | ||
from pants.core.goals.check import CheckRequest, CheckResult, CheckResults | ||
from pants.engine.rules import Get, MultiGet, collect_rules, rule | ||
from pants.engine.target import FieldSet | ||
from pants.engine.unions import UnionRule | ||
|
||
|
||
@dataclass(frozen=True) | ||
class GoCheckFieldSet(FieldSet): | ||
required_fields = (GoFirstPartyPackageSourcesField,) | ||
|
||
sources: GoFirstPartyPackageSourcesField | ||
|
||
|
||
class GoCheckRequest(CheckRequest): | ||
field_set_type = GoCheckFieldSet | ||
|
||
|
||
@rule | ||
async def check_go(request: GoCheckRequest) -> CheckResults: | ||
results = await MultiGet( | ||
Get(FallibleBuiltGoPackage, BuildGoPackageTargetRequest(field_set.address)) | ||
for field_set in request.field_sets | ||
) | ||
# TODO: Update `build_pkg.py` to use streaming workunits to log compilation results. | ||
# NB: We return CheckResults with exit codes for the root targets, but we do not pass | ||
# stdout/stderr because it will already have been rendered as streaming. | ||
return CheckResults( | ||
[ | ||
CheckResult( | ||
result.exit_code, | ||
stdout="", | ||
stderr="", | ||
partition_description=None, | ||
) | ||
for result in results | ||
], | ||
checker_name="go", | ||
) | ||
|
||
|
||
def rules(): | ||
return [*collect_rules(), UnionRule(CheckRequest, GoCheckRequest)] |
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,80 @@ | ||
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
from textwrap import dedent | ||
|
||
import pytest | ||
|
||
from pants.backend.go import target_type_rules | ||
from pants.backend.go.goals import check | ||
from pants.backend.go.goals.check import GoCheckFieldSet, GoCheckRequest | ||
from pants.backend.go.target_types import GoModTarget | ||
from pants.backend.go.util_rules import ( | ||
assembly, | ||
build_pkg, | ||
first_party_pkg, | ||
go_mod, | ||
import_analysis, | ||
sdk, | ||
third_party_pkg, | ||
) | ||
from pants.core.goals.check import CheckResult, CheckResults | ||
from pants.engine.addresses import Address | ||
from pants.testutil.rule_runner import QueryRule, RuleRunner | ||
|
||
|
||
@pytest.fixture | ||
def rule_runner() -> RuleRunner: | ||
rule_runner = RuleRunner( | ||
rules=[ | ||
*check.rules(), | ||
*sdk.rules(), | ||
*assembly.rules(), | ||
*build_pkg.rules(), | ||
*import_analysis.rules(), | ||
*go_mod.rules(), | ||
*first_party_pkg.rules(), | ||
*third_party_pkg.rules(), | ||
*target_type_rules.rules(), | ||
QueryRule(CheckResults, [GoCheckRequest]), | ||
], | ||
target_types=[GoModTarget], | ||
) | ||
rule_runner.set_options([], env_inherit={"PATH"}) | ||
return rule_runner | ||
|
||
|
||
def test_check(rule_runner: RuleRunner) -> None: | ||
rule_runner.write_files( | ||
{ | ||
"go.mod": dedent( | ||
"""\ | ||
module example.com/greeter | ||
go 1.17 | ||
""" | ||
), | ||
"bad/f.go": "invalid!!!", | ||
"good/f.go": dedent( | ||
"""\ | ||
package greeter | ||
import "fmt" | ||
func Hello() { | ||
fmt.Println("Hello world!") | ||
} | ||
""" | ||
), | ||
"BUILD": "go_mod(name='mod')", | ||
} | ||
) | ||
targets = [ | ||
rule_runner.get_target(Address("", target_name="mod", generated_name="./bad")), | ||
rule_runner.get_target(Address("", target_name="mod", generated_name="./good")), | ||
] | ||
results = rule_runner.request( | ||
CheckResults, [GoCheckRequest(GoCheckFieldSet.create(tgt) for tgt in targets)] | ||
).results | ||
assert set(results) == {CheckResult(0, "", "", None), CheckResult(1, "", "", None)} |
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