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

Fixed missing use of rust_rules_workspace_name setting in templates #331

Merged
merged 1 commit into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions impl/src/bin/cargo-raze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ fn main() -> Result<()> {
package_aliases_dir: settings.package_aliases_dir,
vendored_buildfile_name: settings.output_buildfile_suffix,
bazel_root: cargo_raze_working_dir,
rust_rules_workspace_name: settings.rust_rules_workspace_name,
experimental_api: settings.experimental_api,
};
let bazel_file_outputs = match &settings.genmode {
Expand Down
1 change: 1 addition & 0 deletions impl/src/rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ pub struct RenderDetails {
pub package_aliases_dir: String,
pub vendored_buildfile_name: String,
pub bazel_root: PathBuf,
pub rust_rules_workspace_name: String,
pub experimental_api: bool,
}
28 changes: 20 additions & 8 deletions impl/src/rendering/bazel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ impl BazelRenderer {
&self,
workspace_context: &WorkspaceContext,
package: &CrateContext,
rust_rules_workspace_name: &str,
) -> Result<String, tera::Error> {
let mut context = Context::new();
context.insert("workspace", &workspace_context);
context.insert("crate", &package);
context.insert("rust_rules_workspace_name", rust_rules_workspace_name);
self
.internal_renderer
.render("templates/crate.BUILD.template", &context)
Expand All @@ -154,10 +156,12 @@ impl BazelRenderer {
&self,
workspace_context: &WorkspaceContext,
package: &CrateContext,
rust_rules_workspace_name: &str,
) -> Result<String, tera::Error> {
let mut context = Context::new();
context.insert("workspace", &workspace_context);
context.insert("crate", &package);
context.insert("rust_rules_workspace_name", rust_rules_workspace_name);
self
.internal_renderer
.render("templates/crate.BUILD.template", &context)
Expand Down Expand Up @@ -358,13 +362,16 @@ impl BuildRenderer for BazelRenderer {
}

for package in crate_contexts {
let rendered_crate_build_file =
self
.render_crate(&workspace_context, &package)
.map_err(|e| RazeError::Rendering {
crate_name_opt: None,
message: unwind_tera_error!(e),
})?;
let rendered_crate_build_file = self
.render_crate(
&workspace_context,
&package,
&render_details.rust_rules_workspace_name,
)
.map_err(|e| RazeError::Rendering {
crate_name_opt: None,
message: unwind_tera_error!(e),
})?;

let final_crate_build_file =
include_additional_build_file(package, rendered_crate_build_file)?;
Expand Down Expand Up @@ -406,7 +413,11 @@ impl BuildRenderer for BazelRenderer {

for package in crate_contexts {
let rendered_crate_build_file = self
.render_remote_crate(&workspace_context, &package)
.render_remote_crate(
&workspace_context,
&package,
&render_details.rust_rules_workspace_name,
)
.map_err(|e| RazeError::Rendering {
crate_name_opt: Some(package.pkg_name.to_owned()),
message: unwind_tera_error!(e),
Expand Down Expand Up @@ -488,6 +499,7 @@ mod tests {
package_aliases_dir: "cargo".to_string(),
vendored_buildfile_name: buildfile_suffix.to_owned(),
bazel_root: PathBuf::from("/some/bazel/root"),
rust_rules_workspace_name: "rules_rust".to_owned(),
experimental_api: true,
}
}
Expand Down
2 changes: 1 addition & 1 deletion impl/src/rendering/templates/crate.BUILD.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DO NOT EDIT! Replaced on runs of cargo-raze

# buildifier: disable=load
load(
"@io_bazel_rules_rust//rust:rust.bzl",
"@{{ rust_rules_workspace_name }}//rust:rust.bzl",
"rust_binary",
"rust_library",
"rust_test",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# buildifier: disable=load-on-top
load(
"@io_bazel_rules_rust//cargo:cargo_build_script.bzl",
"@{{ rust_rules_workspace_name }}//cargo:cargo_build_script.bzl",
"cargo_build_script",
)

Expand Down