Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow more configuration for showcase from the CLI #13217

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 34 additions & 22 deletions tools/example-showcase/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ enum Action {
/// WGPU backend to use
wgpu_backend: Option<String>,

#[arg(long)]
/// Don't stop automatically
manual_stop: bool,
#[arg(long, default_value = "250")]
/// Which frame to automatically stop the example at.
///
/// This defaults to frame 250. Set it to 0 to not stop the example automatically.
stop_frame: u32,

#[arg(long)]
/// Take a screenshot
screenshot: bool,
/// Which frame to take a screenshot at. Set to 0 for no screenshot.
screenshot_frame: u32,

#[arg(long, default_value = "0.05")]
/// Fixed duration of a frame, in seconds. Only used when taking a screenshot, default to 0.05
fixed_frame_time: f32,

#[arg(long)]
/// Running in CI (some adaptation to the code)
Expand Down Expand Up @@ -138,8 +144,9 @@ fn main() {
match cli.action {
Action::Run {
wgpu_backend,
manual_stop,
screenshot,
stop_frame,
screenshot_frame,
fixed_frame_time,
in_ci,
ignore_stress_tests,
report_details,
Expand Down Expand Up @@ -171,29 +178,34 @@ fn main() {

let mut extra_parameters = vec![];

match (manual_stop, screenshot) {
(true, true) => {
match (stop_frame, screenshot_frame) {
// When the example does not automatically stop nor take a screenshot.
(0, 0) => (),
mockersf marked this conversation as resolved.
Show resolved Hide resolved
// When the example does not automatically stop.
(0, _) => {
mockersf marked this conversation as resolved.
Show resolved Hide resolved
let mut file = File::create("example_showcase_config.ron").unwrap();
file.write_all(
b"(setup: (fixed_frame_time: Some(0.05)), events: [(100, Screenshot)])",
format!("(setup: (fixed_frame_time: Some({fixed_frame_time})), events: [({screenshot_frame}, Screenshot)])").as_bytes(),
mockersf marked this conversation as resolved.
Show resolved Hide resolved
)
.unwrap();
extra_parameters.push("--features");
extra_parameters.push("bevy_ci_testing");
}
(true, false) => (),
(false, true) => {
// When the example does not take a screenshot.
(_, 0) => {
mockersf marked this conversation as resolved.
Show resolved Hide resolved
let mut file = File::create("example_showcase_config.ron").unwrap();
file.write_all(
b"(setup: (fixed_frame_time: Some(0.05)), events: [(100, Screenshot), (250, AppExit)])",
)
.unwrap();
file.write_all(format!("(events: [({stop_frame}, AppExit)])").as_bytes())
.unwrap();
extra_parameters.push("--features");
extra_parameters.push("bevy_ci_testing");
}
(false, false) => {
// When the example both automatically stops and takes a screenshot.
(_, _) => {
mockersf marked this conversation as resolved.
Show resolved Hide resolved
let mut file = File::create("example_showcase_config.ron").unwrap();
file.write_all(b"(events: [(250, AppExit)])").unwrap();
file.write_all(
format!("(setup: (fixed_frame_time: Some({fixed_frame_time})), events: [({screenshot_frame}, Screenshot), ({stop_frame}, AppExit)])").as_bytes(),
)
.unwrap();
extra_parameters.push("--features");
extra_parameters.push("bevy_ci_testing");
}
Expand Down Expand Up @@ -314,7 +326,7 @@ fn main() {
cmd = cmd.env("WGPU_BACKEND", backend);
}

if !manual_stop || screenshot {
if stop_frame > 0 || screenshot_frame > 0 {
cmd = cmd.env("CI_TESTING_CONFIG", "example_showcase_config.ron");
}

Expand All @@ -329,10 +341,10 @@ fn main() {
if (!report_details && result.is_ok())
|| (report_details && result.as_ref().unwrap().status.success())
{
if screenshot {
if screenshot_frame > 0 {
let _ = fs::create_dir_all(Path::new("screenshots").join(&to_run.category));
let renamed_screenshot = fs::rename(
"screenshot-100.png",
format!("screenshot-{screenshot_frame}.png"),
Path::new("screenshots")
.join(&to_run.category)
.join(format!("{}.png", to_run.technical_name)),
Expand Down Expand Up @@ -404,7 +416,7 @@ fn main() {
.collect::<Vec<_>>()
.join("\n"),
);
if screenshot {
if screenshot_frame > 0 {
let _ = fs::write(
format!("{reports_path}/no_screenshots"),
no_screenshot_examples
Expand Down