Skip to content

Commit

Permalink
First working version for --no-test-if-emulate
Browse files Browse the repository at this point in the history
  • Loading branch information
hadim committed Nov 13, 2024
1 parent 31a1e44 commit 6e4c788
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,44 @@ pub async fn run_build(
directories.clean().into_diagnostic()?;
}

if tool_configuration.no_test {
tracing::info!("Skipping tests");
// Are we cross compiling?
// NOTE: cannot use output.build_configuration.cross_compilation() here because it uses target_platform instead of host_platform and it enables cross-compilation when noarch.
let is_cross_compiling = output.build_configuration.host_platform.platform
!= output.build_configuration.build_platform.platform;

println!(
"target_platform={}",
output.build_configuration.target_platform
);
println!(
"build_platform={}",
output.build_configuration.build_platform.platform
);
println!(
"host_platform={}",
output.build_configuration.host_platform.platform
);
println!(
"cross_compilation()={}",
output.build_configuration.cross_compilation()
);

println!("is_cross_compiling={}", is_cross_compiling);

// Decide whether the tests should be skipped or not
let (skip_test, skip_test_reason) = if tool_configuration.no_test {
(true, "the --no-test flag was set")
} else if tool_configuration.no_test_if_emulate {
(
is_cross_compiling,
"the --no-test-if-emulate flag was set and cross-compiling",
)
} else {
(false, "")
};

if skip_test {
tracing::info!("Skipping tests because {}", skip_test_reason);
} else {
package_test::run_test(
&result,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub fn get_tool_config(
.with_compression_threads(args.compression_threads)
.with_reqwest_client(client)
.with_testing(!args.no_test)
.with_testing_if_emulate(!args.no_test_if_emulate)
.with_zstd_repodata_enabled(args.common.use_zstd)
.with_bz2_repodata_enabled(args.common.use_zstd)
.with_skip_existing(args.skip_existing)
Expand Down
5 changes: 5 additions & 0 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ pub struct BuildOpts {
#[arg(long, default_value = "false", help_heading = "Modifying result")]
pub no_test: bool,

/// Don't run the tests after building the package if the building platform
/// is different than the host platform (cross-compilation)
#[arg(long, default_value = "false", help_heading = "Modifying result")]
pub no_test_if_emulate: bool,

/// Don't force colors in the output of the build script
#[arg(long, default_value = "true", help_heading = "Modifying result")]
pub color_build_log: bool,
Expand Down
14 changes: 14 additions & 0 deletions src/tool_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ pub struct Configuration {
/// Whether to skip the test phase
pub no_test: bool,

/// Whether to skip the test phase if cross-compiling
pub no_test_if_emulate: bool,

/// Whether to use zstd
pub use_zstd: bool,

Expand Down Expand Up @@ -112,6 +115,7 @@ pub struct ConfigurationBuilder {
client: Option<ClientWithMiddleware>,
no_clean: bool,
no_test: bool,
no_test_if_emulate: bool,
use_zstd: bool,
use_bz2: bool,
skip_existing: SkipExisting,
Expand All @@ -135,6 +139,7 @@ impl ConfigurationBuilder {
client: None,
no_clean: false,
no_test: false,
no_test_if_emulate: false,
use_zstd: true,
use_bz2: false,
skip_existing: SkipExisting::None,
Expand Down Expand Up @@ -216,6 +221,14 @@ impl ConfigurationBuilder {
}
}

/// Sets whether tests should be executed if cross-compiling.
pub fn with_testing_if_emulate(self, testing_enabled_if_emulate: bool) -> Self {
Self {
no_test_if_emulate: !testing_enabled_if_emulate,
..self
}
}

/// Whether downloading repodata as `.zst` files is enabled.
pub fn with_zstd_repodata_enabled(self, zstd_repodata_enabled: bool) -> Self {
Self {
Expand Down Expand Up @@ -266,6 +279,7 @@ impl ConfigurationBuilder {
client,
no_clean: self.no_clean,
no_test: self.no_test,
no_test_if_emulate: self.no_test_if_emulate,
use_zstd: self.use_zstd,
use_bz2: self.use_bz2,
skip_existing: self.skip_existing,
Expand Down

0 comments on commit 6e4c788

Please sign in to comment.