Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[internal] Refactor computing metadata for first-party Go packages #13161

Merged
merged 1 commit into from
Oct 8, 2021

Conversation

Eric-Arellano
Copy link
Contributor

This renames the type to FirstPartyPkgInfo and renames the file.

It removes all unused fields so that it's the simplest implementation possible. We can add back fields for things like .h files when we add support.

[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]
Comment on lines -117 to -129
# Raise an exception if any unsupported source file keys are present in the metadata.
for key in (
"CompiledGoFiles",
"FFiles",
"SwigFiles",
"SwigCXXFiles",
):
files = metadata.get(key, [])
if files:
raise ValueError(
f"The go_package at address {address} contains the following unsupported source "
f"files that were detected under the key '{key}': {', '.join(files)}."
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NB that these errors should have never actually triggered. We run in a sandbox, and we ban the sources field from having those file endings. So this code path couldn't happen afaict.

Copy link
Contributor

Choose a reason for hiding this comment

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

As explained in my other comment, it can happen for cgo since that is just a .go file that does import "C".

Copy link
Contributor Author

@Eric-Arellano Eric-Arellano Oct 8, 2021

Choose a reason for hiding this comment

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

Ah, specifically CGoFiles is the issue. Everything else has a different file extension. See the entry on GoFiles.

        // Source files
        GoFiles         []string   // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
        CgoFiles        []string   // .go source files that import "C"
        CompiledGoFiles []string   // .go files presented to compiler (when using -compiled)
        IgnoredGoFiles  []string   // .go source files ignored due to build constraints
        IgnoredOtherFiles []string // non-.go source files ignored due to build constraints
        CFiles          []string   // .c source files
        CXXFiles        []string   // .cc, .cxx and .cpp source files
        MFiles          []string   // .m source files
        HFiles          []string   // .h, .hh, .hpp and .hxx source files
        FFiles          []string   // .f, .F, .for and .f90 Fortran source files
        SFiles          []string   // .s source files
        SwigFiles       []string   // .swig files
        SwigCXXFiles    []string   // .swigcxx files
        SysoFiles       []string   // .syso object files to add to archive
        TestGoFiles     []string   // _test.go files in package
        XTestGoFiles    []string   // _test.go files outside package

Will fix in a followup.

working_dir=owning_go_mod.address.spec_path,
),
)
metadata = json.loads(result.stdout)
Copy link
Contributor

Choose a reason for hiding this comment

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

This method should error if any of the supported source code keys are set in the JSON. This will at least prevent Pants from acting incorrectly with respect to first-party code. For example, imagine the user writes a cgo file (which is triggered merely by including import "C" in a .go file). We want to alert the user that we will not do what they expect in that instance. Plus it raises our attention to what are users will need as they contact us for such support.

Copy link
Contributor

@tdyas tdyas Oct 8, 2021

Choose a reason for hiding this comment

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

I used to have code for that in an earlier version of the plugin but got rid of it when ResolvedGoPackage had all of the source-related fields added to it. (And then I never added back erroring on unsupported source files, e.g. cgo.) But we should fix up erroring now.

Comment on lines -117 to -129
# Raise an exception if any unsupported source file keys are present in the metadata.
for key in (
"CompiledGoFiles",
"FFiles",
"SwigFiles",
"SwigCXXFiles",
):
files = metadata.get(key, [])
if files:
raise ValueError(
f"The go_package at address {address} contains the following unsupported source "
f"files that were detected under the key '{key}': {', '.join(files)}."
)
Copy link
Contributor

Choose a reason for hiding this comment

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

As explained in my other comment, it can happen for cgo since that is just a .go file that does import "C".

@Eric-Arellano Eric-Arellano enabled auto-merge (squash) October 8, 2021 02:05
@Eric-Arellano Eric-Arellano merged commit 178ffba into pantsbuild:main Oct 8, 2021
@Eric-Arellano Eric-Arellano deleted the pkg-info branch October 8, 2021 02:56
@stuhood stuhood mentioned this pull request Oct 11, 2021
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.

2 participants