Skip to content

Commit

Permalink
Common glob excludes (#1673)
Browse files Browse the repository at this point in the history
* fix: common glob exclude

* fix: clippy redundant_static_lifetimes warn
  • Loading branch information
bazaglia committed Nov 26, 2022
1 parent 61b99cd commit ed32b6d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions crate_universe/src/rendering/template_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ pub struct TemplateEngine {
context: tera::Context,
}

const COMMON_GLOB_EXCLUDES: &[&str] = &[
"**/* *",
"BUILD.bazel",
"BUILD",
"WORKSPACE.bazel",
"WORKSPACE",
];

impl TemplateEngine {
pub fn new(render_config: &RenderConfig) -> Self {
let mut tera = Tera::default();
Expand Down Expand Up @@ -202,6 +210,7 @@ impl TemplateEngine {
context.insert("vendor_mode", &render_config.vendor_mode);
context.insert("regen_command", &render_config.regen_command);
context.insert("Null", &tera::Value::Null);
context.insert("common_glob_excludes", &COMMON_GLOB_EXCLUDES);
context.insert(
"default_package_name",
&match render_config.default_package_name.as_ref() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cargo_build_script(
name = "{{ crate.name }}_build_script",
aliases = {% set selectable = build_aliases %}{% include "partials/crate/aliases.j2" -%},
build_script_env = {% set selectable = crate.build_script_attrs | get(key="build_script_env", default=Null) %}{% include "partials/starlark/selectable_dict.j2" -%},
compile_data = {% if crate.build_script_attrs | get(key="compile_data_glob") %}glob({{ crate.build_script_attrs.compile_data_glob | json_encode | safe }}) + {% endif %}{% set selectable = crate.build_script_attrs | get(key="compile_data", default=Null) %}{% include "partials/starlark/selectable_list.j2" %},
compile_data = {% if crate.build_script_attrs | get(key="compile_data_glob") %}glob(include = {{ crate.build_script_attrs.compile_data_glob | json_encode | safe }}, exclude = {{ common_glob_excludes | json_encode() | safe }}) + {% endif %}{% set selectable = crate.build_script_attrs | get(key="compile_data", default=Null) %}{% include "partials/starlark/selectable_list.j2" %},
crate_name = "{{ sanitize_module_name(crate_name=target.crate_name) }}",
crate_root = "{{ target.crate_root }}",
crate_features = [
Expand All @@ -13,7 +13,7 @@ cargo_build_script(
{%- endfor %}
{%- endif %}
],
data = {% if crate.build_script_attrs | get(key="data_glob") %}glob({{ crate.build_script_attrs.data_glob | json_encode | safe }}) + {% endif %}{% set selectable = crate.build_script_attrs | get(key="data", default=Null) %}{% include "partials/starlark/selectable_list.j2" %},
data = {% if crate.build_script_attrs | get(key="data_glob") %}glob(include = {{ crate.build_script_attrs.data_glob | json_encode | safe }}, exclude = {{ common_glob_excludes | json_encode() | safe }}) + {% endif %}{% set selectable = crate.build_script_attrs | get(key="data", default=Null) %}{% include "partials/starlark/selectable_list.j2" %},
deps = [
{%- for dep in crate.build_script_attrs | get(key="extra_deps", default=[]) %}
"{{ dep }}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
compile_data = {% if crate.common_attrs | get(key="compile_data_glob") %}glob(include = {{ crate.common_attrs.compile_data_glob | json_encode | safe }}, exclude = ["BUILD", "BUILD.bazel", "WORKSPACE", "WORKSPACE.bazel"]) + {% endif %}{% set selectable = crate.common_attrs | get(key="compile_data", default=default_select_list) %}{% include "partials/starlark/selectable_list.j2" -%},
compile_data = {% if crate.common_attrs | get(key="compile_data_glob") %}glob(include = {{ crate.common_attrs.compile_data_glob | json_encode | safe }}, exclude = {{ common_glob_excludes | json_encode() | safe }}) + {% endif %}{% set selectable = crate.common_attrs | get(key="compile_data", default=default_select_list) %}{% include "partials/starlark/selectable_list.j2" -%},
crate_root = "{{ target.crate_root }}",
crate_features = [
{%- for feature in crate.common_attrs | get(key="crate_features", default=[]) %}
"{{ feature }}",
{%- endfor %}
],
data = {% if crate.common_attrs | get(key="data_glob") %}glob(include = {{ crate.common_attrs.data_glob | json_encode | safe }}, exclude = ["BUILD", "BUILD.bazel", "WORKSPACE", "WORKSPACE.bazel", "**/* *"]) + {% endif %}{% set selectable = crate.common_attrs | get(key="data", default=default_select_list) %}{% include "partials/starlark/selectable_list.j2" -%},
data = {% if crate.common_attrs | get(key="data_glob") %}glob(include = {{ crate.common_attrs.data_glob | json_encode | safe }}, exclude = {{ common_glob_excludes | json_encode() | safe }}) + {% endif %}{% set selectable = crate.common_attrs | get(key="data", default=default_select_list) %}{% include "partials/starlark/selectable_list.j2" -%},
edition = "{{ crate.common_attrs.edition }}",
{%- if crate.common_attrs | get(key="linker_script", default=Null) %}
linker_script = "{{ crate.common_attrs.linker_script }}",
Expand Down

0 comments on commit ed32b6d

Please sign in to comment.