Skip to content

Commit

Permalink
Merge pull request #1 from crablang/feature/crab-extension
Browse files Browse the repository at this point in the history
.crab extension
  • Loading branch information
sammi-turner authored May 30, 2023
2 parents c9b89c6 + d582eb5 commit 7cc6600
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
24 changes: 12 additions & 12 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ fn check_name(
"\n\
If you need a binary with the name \"{name}\", use a valid package \
name, and set the binary name to be different from the package. \
This can be done by setting the binary filename to `src/bin/{name}.rs` \
This can be done by setting the binary filename to `src/bin/{name}.crab` \
or change the name in Cargo.toml with:\n\
\n \
[[bin]]\n \
name = \"{name}\"\n \
path = \"src/main.rs\"\n\
path = \"src/main.crab\"\n\
",
name = name
));
Expand Down Expand Up @@ -296,27 +296,27 @@ fn detect_source_paths_and_types(

let tests = vec![
Test {
proposed_path: "src/main.rs".to_string(),
proposed_path: "src/main.crab".to_string(),
handling: H::Bin,
},
Test {
proposed_path: "main.rs".to_string(),
proposed_path: "main.crab".to_string(),
handling: H::Bin,
},
Test {
proposed_path: format!("src/{}.rs", name),
proposed_path: format!("src/{}.crab", name),
handling: H::Detect,
},
Test {
proposed_path: format!("{}.rs", name),
proposed_path: format!("{}.crab", name),
handling: H::Detect,
},
Test {
proposed_path: "src/lib.rs".to_string(),
proposed_path: "src/lib.crab".to_string(),
handling: H::Lib,
},
Test {
proposed_path: "lib.rs".to_string(),
proposed_path: "lib.crab".to_string(),
handling: H::Lib,
},
];
Expand Down Expand Up @@ -392,13 +392,13 @@ cannot automatically generate Cargo.toml as the main target would be ambiguous",
fn plan_new_source_file(bin: bool, package_name: String) -> SourceFileInformation {
if bin {
SourceFileInformation {
relative_path: "src/main.rs".to_string(),
relative_path: "src/main.crab".to_string(),
target_name: package_name,
bin: true,
}
} else {
SourceFileInformation {
relative_path: "src/lib.rs".to_string(),
relative_path: "src/lib.crab".to_string(),
target_name: package_name,
bin: false,
}
Expand Down Expand Up @@ -782,7 +782,7 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
// Calculate what `[lib]` and `[[bin]]`s we need to append to `Cargo.toml`.
for i in &opts.source_files {
if i.bin {
if i.relative_path != "src/main.rs" {
if i.relative_path != "src/main.crab" {
let mut bin = toml_edit::Table::new();
bin["name"] = toml_edit::value(i.target_name.clone());
bin["path"] = toml_edit::value(i.relative_path.clone());
Expand All @@ -794,7 +794,7 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
.expect("bin is an array of tables")
.push(bin);
}
} else if i.relative_path != "src/lib.rs" {
} else if i.relative_path != "src/lib.crab" {
let mut lib = toml_edit::Table::new();
lib["name"] = toml_edit::value(i.target_name.clone());
lib["path"] = toml_edit::value(i.relative_path.clone());
Expand Down
26 changes: 13 additions & 13 deletions src/cargo/util/toml/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,19 @@ fn clean_lib(
(Some(path), _) => package_root.join(&path.0),
(None, Some(path)) => path,
(None, None) => {
let legacy_path = package_root.join("src").join(format!("{}.rs", lib.name()));
let legacy_path = package_root.join("src").join(format!("{}.crab", lib.name()));
if edition == Edition::Edition2015 && legacy_path.exists() {
warnings.push(format!(
"path `{}` was erroneously implicitly accepted for library `{}`,\n\
please rename the file to `src/lib.rs` or set lib.path in Cargo.toml",
please rename the file to `src/lib.crab` or set lib.path in Cargo.toml",
legacy_path.display(),
lib.name()
));
legacy_path
} else {
anyhow::bail!(
"can't find library `{}`, \
rename file to `src/lib.rs` or specify lib.path",
rename file to `src/lib.crab` or specify lib.path",
lib.name()
)
}
Expand Down Expand Up @@ -355,20 +355,20 @@ fn clean_bins(

fn legacy_bin_path(package_root: &Path, name: &str, has_lib: bool) -> Option<PathBuf> {
if !has_lib {
let path = package_root.join("src").join(format!("{}.rs", name));
let path = package_root.join("src").join(format!("{}.crab", name));
if path.exists() {
return Some(path);
}
}
let path = package_root.join("src").join("main.rs");
let path = package_root.join("src").join("main.crab");
if path.exists() {
return Some(path);
}

let path = package_root
.join("src")
.join(DEFAULT_BIN_DIR_NAME)
.join("main.rs");
.join("main.crab");
if path.exists() {
return Some(path);
}
Expand Down Expand Up @@ -466,7 +466,7 @@ fn clean_benches(

let targets = {
let mut legacy_bench_path = |bench: &TomlTarget| {
let legacy_path = package_root.join("src").join("bench.rs");
let legacy_path = package_root.join("src").join("bench.crab");
if !(bench.name() == "bench" && legacy_path.exists()) {
return None;
}
Expand Down Expand Up @@ -589,7 +589,7 @@ fn clean_targets_with_legacy_path(
}

fn inferred_lib(package_root: &Path) -> Option<PathBuf> {
let lib = package_root.join("src").join("lib.rs");
let lib = package_root.join("src").join("lib.crab");
if lib.exists() {
Some(lib)
} else {
Expand All @@ -598,7 +598,7 @@ fn inferred_lib(package_root: &Path) -> Option<PathBuf> {
}

fn inferred_bins(package_root: &Path, package_name: &str) -> Vec<(String, PathBuf)> {
let main = package_root.join("src").join("main.rs");
let main = package_root.join("src").join("main.crab");
let mut result = Vec::new();
if main.exists() {
result.push((package_name.to_string(), main));
Expand Down Expand Up @@ -626,7 +626,7 @@ fn infer_from_directory(directory: &Path) -> Vec<(String, PathBuf)> {
fn infer_any(entry: &DirEntry) -> Option<(String, PathBuf)> {
if entry.file_type().map_or(false, |t| t.is_dir()) {
infer_subdirectory(entry)
} else if entry.path().extension().and_then(|p| p.to_str()) == Some("rs") {
} else if entry.path().extension().and_then(|p| p.to_str()) == Some("crab") {
infer_file(entry)
} else {
None
Expand All @@ -642,7 +642,7 @@ fn infer_file(entry: &DirEntry) -> Option<(String, PathBuf)> {

fn infer_subdirectory(entry: &DirEntry) -> Option<(String, PathBuf)> {
let path = entry.path();
let main = path.join("main.rs");
let main = path.join("main.crab");
let name = path.file_name().and_then(|n| n.to_str());
match (name, main.exists()) {
(Some(name), true) => Some((name.to_owned(), main)),
Expand Down Expand Up @@ -868,11 +868,11 @@ fn target_path_not_found_error_message(

let target_path_file = {
let mut path = target_path.clone();
path.set_extension("rs");
path.set_extension("crab");
path
};
let target_path_subdir = {
target_path.push("main.rs");
target_path.push("main.crab");
target_path
};
return [target_path_file, target_path_subdir];
Expand Down

0 comments on commit 7cc6600

Please sign in to comment.