Skip to content

Commit 11d014f

Browse files
committed
no-bug: A few quality-of-life tweaks
linux/mozconfig: Honor the existing CC and CXX environment variables if set 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: Specify the prefs and engine dirs on the command line instead of hard-coding their locations relative to a common root
1 parent b1be664 commit 11d014f

5 files changed

Lines changed: 45 additions & 34 deletions

File tree

configs/linux/mozconfig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5-
# Setting the compiler based on the existence of clang bin directory
6-
if test -d "$HOME/.mozbuild/clang/bin"; then
5+
# Setting the compiler based on the environment or existence of the clang
6+
# bin directory
7+
if test "$CC" && test "$CXX"; then
8+
true
9+
elif test -d "$HOME/.mozbuild/clang/bin"; then
710
export CC="$HOME/.mozbuild/clang/bin/clang"
811
export CXX="$HOME/.mozbuild/clang/bin/clang++"
912
else

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test": "python3 scripts/run_tests.py",
3030
"test:dbg": "python3 scripts/run_tests.py --jsdebugger --debug-on-failure",
3131
"test:gtest": "cd engine && ./mach gtest Zen*",
32-
"ffprefs": "cd tools/ffprefs && cargo run --bin ffprefs -- ../../",
32+
"ffprefs": "python3 scripts/run_cargo.py run --manifest-path tools/ffprefs/Cargo.toml --bin ffprefs -- prefs engine",
3333
"lc": "surfer license-check",
3434
"lc:fix": "surfer license-check --fix",
3535
"use-moz-src": "cd engine && ./mach use-moz-src",

scripts/run_cargo.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
import os
6+
import sys
7+
8+
cargo = os.environ.get('CARGO', 'cargo')
9+
10+
command = [cargo] + sys.argv[1:]
11+
12+
try:
13+
os.execvp(command[0], command)
14+
except OSError as e:
15+
print(f"{sys.argv[0]}: '{command[0]}': {e}", file=sys.stderr)
16+
if 'CARGO' in os.environ:
17+
print('(CARGO environment variable is set)', file=sys.stderr)
18+
sys.exit(1)

scripts/update_service_dumps.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

55
import os
6+
import sys
67
import json
78
from json_with_comments import JSONWithCommentsDecoder
89

@@ -60,4 +61,6 @@ def main():
6061

6162

6263
if __name__ == "__main__":
64+
if len(sys.argv) == 3:
65+
_, DUMPS_FOLDER, ENGINE_DUMPS_FOLDER = sys.argv
6366
main()

tools/ffprefs/src/main.rs

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ use std::env;
107107
use std::fs;
108108
use std::path::PathBuf;
109109

110-
const STATIC_PREFS: &str = "../engine/modules/libpref/init/zen-static-prefs.inc";
111-
const FIREFOX_PREFS: &str = "../engine/browser/app/profile/firefox.js";
112-
const DYNAMIC_PREFS: &str = "../engine/browser/app/profile/zen.js";
110+
const STATIC_PREFS: &str = "modules/libpref/init/zen-static-prefs.inc";
111+
const FIREFOX_PREFS: &str = "browser/app/profile/firefox.js";
112+
const DYNAMIC_PREFS: &str = "browser/app/profile/zen.js";
113113

114114
#[derive(Serialize, Deserialize, PartialEq, Debug)]
115115
struct Preference {
@@ -124,12 +124,6 @@ struct Preference {
124124
sticky: Option<bool>,
125125
}
126126

127-
fn get_config_path() -> PathBuf {
128-
let mut path = env::current_dir().expect("Failed to get current directory");
129-
path.push("prefs");
130-
path
131-
}
132-
133127
fn ordered_prefs(mut prefs: Vec<Preference>) -> Vec<Preference> {
134128
// Sort preferences by name
135129
prefs.sort_by(|a, b| a.name.cmp(&b.name));
@@ -153,11 +147,10 @@ fn get_prefs_files_recursively(dir: &PathBuf, files: &mut Vec<PathBuf>) {
153147
}
154148
}
155149

156-
fn load_preferences() -> Vec<Preference> {
150+
fn load_preferences(prefs_path: &PathBuf) -> Vec<Preference> {
157151
let mut prefs = Vec::new();
158-
let config_path = get_config_path();
159152
let mut pref_files = Vec::new();
160-
get_prefs_files_recursively(&config_path, &mut pref_files);
153+
get_prefs_files_recursively(&prefs_path, &mut pref_files);
161154
for file_path in pref_files {
162155
let content = fs::read_to_string(&file_path).expect("Failed to read file");
163156
let mut parsed_prefs: Vec<Preference> =
@@ -263,14 +256,9 @@ fn get_value(pref: &Preference) -> String {
263256
}
264257
}
265258

266-
fn write_preferences(prefs: &[Preference]) {
267-
let config_path = get_config_path();
268-
if !config_path.exists() {
269-
fs::create_dir_all(&config_path).expect("Failed to create prefs directory");
270-
}
271-
272-
let static_prefs_path = config_path.join(STATIC_PREFS);
273-
let dynamic_prefs_path = config_path.join(DYNAMIC_PREFS);
259+
fn write_preferences(engine_path: &PathBuf, prefs: &[Preference]) {
260+
let static_prefs_path = engine_path.join(STATIC_PREFS);
261+
let dynamic_prefs_path = engine_path.join(DYNAMIC_PREFS);
274262
println!(
275263
"Writing preferences to:\n Static: {}\n Dynamic: {}",
276264
static_prefs_path.display(),
@@ -300,10 +288,10 @@ fn write_preferences(prefs: &[Preference]) {
300288
fs::write(&dynamic_prefs_path, dynamic_content).expect("Failed to write dynamic prefs");
301289
}
302290

303-
fn prepare_zen_prefs() {
291+
fn prepare_zen_prefs(engine_path: &PathBuf) {
304292
// Add `#include zen.js` to the bottom of the firefox.js file if it doesn't exist
305293
let line = "#include zen.js";
306-
let firefox_prefs_path = get_config_path().join(FIREFOX_PREFS);
294+
let firefox_prefs_path = engine_path.join(FIREFOX_PREFS);
307295
if let Ok(mut content) = fs::read_to_string(&firefox_prefs_path) {
308296
if !content.contains(line) {
309297
content.push_str(format!("\n{}\n", line).as_str());
@@ -351,15 +339,14 @@ fn expand_pref_values(prefs: &mut [Preference]) {
351339

352340
fn main() {
353341
let args: Vec<String> = env::args().collect();
354-
let root_path = if args.len() > 1 {
355-
PathBuf::from(&args[1])
356-
} else {
357-
env::current_dir().expect("Failed to get current directory")
358-
};
359-
env::set_current_dir(&root_path).expect("Failed to change directory");
342+
if args.len() != 3 {
343+
panic!("Must specify exactly two directories: prefs and engine");
344+
}
345+
let prefs_path = PathBuf::from(&args[1]);
346+
let engine_path = PathBuf::from(&args[2]);
360347

361-
prepare_zen_prefs();
362-
let mut preferences = load_preferences();
348+
prepare_zen_prefs(&engine_path);
349+
let mut preferences = load_preferences(&prefs_path);
363350
expand_pref_values(&mut preferences);
364-
write_preferences(&preferences);
351+
write_preferences(&engine_path, &preferences);
365352
}

0 commit comments

Comments
 (0)