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

go: remove notion of separate __obj__ directory #17775

Merged
merged 2 commits into from
Dec 12, 2022

Conversation

tdyas
Copy link
Contributor

@tdyas tdyas commented Dec 11, 2022

Remove the notion of a separate __obj__ directory (obj_dir_path in the code) for compiling object files (e.g., Cgo and assembly) and just generate and capture object files in the same directory as the sources they are built from.

The issue is that the user can configure references to the source directory in -I and other compiler/assembler options using the ${SRCDIR} syntax. With a separate object directory, the rules would need additional code to either copy files around or duplicate -I and other options to account for both the original sources directory and the objects directory if code wanted to be agnostic to the location of files that it expected to be in the package directory.

The idea for an objects tmp directory originally came from the go toolchain. go copies source files into the objects directory to avoid the duplication problem mentioned above. It makes sense for the Go toolchain to do this because the original sources are the user's actual source repository. Writing temporary object files into the original repository would make for a bad user experience.

Pants, on the other hand, uses an execution sandbox and does not have the same issue about modifying the original repository during a build. Thus, it makes sense in Pants to avoid copying files and just put object files next to the sources in the execution sandbox they are built from. This means the Cgo rules can avoid having to parse and duplicate options in which ${SRCDIR} is used.

This is a partial fix for #17592. It fixes errors due to the mishandling of ${SRCDIR} by the Cgo rules in not duplicating options that had ${SRCDIR} in them to account for both the original sources directory and the objects directory.

@tdyas tdyas added backend: Go Go backend-related issues category:bugfix Bug fixes for released features labels Dec 11, 2022
@tdyas tdyas changed the title go: remove notion of separate "object" directory go: remove notion of separate __obj__ directory Dec 11, 2022
sandbox_root="$(/bin/pwd)"
args=("${@//__PANTS_SANDBOX_ROOT__/$sandbox_root}")
export sandbox_root="$(/bin/pwd)"
ln -s "${sandbox_root}" __pants_sandbox_root__
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this symlink for? I don't see where it's used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh leftover from the original PR that I was cleaning up. Good spotting it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Context: I had originally tried to use the symlink to solve the problem solved by the next PR (not this one). Missed removing this for this PR. Grr..

@tdyas tdyas merged commit 60f77fb into pantsbuild:main Dec 12, 2022
@tdyas tdyas deleted the golang_no_obj_dir branch December 12, 2022 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Go Go backend-related issues category:bugfix Bug fixes for released features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants