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

refactor(toml): Decouple target discovery from Target creation #13701

Merged
merged 23 commits into from
Apr 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
71e362f
test(package): Clean up a build.rs test
epage Apr 3, 2024
cc9710e
refactor(toml): Be consistent in readme resolve name
epage Apr 3, 2024
d3cfa7f
refactor(toml): Clarify which manifest is being used
epage Apr 4, 2024
b86b4b4
refactor(toml): Clarify conversion nature of target fn's
epage Apr 4, 2024
74e8d76
refactor(toml): Simplify lib resolving
epage Apr 5, 2024
6ef9779
refactor(toml): Abstract out lib name validation
epage Apr 5, 2024
019bae2
refactor(toml): Consolidate lib discovery
epage Apr 5, 2024
f900b3f
refactor(toml): Split lib discovery from Target creation
epage Apr 5, 2024
b08d197
refactor(toml): Move lib resolving up a level
epage Apr 5, 2024
f2b0678
refactor(toml): Pull out legacy_bin_path
epage Apr 4, 2024
b061bc5
refactor(toml): Abstract out bin name validation
epage Apr 4, 2024
72ee140
refactor(toml): Split bin discovery from Target creation
epage Apr 4, 2024
c699941
refactor(toml): Move bin resolving up a level
epage Apr 4, 2024
943f9bc
refactor(toml): Track paths in TomlTarget, rather than next to it
epage Apr 4, 2024
36891ba
refactor(toml): Move unique name validation out of resolving
epage Apr 4, 2024
8439a4b
refactor(toml): Split target discovery from Target creation
epage Apr 4, 2024
e8f56df
refactor(toml): Clarify meaning of target 'clean' fn's
epage Apr 4, 2024
f243c91
refactor(toml): Move target resolving up a level
epage Apr 4, 2024
b2ca065
refactor(toml): Prefer common constant for bench dir name
epage Apr 5, 2024
b6c7544
refactor(toml): Avoid incomplete constant for bin dir name
epage Apr 5, 2024
f38136e
refactor(toml): Give higher level info to target inference
epage Apr 4, 2024
f1f7bbf
refactor(toml): Simplify file/dir target inference
epage Apr 4, 2024
ff41868
refactor(toml): Use relative paths in resolved targets
epage Apr 4, 2024
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
Prev Previous commit
Next Next commit
refactor(toml): Abstract out bin name validation
  • Loading branch information
epage committed Apr 5, 2024
commit b061bc5e8317a2b776f793cb445a988814c50133
29 changes: 17 additions & 12 deletions src/cargo/util/toml/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,17 @@ fn to_bin_targets(

// This loop performs basic checks on each of the TomlTarget in `bins`.
for bin in &bins {
validate_bin_name(bin, warnings)?;

// For each binary, check if the `filename` parameter is populated. If it is,
// check if the corresponding cargo feature has been activated.
if bin.filename.is_some() {
features.require(Feature::different_binary_name())?;
}

validate_target_name(bin, "binary", "bin", warnings)?;

let name = name_or_panic(bin).to_owned();

if let Some(crate_types) = bin.crate_types() {
if !crate_types.is_empty() {
let name = name_or_panic(bin);
errors.push(format!(
"the target `{}` is a binary and can't have any \
crate-types set (currently \"{}\")",
Expand All @@ -323,20 +322,13 @@ fn to_bin_targets(
}

if bin.proc_macro() == Some(true) {
let name = name_or_panic(bin);
errors.push(format!(
"the target `{}` is a binary and can't have `proc-macro` \
set `true`",
name
));
}

if restricted_names::is_conflicting_artifact_name(&name) {
anyhow::bail!(
"the binary target name `{}` is forbidden, \
it conflicts with cargo's build directory names",
name
)
}
}

validate_unique_names(&bins, "binary")?;
Expand Down Expand Up @@ -794,6 +786,19 @@ fn validate_lib_name(target: &TomlTarget, warnings: &mut Vec<String>) -> CargoRe
Ok(())
}

fn validate_bin_name(bin: &TomlTarget, warnings: &mut Vec<String>) -> CargoResult<()> {
validate_target_name(bin, "binary", "bin", warnings)?;
let name = name_or_panic(bin).to_owned();
if restricted_names::is_conflicting_artifact_name(&name) {
anyhow::bail!(
"the binary target name `{name}` is forbidden, \
it conflicts with cargo's build directory names",
)
}

Ok(())
}

fn validate_target_name(
target: &TomlTarget,
target_kind_human: &str,
Expand Down