From fe58556c0bf37f9f13685c367341d598fcb52d33 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:02:47 +0100 Subject: [PATCH] Disable resources_for_tests in production (#34177) Rather than relying on dead-code elimination to remove the function in production builds, it is better if it is never included in the first place. On OpenHarmony we never want to include these files into the binary, since we always bundle the test files into the `.hap` as part of the build process. The original comment got the condition inverted and in all normal builds the function will be checked as usual. There shouldn't be any additional value in checking the correctness of `resources_for_tests()` in production builds. Signed-off-by: Jonathan Schwender --- components/shared/embedder/resources.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/shared/embedder/resources.rs b/components/shared/embedder/resources.rs index 0dc7d4c65f6..a518061daf7 100644 --- a/components/shared/embedder/resources.rs +++ b/components/shared/embedder/resources.rs @@ -10,7 +10,7 @@ use cfg_if::cfg_if; static RES: LazyLock>>> = LazyLock::new(|| { cfg_if! { - if #[cfg(servo_production)] { + if #[cfg(any(servo_production, target_env = "ohos"))] { RwLock::new(None) } else { // Static assert that this is really a non-production build, rather @@ -150,9 +150,9 @@ pub trait ResourceReaderMethods { /// /// 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. +/// On OpenHarmony we never want to include files, since we ship all the files in the application +/// bundle anyway. +#[cfg(not(any(servo_production, target_env = "ohos")))] fn resources_for_tests() -> Box { struct ResourceReader; impl ResourceReaderMethods for ResourceReader {