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

Fix packaging plugins when --no-verify is passed #1643

Merged
merged 9 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ dialoguer = "0.11.0"
directories = "5"
dunce = "1"
expect-test = "1.5"
flate2 = { version = "1.0.30", default-features = false, features = ["zlib"] }
fs4 = { version = "0.7", features = ["tokio"] }
fs_extra = "1"
futures = { version = "0.3", default-features = false, features = ["std", "async-await"] }
Expand Down
1 change: 1 addition & 0 deletions scarb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ which.workspace = true
windows-sys.workspace = true
zstd.workspace = true
cargo_metadata.workspace = true
flate2.workspace = true

[target.'cfg(not(target_os = "linux"))'.dependencies]
reqwest = { workspace = true, default-features = true }
Expand Down
33 changes: 33 additions & 0 deletions scarb/src/compiler/plugin/proc_macro/compilation.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::compiler::ProcMacroCompilationUnit;
use crate::core::{Config, Package, Workspace};
use crate::flock::Filesystem;
use crate::internal::fsx;
use crate::ops::PackageOpts;
use crate::process::exec_piping;
use crate::CARGO_MANIFEST_FILE_NAME;
use anyhow::{anyhow, Context, Result};
use camino::Utf8PathBuf;
use cargo_metadata::MetadataCommand;
use flate2::read::GzDecoder;
use indoc::formatdoc;
use libloading::library_filename;
use ra_ap_toolchain::Tool;
Expand All @@ -15,7 +17,10 @@ use serde::{Serialize, Serializer};
use serde_json::value::RawValue;
use std::fmt::Display;
use std::fs;
use std::io::{Seek, SeekFrom};
use std::ops::Deref;
use std::process::Command;
use tar::Archive;
use tracing::trace_span;

pub const PROC_MACRO_BUILD_PROFILE: &str = "release";
Expand Down Expand Up @@ -150,6 +155,33 @@ pub fn get_crate_archive_basename(package: &Package) -> Result<String> {
Ok(format!("{}-{}", package_name, package_version))
}

pub fn unpack_crate(package: &Package, config: &Config) -> Result<()> {
let archive_basename = get_crate_archive_basename(package)?;
let archive_name = format!("{}.crate", archive_basename);

let tar = package.target_path(config).into_child("package").open_ro(
DelevoXDG marked this conversation as resolved.
Show resolved Hide resolved
&archive_name,
&archive_name,
config,
)?;

// The following implementation has been copied from the `Cargo` codebase with slight modifications only.
// The original implementation can be found here:
// https://github.com/rust-lang/cargo/blob/a4600184b8d6619ed0b5a0a19946dbbe97e1d739/src/cargo/ops/cargo_package.rs#L1110

tar.deref().seek(SeekFrom::Start(0))?;
let f = GzDecoder::new(tar.deref());
let dst = tar.parent().join(&archive_basename);
if dst.exists() {
fsx::remove_dir_all(&dst)?;
}
let mut archive = Archive::new(f);
archive.set_preserve_mtime(false); // Don't set modified time to avoid filesystem errors
archive.unpack(dst.parent().unwrap())?;

Ok(())
}

pub fn fetch_crate(package: &Package, ws: &Workspace<'_>) -> Result<()> {
run_cargo(CargoAction::Fetch, package, ws)
}
Expand Down Expand Up @@ -233,6 +265,7 @@ impl<'c> From<CargoCommand<'c>> for Command {
CargoAction::Package(ref opts) => {
cmd.arg("--target-dir");
cmd.arg(args.target_dir);
cmd.arg("--no-verify");
if !opts.check_metadata {
cmd.arg("--no-metadata");
}
Expand Down
4 changes: 4 additions & 0 deletions scarb/src/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ impl FileLockGuard {
self.path.as_path()
}

pub fn parent(&self) -> &Utf8Path {
self.path.parent().unwrap()
DelevoXDG marked this conversation as resolved.
Show resolved Hide resolved
}

pub fn lock_kind(&self) -> FileLockKind {
self.lock_kind
}
Expand Down
5 changes: 4 additions & 1 deletion scarb/src/ops/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use scarb_ui::{HumanBytes, HumanCount};
use serde::Serialize;

use crate::compiler::plugin::proc_macro::compilation::{
get_crate_archive_basename, package_crate, SharedLibraryProvider,
get_crate_archive_basename, package_crate, unpack_crate, SharedLibraryProvider,
};
use crate::core::publishing::manifest_normalization::prepare_manifest_for_publish;
use crate::core::publishing::source::list_source_files;
Expand Down Expand Up @@ -279,6 +279,9 @@ fn prepare_archive_recipe(
));
}

// Unpack .crate to make normalized Cargo.toml available.
unpack_crate(pkg, ws.config())?;

// Add normalized Cargo.toml file.
recipe.push(ArchiveFile {
path: CARGO_MANIFEST_FILE_NAME.into(),
Expand Down
23 changes: 23 additions & 0 deletions scarb/tests/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,29 @@ fn package_without_verification() {
"#});
}

#[test]
fn package_cairo_plugin_without_verification() {
let t = TempDir::new().unwrap();
CairoPluginProjectBuilder::default().build(&t);

Scarb::quick_snapbox()
.arg("package")
.arg("--no-verify")
.arg("--no-metadata")
.env("CARGO_TERM_QUIET", "true")
.current_dir(&t)
.assert()
.success()
.stdout_matches(indoc! {r#"
[..] Packaging some v1.0.0 [..]
[..]warn: package name or version differs between Cargo manifest and Scarb manifest
[..]Scarb manifest: `some-1.0.0`, Cargo manifest: `some-0.1.0`
[..]this might become an error in future Scarb releases

[..] Packaged [..]
"#});
}

#[test]
fn package_without_publish_metadata() {
let t = TempDir::new().unwrap();
Expand Down
Loading