Skip to content

Commit 9c8a032

Browse files
committed
feat: switch vscode to xtask
1 parent 4aba668 commit 9c8a032

File tree

10 files changed

+91
-909
lines changed

10 files changed

+91
-909
lines changed

.vscode/settings.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
},
1111
"rust-analyzer.rustc.source": "discover",
1212
"rust-analyzer.linkedProjects": [
13-
// "./crates/bevy_api_gen/Cargo.toml",
13+
"./crates/bevy_api_gen/Cargo.toml",
1414
"Cargo.toml",
1515
],
16-
"rust-analyzer.check.invocationStrategy": "per_workspace",
17-
"rust-analyzer.check.invocationLocation": "workspace",
16+
"rust-analyzer.check.invocationStrategy": "once",
1817
"rust-analyzer.check.overrideCommand": [
1918
"/home/makspll/git/bevy_mod_scripting/check.sh"
2019
],
@@ -28,8 +27,8 @@
2827
"rust-analyzer.runnables.extraArgs": [
2928
"--profile=release-with-debug",
3029
],
31-
"rust-analyzer.cargo.features": [
32-
"bevy_mod_scripting_functions/test_functions"
33-
]
30+
// "rust-analyzer.cargo.features": [
31+
// "bevy_mod_scripting_functions/test_functions"
32+
// ]
3433
// "rust-analyzer.semanticHighlighting.operator.enable": false
3534
}

check.sh

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
#!/bin/bash
2-
unset RUSTUP_TOOLCHAIN
3-
CURRENT_DIR=$(basename "$PWD")
4-
5-
6-
if [[ "$CURRENT_DIR" == "bevy_api_gen" ]]; then
7-
cargo +nightly-2024-11-05 clippy --all-targets --message-format=json
8-
else
9-
cargo xtask check --ide-mode
10-
# cargo clippy --workspace --all-targets --message-format=json --features="lua54 rhai rune bevy/file_watcher bevy/multi_threaded "
11-
fi
2+
cd "$(dirname "$0")"
3+
cargo xtask check --ide-mode

crates/bevy_mod_scripting_core/src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<P: IntoScriptPluginParams> Command for CreateOrUpdateScript<P> {
152152
// If None assign new context ID, otherwise assign the old one
153153
// If re-loading and different from the previous one, the old one will be removed
154154
let current_context_id = (assigner.assign)(script.as_deref(), &self.id, &self.content, &mut contexts);
155-
155+
156156
debug!("{}: New context assigned?: {:?}", P::LANGUAGE, current_context_id.is_none() || current_context_id != previous_context_id);
157157

158158
let current_context_id = if let Some(id) = current_context_id {

crates/languages/bevy_mod_scripting_lua/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub fn lua_handler(
174174
pre_handling_initializers: &[ContextPreHandlingInitializer<LuaScriptingPlugin>],
175175
_: &mut (),
176176
world: &mut bevy::ecs::world::World,
177-
) -> Result<(), bevy_mod_scripting_core::error::ScriptError> {
177+
) -> Result<ScriptValue, bevy_mod_scripting_core::error::ScriptError> {
178178
with_world(world, context, |context| {
179179
pre_handling_initializers
180180
.iter()
@@ -183,7 +183,7 @@ pub fn lua_handler(
183183
let handler: Function = match context.globals().raw_get(callback_label.as_ref()) {
184184
Ok(handler) => handler,
185185
// not subscribed to this event type
186-
Err(_) => return Ok(()),
186+
Err(_) => return Ok(ScriptValue::Unit),
187187
};
188188

189189
let input = MultiValue::from_vec(
@@ -192,17 +192,17 @@ pub fn lua_handler(
192192
.collect::<Result<_, _>>()?,
193193
);
194194

195-
handler.call::<()>(input)?;
196-
Ok(())
195+
let out = handler.call::<LuaScriptValue>(input)?;
196+
Ok(out.into())
197197
})
198198
}
199199

200200
/// Safely scopes world access for a lua context to the given closure's scope
201-
pub fn with_world<F: FnOnce(&mut Lua) -> Result<(), ScriptError>>(
201+
pub fn with_world<O, F: FnOnce(&mut Lua) -> Result<O, ScriptError>>(
202202
world: &mut World,
203203
context: &mut Lua,
204204
f: F,
205-
) -> Result<(), ScriptError> {
205+
) -> Result<O, ScriptError> {
206206
WorldCallbackAccess::with_callback_access(world, |guard| {
207207
context
208208
.globals()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

crates/languages/bevy_mod_scripting_rhai/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub fn rhai_callback_handler(
132132
pre_handling_initializers: &[ContextPreHandlingInitializer<RhaiScriptingPlugin>],
133133
runtime: &mut RhaiRuntime,
134134
world: &mut World,
135-
) -> Result<(), ScriptError> {
135+
) -> Result<ScriptValue, ScriptError> {
136136
with_world(world, context, |context| {
137137
pre_handling_initializers
138138
.iter()
@@ -144,27 +144,27 @@ pub fn rhai_callback_handler(
144144
.is_none()
145145
{
146146
// not subscribed to this handler
147-
return Ok(());
147+
return Ok(ScriptValue::Unit);
148148
};
149149

150150
// we want the call to be able to impact the scope
151151
let options = CallFnOptions::new().rewind_scope(false);
152-
runtime.call_fn_with_options(
152+
let out = runtime.call_fn_with_options::<ScriptValue>(
153153
options,
154154
&mut context.scope,
155155
&context.ast,
156156
callback.as_ref(),
157157
args,
158158
)?;
159-
Ok(())
159+
Ok(out)
160160
})
161161
}
162162

163-
pub fn with_world<F: FnOnce(&mut RhaiScriptContext) -> Result<(), ScriptError>>(
163+
pub fn with_world<O, F: FnOnce(&mut RhaiScriptContext) -> Result<O, ScriptError>>(
164164
world: &mut World,
165165
context: &mut RhaiScriptContext,
166166
f: F,
167-
) -> Result<(), ScriptError> {
167+
) -> Result<O, ScriptError> {
168168
WorldCallbackAccess::with_callback_access(world, |guard| {
169169
context.scope.push("world", guard.clone());
170170
f(context)

crates/languages/bevy_mod_scripting_rhai/tests/rhai_tests.rs

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
1-
use bevy::{
2-
app::App,
3-
asset::AssetPlugin,
4-
prelude::{Children, Entity, HierarchyPlugin, Parent, World},
5-
reflect::{Reflect, TypeRegistration},
6-
};
7-
use bevy_mod_scripting_core::{
8-
bindings::{
9-
access_map::ReflectAccessId, pretty_print::DisplayWithWorld, script_value::ScriptValue,
10-
ReflectReference, ScriptTypeRegistration, WorldAccessGuard,
11-
},
12-
context::ContextLoadingSettings,
13-
error::ScriptError,
14-
event::CallbackLabel,
15-
};
16-
use bevy_mod_scripting_functions::ScriptFunctionsPlugin;
17-
use bevy_mod_scripting_rhai::{RhaiScriptContext, RhaiScriptingPlugin};
1+
// use bevy::app::App;
2+
// use bevy_mod_scripting_functions::ScriptFunctionsPlugin;
3+
// use bevy_mod_scripting_rhai::RhaiScriptingPlugin;
184
use libtest_mimic::{Arguments, Failed, Trial};
19-
use rhai::Engine;
205
use std::{
216
fs::{self, DirEntry},
227
io, panic,
238
path::{Path, PathBuf},
24-
sync::Arc,
259
};
26-
use test_utils::test_data::{setup_integration_test, setup_world, EnumerateTestComponents};
10+
// use test_utils::test_data::setup_integration_test;
2711

28-
/// Initializes world for tests
29-
fn init_app() -> App {
30-
let mut app = setup_integration_test(|_, _| {});
12+
// Initializes world for tests
13+
// fn init_app() -> App {
14+
// let mut app = setup_integration_test(|_, _| {});
3115

32-
app.add_plugins(RhaiScriptingPlugin::default())
33-
.add_plugins(ScriptFunctionsPlugin);
16+
// app.add_plugins(RhaiScriptingPlugin::default())
17+
// .add_plugins(ScriptFunctionsPlugin);
3418

35-
app.finish();
36-
app.cleanup();
19+
// app.finish();
20+
// app.cleanup();
3721

38-
app
39-
}
22+
// app
23+
// }
4024

4125
struct Test {
4226
code: String,
@@ -45,10 +29,12 @@ struct Test {
4529

4630
impl Test {
4731
fn execute(self) -> Result<(), Failed> {
32+
println!("Running test: {}", self.name());
33+
println!("Code: {}", self.code);
4834
// let lua = Lua::new();
4935
// set file information
50-
let mut app = init_app();
51-
app.add_systems(schedule, systems)
36+
// let mut app = init_app();
37+
// app.add_systems(schedule, systems);
5238

5339
// let mut lua = lua_context_load(
5440
// &(self.name()).into(),

crates/test_utils/src/test_data.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::alloc::Layout;
2-
use std::sync::{Arc, RwLock};
32

43
use bevy::ecs::{component::*, world::World};
54
use bevy::prelude::*;

crates/xtask/src/main.rs

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ struct App {
175175
subcmd: Xtasks,
176176
}
177177

178+
#[derive(Debug, Clone, Default, strum::EnumString)]
179+
#[strum(serialize_all = "snake_case")]
180+
enum CheckKind {
181+
#[default]
182+
All,
183+
Main,
184+
Codegen,
185+
}
186+
178187
#[derive(Debug, clap::Subcommand)]
179188
#[clap(
180189
name = "xtask",
@@ -195,6 +204,15 @@ enum Xtasks {
195204
help = "Run in the expected format for rust-analyzer's override check command"
196205
)]
197206
ide_mode: bool,
207+
208+
#[clap(
209+
long,
210+
short,
211+
default_value = "all",
212+
value_parser=clap::value_parser!(CheckKind),
213+
help = "The kind of check to perform",
214+
)]
215+
kind: CheckKind,
198216
},
199217
/// Build the rust crates.io docs as well as any other docs
200218
Docs {
@@ -217,7 +235,7 @@ impl Xtasks {
217235
fn run(self, features: Features) -> Result<()> {
218236
match self {
219237
Xtasks::Build => Self::build(features),
220-
Xtasks::Check { ide_mode } => Self::check(features, ide_mode),
238+
Xtasks::Check { ide_mode, kind } => Self::check(features, ide_mode, kind),
221239
Xtasks::Docs { open, no_rust_docs } => Self::docs(open, no_rust_docs),
222240
Xtasks::Test => Self::test(features),
223241
Xtasks::CiCheck => Self::cicd(),
@@ -361,7 +379,7 @@ impl Xtasks {
361379

362380
fn check_main_workspace(features: Features, ide_mode: bool) -> Result<()> {
363381
// start with cargo clippy
364-
let mut clippy_args = Vec::default();
382+
let mut clippy_args = vec![];
365383
if ide_mode {
366384
clippy_args.push("--message-format=json");
367385
}
@@ -390,14 +408,42 @@ impl Xtasks {
390408
Ok(())
391409
}
392410

393-
fn check_codegen_crate(features: Features, ide_mode: bool) -> Result<()> {
411+
fn check_codegen_crate(_ide_mode: bool) -> Result<()> {
394412
// set the working directory to the codegen crate
395-
let codegen_dir = Self::relative_workspace_dir(Path::join("crates", "bevy_api_gen"))?;
413+
// let crates_path = Self::relative_workspace_dir(PathBuf::from("crates"))?;
414+
// let codegen_crate_path = crates_path.join("bevy_api_gen");
415+
416+
// let mut clippy_args = vec!["+nightly-2024-12-15", "clippy"];
417+
// if ide_mode {
418+
// clippy_args.push("--message-format=json");
419+
// }
420+
// clippy_args.extend(vec!["--all-targets", "--", "-D", "warnings"]);
421+
422+
// Self::run_system_command(
423+
// "cargo",
424+
// "Failed to run clippy on codegen crate",
425+
// clippy_args,
426+
// Some(&codegen_crate_path),
427+
// )?;
428+
429+
// TODO: for now do nothing, it's difficult to get rust analyzer to accept the nightly version
430+
396431
Ok(())
397432
}
398433

399-
fn check(features: Features, ide_mode: bool) -> Result<()> {
400-
check_main_workspace(features, ide_mode)?;
434+
fn check(features: Features, ide_mode: bool, kind: CheckKind) -> Result<()> {
435+
match kind {
436+
CheckKind::All => {
437+
Self::check_main_workspace(features.clone(), ide_mode)?;
438+
Self::check_codegen_crate(ide_mode)?;
439+
}
440+
CheckKind::Main => {
441+
Self::check_main_workspace(features, ide_mode)?;
442+
}
443+
CheckKind::Codegen => {
444+
Self::check_codegen_crate(ide_mode)?;
445+
}
446+
}
401447
Ok(())
402448
}
403449

@@ -591,7 +637,7 @@ impl Xtasks {
591637

592638
// run lints
593639
let all_features = Features::all_features();
594-
Self::check(all_features.clone(), false)?;
640+
Self::check(all_features.clone(), false, CheckKind::Main)?;
595641

596642
// run docs
597643
Self::docs(false, false)?;

0 commit comments

Comments
 (0)