Skip to content

Commit

Permalink
Remove cargo publish workaround
Browse files Browse the repository at this point in the history
This wasn't really working, the compile succeeded during cargo publish
but the sources are still not included in the crate.
This is because cargo ignores all subdirectories with a Cargo.toml file:
rust-lang/cargo#8597
  • Loading branch information
Abestanis committed Aug 4, 2023
1 parent c5702db commit 1af6a5f
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ fn prepare_source(
source: &Source,
generated_project_dir: &Path,
source_file: &Path,
crate_dir: &Path,
args: &MatchTelecommandArgs,
) -> syn::Result<(Option<File>, PathBuf)> {
Ok(match source {
Expand Down Expand Up @@ -416,38 +415,10 @@ fn prepare_source(
let generated_project_dir = if path.is_absolute() {
path.clone()
} else {
// Cargo publish copies the source files into a new directory, which can break relative paths.
// Attempt to recover the original source code path.
let Ok(crate_name) = std::env::var("CARGO_PKG_NAME") else {
return Err(Error::new(
Span::call_site(),
"Unable to get crate name",
));
};
let Ok(crate_version) = std::env::var("CARGO_PKG_VERSION") else {
return Err(Error::new(
Span::call_site(),
"Unable to get crate version",
));
};
let cargo_publish_path = PathBuf::from("target")
.join("package")
.join(format!("{crate_name}-{crate_version}"));
let source_dir = source_file
source_file
.parent()
.expect("Should be able to resolve the parent directory of the source file");
let base_path = if crate_dir.ends_with(&cargo_publish_path) {
let relative_source_path =
source_dir.strip_prefix(crate_dir).unwrap_or(source_dir);
let mut base_path = crate_dir;
for _ in cargo_publish_path.iter() {
base_path = base_path.parent().expect("Should be able to remove path parts after checking that a path ends with them");
}
base_path.join(relative_source_path)
} else {
source_dir.to_path_buf()
};
base_path.join(path)
.expect("Should be able to resolve the parent directory of the source file")
.join(path)
};
if !generated_project_dir.exists() {
return Err(Error::new(
Expand Down Expand Up @@ -496,7 +467,6 @@ fn compile_rust(args: MatchTelecommandArgs) -> syn::Result<PathBuf> {
&args.sources[i],
&generated_project_dir,
&source_file,
&crate_dir,
&args,
) {
Ok((lock_file, new_generated_project_dir)) => {
Expand Down

0 comments on commit 1af6a5f

Please sign in to comment.