diff --git a/prdoc/pr_9670.prdoc b/prdoc/pr_9670.prdoc new file mode 100644 index 0000000000000..5295faeb56f1e --- /dev/null +++ b/prdoc/pr_9670.prdoc @@ -0,0 +1,14 @@ +title: Move revive fixtures into release directory +doc: +- audience: Runtime Dev + description: |- + https://github.com/paritytech/polkadot-sdk/pull/8980 did fix the fellowship CI but it triggers a rebuild of the fixtures every single time you run tests. Annoying during development. + + Instead of rebuilding, we just move the fixtures into the `target/release` directory where it should be cached by the fellowship CI. + + Verifying that it works here: https://github.com/polkadot-fellows/runtimes/pull/891 + + Why: Re-running when the output dir changes will make it re-run every time. Since every run changes the output dir. +crates: +- name: pallet-revive-fixtures + bump: patch diff --git a/substrate/frame/revive/fixtures/build.rs b/substrate/frame/revive/fixtures/build.rs index f827ac4349943..126f2325dcdbe 100644 --- a/substrate/frame/revive/fixtures/build.rs +++ b/substrate/frame/revive/fixtures/build.rs @@ -385,66 +385,6 @@ fn write_output(build_dir: &Path, out_dir: &Path, entries: Vec) -> Result Ok(()) } -/// Create a directory in the `target` as output directory -fn create_out_dir() -> Result { - let temp_dir: PathBuf = - env::var("OUT_DIR").context("Failed to fetch `OUT_DIR` env variable")?.into(); - - // this is set in case the user has overridden the target directory - let out_dir = if let Ok(path) = env::var("CARGO_TARGET_DIR") { - let path = PathBuf::from(path); - - if path.is_absolute() { - path - } else { - let output = std::process::Command::new(env!("CARGO")) - .arg("locate-project") - .arg("--workspace") - .arg("--message-format=plain") - .output() - .context("Failed to determine workspace root")? - .stdout; - - let workspace_root = Path::new( - std::str::from_utf8(&output) - .context("Invalid output from `locate-project`")? - .trim(), - ) - .parent() - .expect("Workspace root path contains the `Cargo.toml`; qed"); - - PathBuf::from(workspace_root).join(path) - } - } else { - // otherwise just traverse up from the out dir - let mut out_dir: PathBuf = temp_dir.clone(); - loop { - if !out_dir.pop() { - bail!("Cannot find project root.") - } - if out_dir.join("Cargo.lock").exists() { - break; - } - } - out_dir.join("target") - } - .join("pallet-revive-fixtures"); - - // clean up some leftover symlink from previous versions of this script - let mut out_exists = out_dir.exists(); - if out_exists && !out_dir.is_dir() { - fs::remove_file(&out_dir).context("Failed to remove `OUT_DIR`.")?; - out_exists = false; - } - - if !out_exists { - fs::create_dir(&out_dir) - .context(format!("Failed to create output directory: {})", out_dir.display(),))?; - } - - Ok(out_dir) -} - /// Generate the fixture_location.rs file with macros and sol! definitions. fn generate_fixture_location(temp_dir: &Path, out_dir: &Path, entries: &[Entry]) -> Result<()> { let mut file = fs::File::create(temp_dir.join("fixture_location.rs")) @@ -500,16 +440,21 @@ fn generate_fixture_location(temp_dir: &Path, out_dir: &Path, entries: &[Entry]) } pub fn main() -> Result<()> { + // input pathes let fixtures_dir: PathBuf = env::var("CARGO_MANIFEST_DIR")?.into(); let contracts_dir = fixtures_dir.join("contracts"); - let out_dir = create_out_dir().context("Cannot determine output directory")?; - let build_dir = out_dir.join("build"); - fs::create_dir_all(&build_dir).context("Failed to create build directory")?; + + // output pathes + let out_dir: PathBuf = + env::var("OUT_DIR").context("Failed to fetch `OUT_DIR` env variable")?.into(); + let out_fixtures_dir = out_dir.join("fixtures"); + let out_build_dir = out_dir.join("build"); + fs::create_dir_all(&out_fixtures_dir).context("Failed to create output fixture directory")?; + fs::create_dir_all(&out_build_dir).context("Failed to create output build directory")?; println!("cargo::rerun-if-env-changed={OVERRIDE_RUSTUP_TOOLCHAIN_ENV_VAR}"); println!("cargo::rerun-if-env-changed={OVERRIDE_STRIP_ENV_VAR}"); println!("cargo::rerun-if-env-changed={OVERRIDE_OPTIMIZE_ENV_VAR}"); - println!("cargo::rerun-if-changed={}", out_dir.display()); // the fixtures have a dependency on the uapi crate println!("cargo::rerun-if-changed={}", fixtures_dir.display()); @@ -530,20 +475,17 @@ pub fn main() -> Result<()> { .filter(|e| matches!(e.contract_type, ContractType::Rust)) .collect(); if !rust_entries.is_empty() { - create_cargo_toml(&fixtures_dir, rust_entries.into_iter(), &build_dir)?; - invoke_build(&build_dir)?; - write_output(&build_dir, &out_dir, entries.clone())?; + create_cargo_toml(&fixtures_dir, rust_entries.into_iter(), &out_build_dir)?; + invoke_build(&out_build_dir)?; + write_output(&out_build_dir, &out_fixtures_dir, entries.clone())?; } // Compile Solidity contracts - compile_solidity_contracts(&contracts_dir, &out_dir, &entries)?; + compile_solidity_contracts(&contracts_dir, &out_fixtures_dir, &entries)?; } - let temp_dir: PathBuf = - env::var("OUT_DIR").context("Failed to fetch `OUT_DIR` env variable")?.into(); - // Generate fixture_location.rs with sol! macros - generate_fixture_location(&temp_dir, &out_dir, &entries)?; + generate_fixture_location(&out_dir, &out_fixtures_dir, &entries)?; Ok(()) }