Skip to content

Commit

Permalink
Fix CI build
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysxia committed Jan 14, 2025
1 parent 7ffc4f3 commit e290461
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
33 changes: 25 additions & 8 deletions cargo-creusot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use creusot_args::{options::*, CREUSOT_RUSTC_ARGS};
use creusot_setup as setup;
use std::{
env,
path::PathBuf,
process::{exit, Command},
};
use tempdir::TempDir;
Expand All @@ -20,11 +21,20 @@ fn main() -> Result<()> {
let cargs = CargoCreusotArgs::parse_from(std::env::args().skip(1));

match cargs.subcommand {
None => creusot(None, cargs.options, cargs.cargo_flags),
Some(Creusot(subcmd)) => creusot(Some(subcmd), cargs.options, cargs.cargo_flags),
None => creusot(None, cargs.options, cargs.creusot_rustc, cargs.cargo_flags),
Some(Creusot(subcmd)) => {
creusot(Some(subcmd), cargs.options, cargs.creusot_rustc, cargs.cargo_flags)
}
Some(Setup { command: SetupSubCommand::Status }) => setup::status(),
Some(Setup {
command: SetupSubCommand::Install { provers_parallelism, external, no_check_version, only_creusot_rustc, skip_creusot_rustc },
command:
SetupSubCommand::Install {
provers_parallelism,
external,
no_check_version,
only_creusot_rustc,
skip_creusot_rustc,
},
}) => {
let extflag =
|name| setup::ExternalFlag { check_version: !no_check_version.contains(&name) };
Expand Down Expand Up @@ -55,6 +65,7 @@ fn main() -> Result<()> {
fn creusot(
subcmd: Option<CreusotSubCommand>,
options: CommonOptions,
creusot_rustc: Option<PathBuf>,
cargo_flags: Vec<String>,
) -> Result<()> {
let (coma_src, coma_glob) = get_coma(&options);
Expand Down Expand Up @@ -85,7 +96,7 @@ fn creusot(
subcommand: creusot_rustc_subcmd.clone(),
};

invoke_cargo(&creusot_args, cargo_flags);
invoke_cargo(&creusot_args, creusot_rustc, cargo_flags);

if let Some((mode, coma_src, args)) = launch_why3 {
let mut coma_files = vec![coma_src];
Expand Down Expand Up @@ -115,7 +126,7 @@ fn creusot(
Ok(())
}

fn invoke_cargo(args: &CreusotArgs, cargo_flags: Vec<String>) {
fn invoke_cargo(args: &CreusotArgs, creusot_rustc: Option<PathBuf>, cargo_flags: Vec<String>) {
let cargo_path = env::var("CARGO_PATH").unwrap_or_else(|_| "cargo".to_string());
let cargo_cmd = match &args.subcommand {
Some(CreusotSubCommand::Doc { .. }) => "doc",
Expand All @@ -128,9 +139,12 @@ fn invoke_cargo(args: &CreusotArgs, cargo_flags: Vec<String>) {
}
};
let toolchain = setup::toolchain_channel();
let creusot_rustc_path = setup::toolchain_dir(&setup::get_data_dir().unwrap(), &toolchain)
.join("bin")
.join("creusot-rustc");
let creusot_rustc_path = match creusot_rustc {
Some(path) => path,
None => setup::toolchain_dir(&setup::get_data_dir().unwrap(), &toolchain)
.join("bin")
.join("creusot-rustc"),
};
// creusot_rustc binary exists
if !creusot_rustc_path.exists() {
eprintln!("creusot-rustc not found (expected at {creusot_rustc_path:?})");
Expand Down Expand Up @@ -183,6 +197,9 @@ fn invoke_cargo(args: &CreusotArgs, cargo_flags: Vec<String>) {
pub struct CargoCreusotArgs {
#[clap(flatten)]
pub options: CommonOptions,
/// Path to creusot-rustc (for testing)
#[clap(long, value_name = "PATH")]
pub creusot_rustc: Option<PathBuf>,
/// Subcommand: why3, setup
#[command(subcommand)]
pub subcommand: Option<CargoCreusotSubCommand>,
Expand Down
4 changes: 3 additions & 1 deletion creusot/tests/creusot-contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() {
args.force_color = true;
}
// Build creusot-rustc to make it available to cargo-creusot
let _ = escargot::CargoBuild::new()
let creusot_rustc = escargot::CargoBuild::new()
.bin("creusot-rustc")
.current_release()
.manifest_path("../creusot-rustc/Cargo.toml")
Expand All @@ -52,6 +52,8 @@ fn main() {
.unwrap();
cargo_creusot.current_dir(&base_path).args([
"creusot",
"--creusot-rustc",
creusot_rustc.path().to_str().unwrap(),
"--stdout",
"--export-metadata=false",
"--span-mode=relative",
Expand Down
2 changes: 2 additions & 0 deletions creusot/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ fn main() {
let mut metadata_file = cargo_creusot;
metadata_file.current_dir(base_path);
metadata_file.arg("creusot").args(&[
"--creusot-rustc".as_ref(),
creusot_rustc.path().as_os_str(),
"--metadata-path".as_ref(),
temp_file.as_os_str(),
"--output-file=/dev/null".as_ref(),
Expand Down

0 comments on commit e290461

Please sign in to comment.