-
Notifications
You must be signed in to change notification settings - Fork 480
Handle files from external repos (fix breaking change in Bazel 3.7.0) #2138
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2b529aa
Consider workspace_root in package_root
jgsogo c8bbfb8
relativize for different cfgs
jgsogo 0a85c6b
trigger CI again
jgsogo d046a6d
trigger CI again
jgsogo b245e57
Merge branch 'main' into fix/1780-external-repo
jgsogo d216ef9
Merge remote-tracking branch 'upstream/main' into fix/1780-external-repo
jgsogo 17c9d01
move logic to external function
jgsogo 5b90787
Merge remote-tracking branch 'upstream/main' into fix/1780-external-repo
jgsogo d30367f
Add test
jgsogo e3895d4
Add test to CI
jgsogo 4ff6df5
fix buildifier, fmt
jgsogo ef26d2f
simplify source
jgsogo e9e0a31
trigger CI
jgsogo bb88bb8
Merge remote-tracking branch 'upstream/main' into fix/1780-external-repo
jgsogo a891183
Review feedback - improve comment
jgsogo 8d0b467
Review feedback - different strategy for testing
jgsogo 923ac33
run buildifier
jgsogo ae8c6ba
Update .gitignore
jgsogo d24e2dc
trigger CI
jgsogo 0fa922e
Update test/generated_inputs/BUILD.bazel
UebelAndre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
"""External repository for `generated_inputs` tests""" | ||
|
||
_BUILD_FILE_CONTENT = """ | ||
load("@rules_rust//rust:defs.bzl", "rust_library") | ||
load("@bazel_skylib//rules:write_file.bzl", "write_file") | ||
|
||
write_file( | ||
name = "generate_src", | ||
out = "src.rs", | ||
content = ["pub fn forty_two() -> i32 { 42 }"], | ||
) | ||
|
||
rust_library( | ||
name = "generated_inputs_external_repo", | ||
srcs = [ | ||
"lib.rs", | ||
":generate_src", | ||
], | ||
edition = "2021", | ||
visibility = ["//visibility:public"], | ||
) | ||
""" | ||
|
||
_LIB_RS_CONTENT = """ | ||
mod src; | ||
|
||
pub fn forty_two_from_generated_src() -> String { | ||
format!("{}", src::forty_two()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
#[test] | ||
fn test_forty_two_as_string() { | ||
assert_eq!(super::forty_two_from_generated_src(), "42"); | ||
} | ||
} | ||
""" | ||
|
||
def _generated_inputs_in_external_repo_impl(repository_ctx): | ||
# Create repository files (not in the root directory) | ||
repo_path = repository_ctx.path("lib") | ||
repository_ctx.file( | ||
"{}/BUILD.bazel".format(repo_path), | ||
content = _BUILD_FILE_CONTENT, | ||
) | ||
repository_ctx.file( | ||
"{}/lib.rs".format(repo_path), | ||
content = _LIB_RS_CONTENT, | ||
) | ||
|
||
_generated_inputs_in_external_repo = repository_rule( | ||
implementation = _generated_inputs_in_external_repo_impl, | ||
doc = ( | ||
"A test repository rule providing a Rust library using generated sources" | ||
), | ||
) | ||
|
||
def generated_inputs_in_external_repo(): | ||
"""Define the a test repository with Rust library using generated sources""" | ||
|
||
_generated_inputs_in_external_repo( | ||
name = "generated_inputs_in_external_repo", | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit, can you put the action to symlink back in
_transform_sources
? The thing I wanted to make crystal clear is what is happening with the path manipulation here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I'm not sure about it, there will be more duplicated logic and more lines. As a newcomer, I find it harder to read (I was not used to the previous implementation).
Maybe I'm missing something and you have a much better proposal. I will work on the comment about the tests and come back here later to think about something better/easier.