no-bug: A few quality-of-life tweaks, take 2#13637
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to make npm run import more cross-platform (notably on Windows) by avoiding direct cargo invocation from package.json, and by making path inputs configurable for the supporting import scripts/tools.
Changes:
- Updated
npm run ffprefsto invoke Cargo via a small Python wrapper that honors theCARGOenvironment variable. - Updated
ffprefsto accept explicitprefsandenginepaths (instead of relying on a shared root +chdir). - Added optional CLI overrides for dump folder paths in
update_service_dumps.py.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tools/ffprefs/src/main.rs | Switches ffprefs from chdir-based root handling to explicit prefs/engine path arguments. |
| scripts/update_service_dumps.py | Adds optional argv-based overrides for dumps folder locations. |
| scripts/run_cargo.py | Introduces a Python wrapper to execute Cargo, honoring $CARGO when set. |
| package.json | Uses run_cargo.py for ffprefs and passes prefs/engine args using the new convention. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fn main() { | ||
| let args: Vec<String> = env::args().collect(); | ||
| let root_path = if args.len() > 1 { | ||
| let prefs_path = if args.len() > 1 { | ||
| PathBuf::from(&args[1]) | ||
| } else { | ||
| env::current_dir().expect("Failed to get current directory") | ||
| PathBuf::from("prefs") | ||
| }; | ||
| let engine_path = if args.len() > 2 { | ||
| PathBuf::from(&args[2]) | ||
| } else { | ||
| PathBuf::from("engine") | ||
| }; | ||
| env::set_current_dir(&root_path).expect("Failed to change directory"); | ||
|
|
||
| prepare_zen_prefs(); | ||
| let mut preferences = load_preferences(); | ||
| prepare_zen_prefs(&engine_path); | ||
| let mut preferences = load_preferences(&prefs_path); | ||
| expand_pref_values(&mut preferences); | ||
| write_preferences(&preferences); | ||
| write_preferences(&engine_path, &preferences); |
There was a problem hiding this comment.
Zen build tooling already works with $CWD/.surfer/.
| except Exception: | ||
| print('Exec failed', file=sys.stderr) |
There was a problem hiding this comment.
I've pushed an update that makes the error message more informative.
| if len(sys.argv) == 3: | ||
| _, DUMPS_FOLDER, ENGINE_DUMPS_FOLDER = sys.argv | ||
| main() |
There was a problem hiding this comment.
update_service_dumps.py is not a general-purpose utility that needs extensive input validation and usage information. My goal here was a minimal change that allows the locations to be specified externally.
package.json: Invoke cargo(1) through a Python script that honors the CARGO environment variable if set, and pass arguments to ffprefs using the new convention (see below) run_cargo.py: Script to invoke cargo(1), as a workaround for reading an environment variable in a package.json script in a cross-platform manner update_service_dumps.py: Allow specifying DUMPS_FOLDER and ENGINE_DUMPS_FOLDER on the command line ffprefs/src/main.rs: Allow specifying the prefs and engine dirs on the command line instead of hard-coding their locations relative to a common root dir
This should support
npm run importon Windows. I looked into run-script-os, and a couple other approaches, but then figured it would be simpler to just call a small Python script that looks up the environment variable and callscargo/$CARGOas appropriate.Please give this a try, and let me know if you see any regressions.
package.json: Invokecargo(1)through a Python script that honors theCARGOenvironment variable if set, and pass arguments toffprefsusing the new convention (see below)run_cargo.py: Script to invokecargo(1), as a workaround for reading an environment variable in apackage.jsonscript in a cross-platform mannerupdate_service_dumps.py: Allow specifyingDUMPS_FOLDERandENGINE_DUMPS_FOLDERon the command lineffprefs/src/main.rs: Allow specifying theprefsandenginedirs on the command line instead of hard-coding their locations relative to a common root dir