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

Revert "Replace slashes with underscores in default crate names." #1335

Merged
merged 1 commit into from
May 13, 2022
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
4 changes: 1 addition & 3 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ def _rust_binary_impl(ctx):
crate_name = compute_crate_name(ctx.workspace_name, ctx.label, toolchain, ctx.attr.crate_name)
_assert_correct_dep_mapping(ctx)

# If the target's label contains "/" characters, we need to convert those to
# something safe, otherwise they get converted into path separators.
output = ctx.actions.declare_file(ctx.label.name.replace("/", "_") + toolchain.binary_ext)
output = ctx.actions.declare_file(ctx.label.name + toolchain.binary_ext)

deps = transform_deps(ctx.attr.deps)
proc_macro_deps = transform_deps(ctx.attr.proc_macro_deps + get_import_macro_deps(ctx))
Expand Down
4 changes: 1 addition & 3 deletions rust/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,7 @@ def name_to_crate_name(name):
Returns:
str: The name of the crate for this target.
"""
for illegal in ("-", "/"):
name = name.replace(illegal, "_")
return name
return name.replace("-", "_")

def _invalid_chars_in_crate_name(name):
"""Returns any invalid chars in the given crate name.
Expand Down
18 changes: 9 additions & 9 deletions test/unit/crate_name/crate_name_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _custom_crate_name_test_test_impl(ctx):

def _invalid_default_crate_name_test_impl(ctx):
env = analysistest.begin(ctx)
asserts.expect_failure(env, "contains invalid character(s): @")
asserts.expect_failure(env, "contains invalid character(s): /")
return analysistest.end(env)

def _invalid_custom_crate_name_test_impl(ctx):
Expand Down Expand Up @@ -119,7 +119,7 @@ no_extra_filename_test = analysistest.make(

def _crate_name_test():
rust_library(
name = "default/crate-name-library",
name = "default-crate-name-library",
srcs = ["lib.rs"],
edition = "2018",
)
Expand All @@ -132,7 +132,7 @@ def _crate_name_test():
)

rust_binary(
name = "default/crate-name-binary",
name = "default-crate-name-binary",
srcs = ["main.rs"],
edition = "2018",
)
Expand All @@ -145,7 +145,7 @@ def _crate_name_test():
)

rust_test(
name = "default/crate-name-test",
name = "default-crate-name-test",
srcs = ["main.rs"],
edition = "2018",
)
Expand All @@ -158,7 +158,7 @@ def _crate_name_test():
)

rust_library(
name = "invalid@default-crate-name",
name = "invalid/default-crate-name",
srcs = ["lib.rs"],
edition = "2018",
tags = ["manual", "norustfmt"],
Expand Down Expand Up @@ -197,7 +197,7 @@ def _crate_name_test():

default_crate_name_library_test(
name = "default_crate_name_library_test",
target_under_test = ":default/crate-name-library",
target_under_test = ":default-crate-name-library",
)

custom_crate_name_library_test(
Expand All @@ -207,7 +207,7 @@ def _crate_name_test():

default_crate_name_binary_test(
name = "default_crate_name_binary_test",
target_under_test = ":default/crate-name-binary",
target_under_test = ":default-crate-name-binary",
)

custom_crate_name_binary_test(
Expand All @@ -217,7 +217,7 @@ def _crate_name_test():

default_crate_name_test_test(
name = "default_crate_name_test_test",
target_under_test = ":default/crate-name-test",
target_under_test = ":default-crate-name-test",
)

custom_crate_name_test_test(
Expand All @@ -227,7 +227,7 @@ def _crate_name_test():

invalid_default_crate_name_test(
name = "invalid_default_crate_name_test",
target_under_test = ":invalid@default-crate-name",
target_under_test = ":invalid/default-crate-name",
)

invalid_custom_crate_name_test(
Expand Down