mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
* Upgrade rustc to 1.83 Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix crown (change copied from linked clippy function) Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix named lifetime lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Bump shell.nix Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix non-local impl warnings Signed-off-by: Nico Burns <nico@nicoburns.com> * Format with 1.83 formatting changes Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix manual non-local impl Signed-off-by: Nico Burns <nico@nicoburns.com> * More fixes for crown Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix tidy Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix needless_return lints Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix doc comment lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix missing wait lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Allow needless_lifetimes lint Signed-off-by: Nico Burns <nico@nicoburns.com> * more doc comments Signed-off-by: Nico Burns <nico@nicoburns.com> * More needless_returns Signed-off-by: Nico Burns <nico@nicoburns.com> * is_empty lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix needless_lifetime lints Signed-off-by: Nico Burns <nico@nicoburns.com> * fix div_ceil lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Allow non-minimal bool Signed-off-by: Nico Burns <nico@nicoburns.com> * Non-local impl in constellation Signed-off-by: Nico Burns <nico@nicoburns.com> * Missing wait in constellation Signed-off-by: Nico Burns <nico@nicoburns.com> * fmt Signed-off-by: Nico Burns <nico@nicoburns.com> * remove useless lints table Signed-off-by: Nico Burns <nico@nicoburns.com> * Fixup comments Signed-off-by: Nico Burns <nico@nicoburns.com> * Allow non-local definition in sandboxing code to simplify feature flagging Signed-off-by: Nico Burns <nico@nicoburns.com> * Remove wait calls and allow zombie_processes lint Signed-off-by: Nico Burns <nico@nicoburns.com> --------- Signed-off-by: Nico Burns <nico@nicoburns.com>
125 lines
4.1 KiB
Rust
125 lines
4.1 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
use std::fs::File;
|
|
use std::io::Write;
|
|
use std::path::PathBuf;
|
|
use std::process::Command;
|
|
use std::time::Instant;
|
|
use std::{env, fmt};
|
|
|
|
use phf_shared::{self, FmtConst};
|
|
use serde_json::{self, Value};
|
|
|
|
fn main() {
|
|
let start = Instant::now();
|
|
|
|
let style_out_dir = PathBuf::from(env::var_os("DEP_SERVO_STYLE_CRATE_OUT_DIR").unwrap());
|
|
let css_properties_json = style_out_dir.join("css-properties.json");
|
|
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
|
|
|
println!("cargo::rerun-if-changed=dom/webidls");
|
|
println!("cargo::rerun-if-changed=dom/bindings/codegen");
|
|
println!("cargo::rerun-if-changed={}", css_properties_json.display());
|
|
println!("cargo::rerun-if-changed=../../third_party/WebIDL/WebIDL.py");
|
|
// NB: We aren't handling changes in `third_party/ply` here.
|
|
|
|
let status = Command::new(find_python())
|
|
.arg("dom/bindings/codegen/run.py")
|
|
.arg(&css_properties_json)
|
|
.arg(&out_dir)
|
|
.status()
|
|
.unwrap();
|
|
if !status.success() {
|
|
std::process::exit(1)
|
|
}
|
|
|
|
println!("Binding generation completed in {:?}", start.elapsed());
|
|
|
|
let json = out_dir.join("InterfaceObjectMapData.json");
|
|
let json: Value = serde_json::from_reader(File::open(json).unwrap()).unwrap();
|
|
let mut map = phf_codegen::Map::new();
|
|
for (key, value) in json.as_object().unwrap() {
|
|
map.entry(Bytes(key), value.as_str().unwrap());
|
|
}
|
|
let phf = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("InterfaceObjectMapPhf.rs");
|
|
let mut phf = File::create(phf).unwrap();
|
|
writeln!(
|
|
&mut phf,
|
|
"pub static MAP: phf::Map<&'static [u8], fn(JSContext, HandleObject)> = {};",
|
|
map.build(),
|
|
)
|
|
.unwrap();
|
|
}
|
|
|
|
#[derive(Eq, Hash, PartialEq)]
|
|
struct Bytes<'a>(&'a str);
|
|
|
|
impl FmtConst for Bytes<'_> {
|
|
fn fmt_const(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
// https://github.com/rust-lang/rust/issues/55223
|
|
// should technically be just `write!(formatter, "b\"{}\"", self.0)
|
|
// but the referenced issue breaks promotion in the surrounding code
|
|
write!(formatter, "{{ const FOO: &[u8] = b\"{}\"; FOO }}", self.0)
|
|
}
|
|
}
|
|
|
|
impl phf_shared::PhfHash for Bytes<'_> {
|
|
fn phf_hash<H: std::hash::Hasher>(&self, hasher: &mut H) {
|
|
self.0.as_bytes().phf_hash(hasher)
|
|
}
|
|
}
|
|
|
|
/// Tries to find a suitable python
|
|
///
|
|
/// Algorithm
|
|
/// 1. Trying to find python3/python in $VIRTUAL_ENV (this should be from Servo's venv)
|
|
/// 2. Checking PYTHON3 (set by mach)
|
|
/// 3. Falling back to the system installation.
|
|
///
|
|
/// Note: This function should be kept in sync with the version in `components/servo/build.rs`
|
|
fn find_python() -> PathBuf {
|
|
let mut candidates = vec![];
|
|
if let Some(venv) = env::var_os("VIRTUAL_ENV") {
|
|
let bin_directory = PathBuf::from(venv).join("bin");
|
|
|
|
let python3 = bin_directory.join("python3");
|
|
if python3.exists() {
|
|
candidates.push(python3);
|
|
}
|
|
let python = bin_directory.join("python");
|
|
if python.exists() {
|
|
candidates.push(python);
|
|
}
|
|
};
|
|
if let Some(python3) = env::var_os("PYTHON3") {
|
|
let python3 = PathBuf::from(python3);
|
|
if python3.exists() {
|
|
candidates.push(python3);
|
|
}
|
|
}
|
|
|
|
let system_python = ["python3", "python"].map(PathBuf::from);
|
|
candidates.extend_from_slice(&system_python);
|
|
|
|
for name in &candidates {
|
|
// Command::new() allows us to omit the `.exe` suffix on windows
|
|
if Command::new(name)
|
|
.arg("--version")
|
|
.output()
|
|
.is_ok_and(|out| out.status.success())
|
|
{
|
|
return name.to_owned();
|
|
}
|
|
}
|
|
let candidates = candidates
|
|
.into_iter()
|
|
.map(|c| c.into_os_string())
|
|
.collect::<Vec<_>>();
|
|
panic!(
|
|
"Can't find python (tried {:?})! Try enabling Servo's Python venv, \
|
|
setting the PYTHON3 env var or adding python3 to PATH.",
|
|
candidates.join(", ".as_ref())
|
|
)
|
|
}
|