Skip to content

Commit 7148639

Browse files
authored
move ci testing to dev_tools (#12371)
# Objective - Fix #12356 - better isolation of ci testing tools in dev tools instead of being in various crates ## Solution - Move the parts doing the work of ci testing to the dev tools
1 parent 0baedcf commit 7148639

File tree

7 files changed

+41
-55
lines changed

7 files changed

+41
-55
lines changed

crates/bevy_dev_tools/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ bevy_ci_testing = ["serde", "ron"]
1616
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
1717
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
1818
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
19+
bevy_render = { path = "../bevy_render", version = "0.14.0-dev" }
20+
bevy_time = { path = "../bevy_time", version = "0.14.0-dev" }
21+
bevy_window = { path = "../bevy_window", version = "0.14.0-dev" }
1922

2023
# other
2124
serde = { version = "1.0", features = ["derive"], optional = true }

crates/bevy_dev_tools/src/ci_testing.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
//! Utilities for testing in CI environments.
22
33
use bevy_app::{App, AppExit, Update};
4+
use bevy_ecs::{
5+
entity::Entity,
6+
prelude::Resource,
7+
query::With,
8+
system::{Local, Query, Res, ResMut},
9+
};
10+
use bevy_render::view::screenshot::ScreenshotManager;
11+
use bevy_time::TimeUpdateStrategy;
12+
use bevy_utils::{tracing::info, Duration};
13+
use bevy_window::PrimaryWindow;
414
use serde::Deserialize;
515

6-
use bevy_ecs::prelude::Resource;
7-
use bevy_utils::tracing::info;
8-
916
/// A configuration struct for automated CI testing.
1017
///
1118
/// 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 {
5360
ron::from_str(config).expect("error deserializing CI testing configuration file")
5461
};
5562

63+
if let Some(frame_time) = config.frame_time {
64+
app.world
65+
.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_secs_f32(
66+
frame_time,
67+
)));
68+
}
69+
5670
app.insert_resource(config)
57-
.add_systems(Update, ci_testing_exit_after);
71+
.add_systems(Update, (ci_testing_exit_after, ci_testing_screenshot_at));
5872

5973
app
6074
}
75+
76+
fn ci_testing_screenshot_at(
77+
mut current_frame: Local<u32>,
78+
ci_testing_config: Res<CiTestingConfig>,
79+
mut screenshot_manager: ResMut<ScreenshotManager>,
80+
main_window: Query<Entity, With<PrimaryWindow>>,
81+
) {
82+
if ci_testing_config
83+
.screenshot_frames
84+
.contains(&*current_frame)
85+
{
86+
info!("Taking a screenshot at frame {}.", *current_frame);
87+
let path = format!("./screenshot-{}.png", *current_frame);
88+
screenshot_manager
89+
.save_screenshot_to_disk(main_window.single(), path)
90+
.unwrap();
91+
}
92+
*current_frame += 1;
93+
}

crates/bevy_internal/Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,7 @@ webgpu = [
113113
]
114114

115115
# enable systems that allow for automated testing on CI
116-
bevy_ci_testing = [
117-
"bevy_dev_tools/bevy_ci_testing",
118-
"bevy_time/bevy_ci_testing",
119-
"bevy_render?/bevy_ci_testing",
120-
"bevy_render?/ci_limits",
121-
]
116+
bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing", "bevy_render?/ci_limits"]
122117

123118
# Enable animation support, and glTF animation loading
124119
animation = ["bevy_animation", "bevy_gltf?/bevy_animation"]

crates/bevy_render/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ webp = ["image/webp"]
1919
dds = ["ddsfile"]
2020
pnm = ["image/pnm"]
2121
multi-threaded = ["bevy_tasks/multi-threaded"]
22-
bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing"]
2322

2423
shader_format_glsl = ["naga/glsl-in", "naga/wgsl-out", "naga_oil/glsl"]
2524
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" }
5756
bevy_window = { path = "../bevy_window", version = "0.14.0-dev" }
5857
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
5958
bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" }
60-
bevy_dev_tools = { path = "../bevy_dev_tools", version = "0.14.0-dev", optional = true }
6159

6260
# rendering
6361
image = { version = "0.24", default-features = false }

crates/bevy_render/src/view/window/screenshot.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -140,35 +140,7 @@ impl Plugin for ScreenshotPlugin {
140140
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
141141
render_app.init_resource::<SpecializedRenderPipelines<ScreenshotToScreenPipeline>>();
142142
}
143-
144-
#[cfg(feature = "bevy_ci_testing")]
145-
if app
146-
.world
147-
.contains_resource::<bevy_dev_tools::ci_testing::CiTestingConfig>()
148-
{
149-
app.add_systems(bevy_app::Update, ci_testing_screenshot_at);
150-
}
151-
}
152-
}
153-
154-
#[cfg(feature = "bevy_ci_testing")]
155-
fn ci_testing_screenshot_at(
156-
mut current_frame: Local<u32>,
157-
ci_testing_config: Res<bevy_dev_tools::ci_testing::CiTestingConfig>,
158-
mut screenshot_manager: ResMut<ScreenshotManager>,
159-
main_window: Query<Entity, With<bevy_window::PrimaryWindow>>,
160-
) {
161-
if ci_testing_config
162-
.screenshot_frames
163-
.contains(&*current_frame)
164-
{
165-
info!("Taking a screenshot at frame {}.", *current_frame);
166-
let path = format!("./screenshot-{}.png", *current_frame);
167-
screenshot_manager
168-
.save_screenshot_to_disk(main_window.single(), path)
169-
.unwrap();
170143
}
171-
*current_frame += 1;
172144
}
173145

174146
pub(crate) fn align_byte_size(value: u32) -> u32 {

crates/bevy_time/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ keywords = ["bevy"]
1111
[features]
1212
default = []
1313
serialize = ["serde"]
14-
bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing"]
1514

1615
[dependencies]
1716
# bevy
@@ -23,7 +22,6 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
2322
"bevy",
2423
] }
2524
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
26-
bevy_dev_tools = { path = "../bevy_dev_tools", version = "0.14.0-dev", optional = true }
2725

2826
# other
2927
crossbeam-channel = "0.5.0"

crates/bevy_time/src/lib.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,6 @@ impl Plugin for TimePlugin {
6464
bevy_ecs::event::reset_event_update_signal_system.after(EventUpdates),
6565
)
6666
.add_systems(FixedPostUpdate, signal_event_update_system);
67-
68-
#[cfg(feature = "bevy_ci_testing")]
69-
if let Some(ci_testing_config) = app
70-
.world
71-
.get_resource::<bevy_dev_tools::ci_testing::CiTestingConfig>()
72-
{
73-
if let Some(frame_time) = ci_testing_config.frame_time {
74-
app.world
75-
.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_secs_f32(
76-
frame_time,
77-
)));
78-
}
79-
}
8067
}
8168
}
8269

0 commit comments

Comments
 (0)