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

@ -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)