Skip to content

Commit

Permalink
Fixed missing use of rust_rules_workspace_name setting in templates (
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Dec 29, 2020
1 parent 8c96a39 commit 6258c69
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions impl/src/bin/cargo-raze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ fn render_files(
package_aliases_dir: settings.package_aliases_dir.clone(),
vendored_buildfile_name: settings.output_buildfile_suffix.clone(),
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

0 comments on commit 6258c69

Please sign in to comment.