Skip to content

Commit

Permalink
Fixed a bug where export_files was being rendered into BUILD files it…
Browse files Browse the repository at this point in the history
… shouldn't have been (#337)

* Fixed a bug where export_files was being rendered into BUILD files it shouldn't have been

* Updated examples

* Fixed ordering issue
  • Loading branch information
UebelAndre committed Dec 30, 2020
1 parent 330fa0b commit 00fc4bb
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 86 deletions.
8 changes: 0 additions & 8 deletions examples/remote/cargo_workspace/num_printer/cargo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,3 @@ alias(
"manual",
],
)

# Export file for Stardoc support
exports_files(
[
"crates.bzl",
],
visibility = ["//visibility:public"],
)
8 changes: 0 additions & 8 deletions examples/remote/cargo_workspace/printer/cargo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,3 @@ alias(
"manual",
],
)

# Export file for Stardoc support
exports_files(
[
"crates.bzl",
],
visibility = ["//visibility:public"],
)
8 changes: 0 additions & 8 deletions examples/remote/cargo_workspace/rng/cargo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,3 @@ alias(
"manual",
],
)

# Export file for Stardoc support
exports_files(
[
"crates.bzl",
],
visibility = ["//visibility:public"],
)
8 changes: 8 additions & 0 deletions examples/vendored/cargo_workspace/cargo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ cargo-raze generated Bazel file.
DO NOT EDIT! Replaced on runs of cargo-raze
"""

# Export file for Stardoc support
exports_files(
[
"crates.bzl",
],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,3 @@ alias(
"manual",
],
)

# Export file for Stardoc support
exports_files(
[
"crates.bzl",
],
visibility = ["//visibility:public"],
)
8 changes: 0 additions & 8 deletions examples/vendored/cargo_workspace/printer/cargo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,3 @@ alias(
"manual",
],
)

# Export file for Stardoc support
exports_files(
[
"crates.bzl",
],
visibility = ["//visibility:public"],
)
8 changes: 0 additions & 8 deletions examples/vendored/cargo_workspace/rng/cargo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,3 @@ alias(
"manual",
],
)

# Export file for Stardoc support
exports_files(
[
"crates.bzl",
],
visibility = ["//visibility:public"],
)
8 changes: 0 additions & 8 deletions examples/vendored/complicated_cargo_library/cargo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,3 @@ alias(
"manual",
],
)

# Export file for Stardoc support
exports_files(
[
"crates.bzl",
],
visibility = ["//visibility:public"],
)
8 changes: 0 additions & 8 deletions examples/vendored/hello_cargo_library/cargo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,3 @@ alias(
"manual",
],
)

# Export file for Stardoc support
exports_files(
[
"crates.bzl",
],
visibility = ["//visibility:public"],
)
8 changes: 0 additions & 8 deletions examples/vendored/non_cratesio_library/cargo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,3 @@ alias(
"manual",
],
)

# Export file for Stardoc support
exports_files(
[
"crates.bzl",
],
visibility = ["//visibility:public"],
)
34 changes: 20 additions & 14 deletions impl/src/rendering/bazel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,20 @@ impl BazelRenderer {
})?
};

rendered_alias_build_file += EXPORTS_FILES;
// Only the root package will have a `crates.bzl` file to export
let is_root_workspace_member = member_path
.to_str()
// Root workspace paths will are represented by an exmpty string
.and_then(|member_path| Some(member_path.is_empty()))
.unwrap_or(false);
if is_root_workspace_member {
// In remote genmode, a `crates.bzl` file will always be rendered. For
// vendored genmode, one is only rendered when using the experimental
// api so it would otherwise be incorrect to export a nonexistent file.
if is_remote_mode || render_details.experimental_api {
rendered_alias_build_file += EXPORTS_FILES;
}
}

file_outputs.push(FileOutputs {
path: render_details
Expand Down Expand Up @@ -327,6 +340,8 @@ impl BuildRenderer for BazelRenderer {
.as_path()
.join(&render_details.path_prefix);

file_outputs.extend(self.render_aliases(planned_build, render_details, false)?);

if render_details.experimental_api {
let crates_bzl_file_path = path_prefix.as_path().join("crates.bzl");
let rendered_crates_bzl_file = self
Expand All @@ -347,17 +362,10 @@ impl BuildRenderer for BazelRenderer {
});

// Ensure there is always a `BUILD.bazel` file to accompany `crates.bzl`
let crates_bzl_pkg_file = path_prefix.as_path().join("BUILD.bazel");
let outputs_contain_crates_bzl_build_file = file_outputs
.iter()
.any(|output| output.path == crates_bzl_pkg_file);
if !outputs_contain_crates_bzl_build_file {
file_outputs.push(FileOutputs {
path: crates_bzl_pkg_file,
contents: self
.internal_renderer
.render("templates/partials/header.template", &tera::Context::new())?,
});
if let Some(rendered_output) =
self.render_crates_bzl_package_file(&path_prefix, &file_outputs)?
{
file_outputs.push(rendered_output);
}
}

Expand All @@ -382,8 +390,6 @@ impl BuildRenderer for BazelRenderer {
})
}

file_outputs.extend(self.render_aliases(planned_build, render_details, false)?);

Ok(file_outputs)
}

Expand Down

0 comments on commit 00fc4bb

Please sign in to comment.