From bc8fe689acd3e80ccfc89e60a74bf6a341f8937e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Thu, 7 Mar 2024 22:58:02 +0100 Subject: [PATCH 1/2] move ci testing to dev_tools --- Cargo.toml | 1 + crates/bevy_dev_tools/Cargo.toml | 3 ++ crates/bevy_dev_tools/src/ci_testing.rs | 41 +++++++++++++++++-- crates/bevy_internal/Cargo.toml | 7 +--- crates/bevy_render/Cargo.toml | 2 - .../bevy_render/src/view/window/screenshot.rs | 28 ------------- crates/bevy_time/Cargo.toml | 2 - crates/bevy_time/src/lib.rs | 13 ------ 8 files changed, 42 insertions(+), 55 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dd9a56d466772..06842c8d4565d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,6 +79,7 @@ default = [ "webgl2", "sysinfo_plugin", "bevy_debug_stepping", + "bevy_ci_testing", ] # Force dynamic linking, which improves iterative compile times diff --git a/crates/bevy_dev_tools/Cargo.toml b/crates/bevy_dev_tools/Cargo.toml index eb6597d8bd7ff..18f66b4e5a3aa 100644 --- a/crates/bevy_dev_tools/Cargo.toml +++ b/crates/bevy_dev_tools/Cargo.toml @@ -16,6 +16,9 @@ bevy_ci_testing = ["serde", "ron"] bevy_app = { path = "../bevy_app", version = "0.14.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" } +bevy_render = { path = "../bevy_render", version = "0.14.0-dev" } +bevy_time = { path = "../bevy_time", version = "0.14.0-dev" } +bevy_window = { path = "../bevy_window", version = "0.14.0-dev" } # other serde = { version = "1.0", features = ["derive"], optional = true } diff --git a/crates/bevy_dev_tools/src/ci_testing.rs b/crates/bevy_dev_tools/src/ci_testing.rs index db2d4a14fc70e..3f11a841c9372 100644 --- a/crates/bevy_dev_tools/src/ci_testing.rs +++ b/crates/bevy_dev_tools/src/ci_testing.rs @@ -1,11 +1,18 @@ //! Utilities for testing in CI environments. use bevy_app::{App, AppExit, Update}; +use bevy_ecs::{ + entity::Entity, + prelude::Resource, + query::With, + system::{Local, Query, Res, ResMut}, +}; +use bevy_render::view::screenshot::ScreenshotManager; +use bevy_time::TimeUpdateStrategy; +use bevy_utils::{tracing::info, Duration}; +use bevy_window::PrimaryWindow; use serde::Deserialize; -use bevy_ecs::prelude::Resource; -use bevy_utils::tracing::info; - /// A configuration struct for automated CI testing. /// /// It gets used when the `bevy_ci_testing` feature is enabled to automatically @@ -53,8 +60,34 @@ pub(crate) fn setup_app(app: &mut App) -> &mut App { ron::from_str(config).expect("error deserializing CI testing configuration file") }; + if let Some(frame_time) = config.frame_time { + app.world + .insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_secs_f32( + frame_time, + ))); + } + app.insert_resource(config) - .add_systems(Update, ci_testing_exit_after); + .add_systems(Update, (ci_testing_exit_after, ci_testing_screenshot_at)); app } + +fn ci_testing_screenshot_at( + mut current_frame: Local, + ci_testing_config: Res, + mut screenshot_manager: ResMut, + main_window: Query>, +) { + if ci_testing_config + .screenshot_frames + .contains(&*current_frame) + { + info!("Taking a screenshot at frame {}.", *current_frame); + let path = format!("./screenshot-{}.png", *current_frame); + screenshot_manager + .save_screenshot_to_disk(main_window.single(), path) + .unwrap(); + } + *current_frame += 1; +} diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 0ea6362ee3fd5..68cb7421d3106 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -113,12 +113,7 @@ webgpu = [ ] # enable systems that allow for automated testing on CI -bevy_ci_testing = [ - "bevy_dev_tools/bevy_ci_testing", - "bevy_time/bevy_ci_testing", - "bevy_render?/bevy_ci_testing", - "bevy_render?/ci_limits", -] +bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing", "bevy_render?/ci_limits"] # Enable animation support, and glTF animation loading animation = ["bevy_animation", "bevy_gltf?/bevy_animation"] diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 7e9012d99df3e..cff32d86c2b94 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -19,7 +19,6 @@ webp = ["image/webp"] dds = ["ddsfile"] pnm = ["image/pnm"] multi-threaded = ["bevy_tasks/multi-threaded"] -bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing"] shader_format_glsl = ["naga/glsl-in", "naga/wgsl-out", "naga_oil/glsl"] shader_format_spirv = ["wgpu/spirv", "naga/spv-in", "naga/spv-out"] @@ -57,7 +56,6 @@ bevy_transform = { path = "../bevy_transform", version = "0.14.0-dev" } bevy_window = { path = "../bevy_window", version = "0.14.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" } bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" } -bevy_dev_tools = { path = "../bevy_dev_tools", version = "0.14.0-dev", optional = true } # rendering image = { version = "0.24", default-features = false } diff --git a/crates/bevy_render/src/view/window/screenshot.rs b/crates/bevy_render/src/view/window/screenshot.rs index b51c4f479770a..64eb3d70169bf 100644 --- a/crates/bevy_render/src/view/window/screenshot.rs +++ b/crates/bevy_render/src/view/window/screenshot.rs @@ -140,35 +140,7 @@ impl Plugin for ScreenshotPlugin { if let Ok(render_app) = app.get_sub_app_mut(RenderApp) { render_app.init_resource::>(); } - - #[cfg(feature = "bevy_ci_testing")] - if app - .world - .contains_resource::() - { - app.add_systems(bevy_app::Update, ci_testing_screenshot_at); - } - } -} - -#[cfg(feature = "bevy_ci_testing")] -fn ci_testing_screenshot_at( - mut current_frame: Local, - ci_testing_config: Res, - mut screenshot_manager: ResMut, - main_window: Query>, -) { - if ci_testing_config - .screenshot_frames - .contains(&*current_frame) - { - info!("Taking a screenshot at frame {}.", *current_frame); - let path = format!("./screenshot-{}.png", *current_frame); - screenshot_manager - .save_screenshot_to_disk(main_window.single(), path) - .unwrap(); } - *current_frame += 1; } pub(crate) fn align_byte_size(value: u32) -> u32 { diff --git a/crates/bevy_time/Cargo.toml b/crates/bevy_time/Cargo.toml index 5b586ebab3d03..c031f6cdea50e 100644 --- a/crates/bevy_time/Cargo.toml +++ b/crates/bevy_time/Cargo.toml @@ -11,7 +11,6 @@ keywords = ["bevy"] [features] default = [] serialize = ["serde"] -bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing"] [dependencies] # bevy @@ -23,7 +22,6 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [ "bevy", ] } bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" } -bevy_dev_tools = { path = "../bevy_dev_tools", version = "0.14.0-dev", optional = true } # other crossbeam-channel = "0.5.0" diff --git a/crates/bevy_time/src/lib.rs b/crates/bevy_time/src/lib.rs index c94e6f46db0ba..39d7cf4e4e6b7 100644 --- a/crates/bevy_time/src/lib.rs +++ b/crates/bevy_time/src/lib.rs @@ -64,19 +64,6 @@ impl Plugin for TimePlugin { bevy_ecs::event::reset_event_update_signal_system.after(EventUpdates), ) .add_systems(FixedPostUpdate, signal_event_update_system); - - #[cfg(feature = "bevy_ci_testing")] - if let Some(ci_testing_config) = app - .world - .get_resource::() - { - if let Some(frame_time) = ci_testing_config.frame_time { - app.world - .insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_secs_f32( - frame_time, - ))); - } - } } } From f29ab5bb8555d9443209eb53c6d70fbb89960d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Thu, 7 Mar 2024 23:04:27 +0100 Subject: [PATCH 2/2] not really a default feature --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 06842c8d4565d..dd9a56d466772 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,7 +79,6 @@ default = [ "webgl2", "sysinfo_plugin", "bevy_debug_stepping", - "bevy_ci_testing", ] # Force dynamic linking, which improves iterative compile times