Enable debug assertions for all builds other than official releases (#30509)

* Run main and try jobs with debug assertions

* use single quotes in workflow expressions

* set force-debug-assertions in main.yml

* set force-debug-assertions as part of decision job

* fix typo in MachCommands.build

* fix more hardcoded profile names

* fix tidy

* split cargo_profile_option on windows

* Fix running servoshell and unit tests through a symlink

* rename steps to make them less confusing

* fix more hardcoded cargo profile options

* fix missing inputs in linux-wpt and mac-wpt

* make filename an inherent method of Resource

* rework release-with-debug-assertions profile to production profile

* rework resource logic to eliminate std_test_override

* set production flag in nightly release builds

* clean up servobuild.example and windows.yml

* oops forgot to check in embedder_traits/build.rs

* fix mach test-unit behaviour through symlink

* unit tests only need current_dir and ancestors

* fix macOS package smoketest breakage

* expect css/css-color/currentcolor-003 to crash under layout 2013

* fix more references to {force,release-with}-debug-assertions

* fix local build failures under --profile production
This commit is contained in:
Delan Azabani 2023-10-26 16:22:14 +08:00 committed by GitHub
parent 88234309b0
commit a3d2f0c586
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 342 additions and 188 deletions

View file

@ -24,8 +24,5 @@ servo_geometry = { path = "../geometry" }
servo_url = { path = "../url" }
url = { workspace = true }
[dev-dependencies]
std_test_override = { path = "../std_test_override" }
[target.'cfg(not(target_os = "android"))'.dependencies]
dirs-next = "2.0"

View file

@ -11,6 +11,7 @@ name = "embedder_traits"
path = "lib.rs"
[dependencies]
cfg-if = { workspace = true }
crossbeam-channel = { workspace = true }
ipc-channel = { workspace = true }
keyboard-types = { workspace = true }

View file

@ -0,0 +1,23 @@
/* 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::error::Error;
use std::path::Path;
fn main() -> Result<(), Box<dyn Error>> {
// Cargo does not expose the profile name to crates or their build scripts,
// but we can extract it from OUT_DIR and set a custom cfg() ourselves.
let out = std::env::var("OUT_DIR")?;
let out = Path::new(&out);
let krate = out.parent().unwrap();
let build = krate.parent().unwrap();
let profile = build.parent().unwrap();
if profile.file_name().unwrap() == "production" {
println!("cargo:rustc-cfg=servo_production");
} else {
println!("cargo:rustc-cfg=servo_do_not_use_in_production");
}
Ok(())
}

View file

@ -3,13 +3,25 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::path::PathBuf;
use std::sync::{Once, RwLock};
use std::sync::RwLock;
use cfg_if::cfg_if;
use lazy_static::lazy_static;
lazy_static! {
static ref RES: RwLock<Option<Box<dyn ResourceReaderMethods + Sync + Send>>> =
RwLock::new(None);
static ref RES: RwLock<Option<Box<dyn ResourceReaderMethods + Sync + Send>>> = {
cfg_if! {
if #[cfg(servo_production)] {
RwLock::new(None)
} else {
// Static assert that this is really a non-production build, rather
// than a failure of the build scripts production check.
const _: () = assert!(cfg!(servo_do_not_use_in_production));
RwLock::new(Some(resources_for_tests()))
}
}
};
}
pub fn set(reader: Box<dyn ResourceReaderMethods + Sync + Send>) {
@ -88,42 +100,13 @@ pub trait ResourceReaderMethods {
fn sandbox_access_files_dirs(&self) -> Vec<PathBuf>;
}
// Cant #[cfg(test)] the following because it breaks tests in dependent crates.
pub fn set_for_tests() {
static ONCE: Once = Once::new();
ONCE.call_once(|| set(resources_for_tests()));
}
lazy_static::lazy_static! {
static ref CMD_RESOURCE_DIR: std::sync::Mutex<Option<PathBuf>> = std::sync::Mutex::new(None);
}
fn resources_dir_path_for_tests() -> PathBuf {
// This needs to be called before the process is sandboxed
// as we only give permission to read inside the resources directory,
// not the permissions the "search" for the resources directory.
let mut dir = CMD_RESOURCE_DIR.lock().unwrap();
if let Some(ref path) = *dir {
return PathBuf::from(path);
}
// Try ./resources in the current directory, then each of its ancestors.
let mut path = std::env::current_dir().unwrap();
loop {
path.push("resources");
if path.is_dir() {
*dir = Some(path);
return dir.clone().unwrap();
}
path.pop();
if !path.pop() {
panic!("Can't find resources directory")
}
}
}
/// Bake all of our resources into this crate for tests, unless we are `cfg!(servo_production)`.
///
/// Local non-production embedder builds (e.g. servoshell) can still override these with [`set`],
/// if runtime loading of prefs.json and other resources is needed.
///
/// In theory this can be `#[cfg(servo_production)]`, but omitting the attribute ensures that the
/// code is always checked by the compiler, even if it later gets optimised out as dead code.
fn resources_for_tests() -> Box<dyn ResourceReaderMethods + Sync + Send> {
struct ResourceReader;
impl ResourceReaderMethods for ResourceReader {
@ -131,12 +114,36 @@ fn resources_for_tests() -> Box<dyn ResourceReaderMethods + Sync + Send> {
vec![]
}
fn sandbox_access_files_dirs(&self) -> Vec<PathBuf> {
vec![resources_dir_path_for_tests()]
vec![]
}
fn read(&self, file: Resource) -> Vec<u8> {
let mut path = resources_dir_path_for_tests();
path.push(file.filename());
std::fs::read(path).expect("Can't read file")
match file {
Resource::Preferences => &include_bytes!("../../resources/prefs.json")[..],
Resource::BluetoothBlocklist => {
&include_bytes!("../../resources/gatt_blocklist.txt")[..]
},
Resource::DomainList => &include_bytes!("../../resources/public_domains.txt")[..],
Resource::HstsPreloadList => {
&include_bytes!("../../resources/hsts_preload.json")[..]
},
Resource::BadCertHTML => &include_bytes!("../../resources/badcert.html")[..],
Resource::NetErrorHTML => &include_bytes!("../../resources/neterror.html")[..],
Resource::UserAgentCSS => &include_bytes!("../../resources/user-agent.css")[..],
Resource::ServoCSS => &include_bytes!("../../resources/servo.css")[..],
Resource::PresentationalHintsCSS => {
&include_bytes!("../../resources/presentational-hints.css")[..]
},
Resource::QuirksModeCSS => &include_bytes!("../../resources/quirks-mode.css")[..],
Resource::RippyPNG => &include_bytes!("../../resources/rippy.png")[..],
Resource::MediaControlsCSS => {
&include_bytes!("../../resources/media-controls.css")[..]
},
Resource::MediaControlsJS => {
&include_bytes!("../../resources/media-controls.js")[..]
},
Resource::CrashHTML => &include_bytes!("../../resources/crash.html")[..],
}
.to_owned()
}
}
Box::new(ResourceReader)

View file

@ -70,7 +70,6 @@ webpki-roots = { workspace = true }
[dev-dependencies]
futures = { version = "0.3", features = ["compat"] }
std_test_override = { path = "../std_test_override" }
tokio-test = "0.4"
tokio-stream = { version = "0.1", features = ["net"] }
hyper = { workspace = true, features = ["full"] }

View file

@ -40,6 +40,3 @@ time = { workspace = true }
url = { workspace = true }
uuid = { workspace = true }
webrender_api = { git = "https://github.com/servo/webrender" }
[dev-dependencies]
std_test_override = { path = "../std_test_override" }

View file

@ -45,6 +45,3 @@ webdriver = { workspace = true }
webgpu = { path = "../webgpu" }
webrender_api = { workspace = true }
webxr-api = { git = "https://github.com/servo/webxr", features = ["ipc"] }
[dev-dependencies]
std_test_override = { path = "../std_test_override" }

View file

@ -1,14 +0,0 @@
[package]
name = "std_test_override"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
edition = "2018"
publish = false
[lib]
name = "test"
path = "lib.rs"
[dependencies]
embedder_traits = { path = "../embedder_traits" }

View file

@ -1,14 +0,0 @@
/* 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/. */
#![feature(test)]
extern crate test;
pub use test::*;
pub fn test_main_static(tests: &[&TestDescAndFn]) {
embedder_traits::resources::set_for_tests();
test::test_main_static(tests);
}