From b8f2ada817a5d96f7889fd78196851f7de5aac31 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sun, 21 Mar 2021 16:15:54 +0000 Subject: [PATCH 1/9] Issue #1053 - Remove __ANDROID__ defines (except in third party code) --- dom/media/AudioStream.cpp | 7 --- dom/media/GraphDriver.cpp | 8 ---- gfx/cairo/libpixman/src/pixman-arm.c | 42 ++--------------- gfx/cairo/libpixman/src/pixman-cpu.c | 48 +++----------------- gfx/harfbuzz/src/hb-private.hh | 9 +--- js/src/jit/JitSpewer.cpp | 2 - js/src/jit/PerfSpewer.cpp | 11 ----- js/src/threading/posix/ConditionVariable.cpp | 5 +- tools/profiler/core/PlatformMacros.h | 10 ---- tools/profiler/lul/LulPlatformMacros.h | 12 +---- 10 files changed, 17 insertions(+), 137 deletions(-) diff --git a/dom/media/AudioStream.cpp b/dom/media/AudioStream.cpp index 4b1d82c37f..77ed512eee 100644 --- a/dom/media/AudioStream.cpp +++ b/dom/media/AudioStream.cpp @@ -331,13 +331,6 @@ AudioStream::Init(uint32_t aNumChannels, uint32_t aRate, cubeb_stream_params params; params.rate = aRate; params.channels = mOutChannels; -#if defined(__ANDROID__) - params.stream_type = CUBEB_STREAM_TYPE_MUSIC; - - if (params.stream_type == CUBEB_STREAM_TYPE_MAX) { - return NS_ERROR_INVALID_ARG; - } -#endif params.format = ToCubebFormat::value; mAudioClock.Init(aRate); diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp index fe40c82e24..e8b71a2318 100644 --- a/dom/media/GraphDriver.cpp +++ b/dom/media/GraphDriver.cpp @@ -630,15 +630,7 @@ AudioCallbackDriver::Init() mSampleRate = output.rate = CubebUtils::PreferredSampleRate(); -#if defined(__ANDROID__) - output.stream_type = CUBEB_STREAM_TYPE_MUSIC; - if (output.stream_type == CUBEB_STREAM_TYPE_MAX) { - NS_WARNING("Bad stream type"); - return; - } -#else (void)mAudioChannel; -#endif output.channels = mGraphImpl->AudioChannelCount(); if (AUDIO_OUTPUT_FORMAT == AUDIO_FORMAT_S16) { diff --git a/gfx/cairo/libpixman/src/pixman-arm.c b/gfx/cairo/libpixman/src/pixman-arm.c index 145bd9050b..358372e50a 100644 --- a/gfx/cairo/libpixman/src/pixman-arm.c +++ b/gfx/cairo/libpixman/src/pixman-arm.c @@ -1,19 +1,20 @@ /* * Copyright © 2000 SuSE, Inc. * Copyright © 2007 Red Hat, Inc. + * Copyright © 2021 Moonchild Productions * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or + * documentation, and that the names of the authors not be used in advertising or * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the + * written prior permission. The authors make no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHORS * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN @@ -94,39 +95,6 @@ detect_cpu_features (void) return features; } -#elif defined(__ANDROID__) || defined(ANDROID) /* Android */ - -static arm_cpu_features_t -detect_cpu_features (void) -{ - arm_cpu_features_t features = 0; - char buf[1024]; - char* pos; - const char* ver_token = "CPU architecture: "; - FILE* f = fopen("/proc/cpuinfo", "r"); - if (!f) { - return features; - } - - fread(buf, sizeof(char), sizeof(buf), f); - fclose(f); - pos = strstr(buf, ver_token); - if (pos) { - char vchar = *(pos + strlen(ver_token)); - if (vchar >= '0' && vchar <= '9') { - int ver = vchar - '0'; - if (ver >= 7) - features |= ARM_V7; - } - } - if (strstr(buf, "neon") != NULL) - features |= ARM_NEON; - if (strstr(buf, "vfp") != NULL) - features |= ARM_VFP; - - return features; -} - #elif defined (__linux__) /* linux ELF */ #include diff --git a/gfx/cairo/libpixman/src/pixman-cpu.c b/gfx/cairo/libpixman/src/pixman-cpu.c index 0eabb4e256..30f5fba8a4 100644 --- a/gfx/cairo/libpixman/src/pixman-cpu.c +++ b/gfx/cairo/libpixman/src/pixman-cpu.c @@ -1,19 +1,20 @@ /* * Copyright © 2000 SuSE, Inc. * Copyright © 2007 Red Hat, Inc. + * Copyright © 2021 Moonchild Productions * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or + * documentation, and that the names of the authors not be used in advertising or * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the + * written prior permission. The authors make no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHORS * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN @@ -290,7 +291,7 @@ pixman_have_arm_iwmmxt (void) #endif } -#elif defined (__linux__) || defined(__ANDROID__) || defined(ANDROID) /* linux ELF or ANDROID */ +#elif defined (__linux__) /* linux ELF */ static pixman_bool_t arm_has_v7 = FALSE; static pixman_bool_t arm_has_v6 = FALSE; @@ -299,39 +300,6 @@ static pixman_bool_t arm_has_neon = FALSE; static pixman_bool_t arm_has_iwmmxt = FALSE; static pixman_bool_t arm_tests_initialized = FALSE; -#if defined(__ANDROID__) || defined(ANDROID) /* Android device support */ - -static void -pixman_arm_read_auxv_or_cpu_features () -{ - char buf[1024]; - char* pos; - const char* ver_token = "CPU architecture: "; - FILE* f = fopen("/proc/cpuinfo", "r"); - if (!f) { - arm_tests_initialized = TRUE; - return; - } - - fread(buf, sizeof(char), sizeof(buf), f); - fclose(f); - pos = strstr(buf, ver_token); - if (pos) { - char vchar = *(pos + strlen(ver_token)); - if (vchar >= '0' && vchar <= '9') { - int ver = vchar - '0'; - arm_has_v7 = ver >= 7; - arm_has_v6 = ver >= 6; - } - } - arm_has_neon = strstr(buf, "neon") != NULL; - arm_has_vfp = strstr(buf, "vfp") != NULL; - arm_has_iwmmxt = strstr(buf, "iwmmxt") != NULL; - arm_tests_initialized = TRUE; -} - -#elif defined (__linux__) /* linux ELF */ - #include #include #include @@ -382,8 +350,6 @@ pixman_arm_read_auxv_or_cpu_features () arm_tests_initialized = TRUE; } -#endif /* Linux elf */ - #if defined(USE_ARM_SIMD) pixman_bool_t pixman_have_arm_simd (void) @@ -420,7 +386,7 @@ pixman_have_arm_iwmmxt (void) #endif /* USE_ARM_IWMMXT */ -#else /* !_MSC_VER && !Linux elf && !Android */ +#else /* !_MSC_VER && !Linux elf */ #define pixman_have_arm_simd() FALSE #define pixman_have_arm_neon() FALSE diff --git a/gfx/harfbuzz/src/hb-private.hh b/gfx/harfbuzz/src/hb-private.hh index 666af6260b..23c07ee258 100644 --- a/gfx/harfbuzz/src/hb-private.hh +++ b/gfx/harfbuzz/src/hb-private.hh @@ -1,6 +1,7 @@ /* * Copyright © 2007,2008,2009 Red Hat, Inc. * Copyright © 2011,2012 Google, Inc. + * Copyright © 2021 Moonchild Productions * * This is part of HarfBuzz, a text shaping library. * @@ -24,6 +25,7 @@ * * Red Hat Author(s): Behdad Esfahbod * Google Author(s): Behdad Esfahbod + * Moonchild Productions Author(s): Moonchild Straver */ #ifndef HB_PRIVATE_HH @@ -202,13 +204,6 @@ static int errno = 0; /* Use something better? */ * mingw32 headers say atexit is safe to use in shared libraries. */ # define HB_USE_ATEXIT 1 -# elif defined(__ANDROID__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) -/* This was fixed in Android NKD r8 or r8b: - * https://code.google.com/p/android/issues/detail?id=6455 - * which introduced GCC 4.6: - * https://developer.android.com/tools/sdk/ndk/index.html - */ -# define HB_USE_ATEXIT 1 # endif #endif diff --git a/js/src/jit/JitSpewer.cpp b/js/src/jit/JitSpewer.cpp index 0248c0a71f..12544b9301 100644 --- a/js/src/jit/JitSpewer.cpp +++ b/js/src/jit/JitSpewer.cpp @@ -30,8 +30,6 @@ #ifndef JIT_SPEW_DIR # if defined(_WIN32) # define JIT_SPEW_DIR "" -# elif defined(__ANDROID__) -# define JIT_SPEW_DIR "/data/local/tmp/" # else # define JIT_SPEW_DIR "/tmp/" # endif diff --git a/js/src/jit/PerfSpewer.cpp b/js/src/jit/PerfSpewer.cpp index 2dfa2c1f54..d428a8f926 100644 --- a/js/src/jit/PerfSpewer.cpp +++ b/js/src/jit/PerfSpewer.cpp @@ -28,12 +28,7 @@ // so also try /sdcard/. #ifndef PERF_SPEW_DIR -# if defined(__ANDROID__) -# define PERF_SPEW_DIR "/data/local/tmp/" -# define PERF_SPEW_DIR_2 "/sdcard/" -# else # define PERF_SPEW_DIR "/tmp/" -# endif #endif using namespace js; @@ -104,12 +99,6 @@ js::jit::CheckPerf() { return; } -#if defined(__ANDROID__) - if (openPerfMap(PERF_SPEW_DIR_2)) { - PerfChecked = true; - return; - } -#endif fprintf(stderr, "Failed to open perf map file. Disabling IONPERF.\n"); PerfMode = PERF_MODE_NONE; } diff --git a/js/src/threading/posix/ConditionVariable.cpp b/js/src/threading/posix/ConditionVariable.cpp index 6189fab989..fe768eae3b 100644 --- a/js/src/threading/posix/ConditionVariable.cpp +++ b/js/src/threading/posix/ConditionVariable.cpp @@ -22,9 +22,8 @@ using mozilla::TimeStamp; static const long NanoSecPerSec = 1000000000; -// Android 32-bit & macOS 10.12 has the clock functions, but not pthread_condattr_setclock. -#if defined(HAVE_CLOCK_MONOTONIC) && \ - !(defined(__ANDROID__) && !defined(__LP64__)) && !defined(__APPLE__) +// MacOS 10.12 has the clock functions, but not pthread_condattr_setclock. +#if defined(HAVE_CLOCK_MONOTONIC) && !defined(__APPLE__) # define USE_CLOCK_API #endif diff --git a/tools/profiler/core/PlatformMacros.h b/tools/profiler/core/PlatformMacros.h index 9a544a42e3..0bedbd512f 100644 --- a/tools/profiler/core/PlatformMacros.h +++ b/tools/profiler/core/PlatformMacros.h @@ -34,16 +34,6 @@ # define SPS_ARCH_amd64 1 # define SPS_OS_linux 1 -#elif defined(__ANDROID__) && defined(__arm__) -# define SPS_PLAT_arm_android 1 -# define SPS_ARCH_arm 1 -# define SPS_OS_android 1 - -#elif defined(__ANDROID__) && defined(__i386__) -# define SPS_PLAT_x86_android 1 -# define SPS_ARCH_x86 1 -# define SPS_OS_android 1 - #elif defined(__linux__) && defined(__i386__) # define SPS_PLAT_x86_linux 1 # define SPS_ARCH_x86 1 diff --git a/tools/profiler/lul/LulPlatformMacros.h b/tools/profiler/lul/LulPlatformMacros.h index 9a19bae106..6464da0678 100644 --- a/tools/profiler/lul/LulPlatformMacros.h +++ b/tools/profiler/lul/LulPlatformMacros.h @@ -30,21 +30,11 @@ # define LUL_ARCH_x64 1 # define LUL_OS_linux 1 -#elif defined(__linux__) && defined(__i386__) && !defined(__ANDROID__) +#elif defined(__linux__) && defined(__i386__) # define LUL_PLAT_x86_linux 1 # define LUL_ARCH_x86 1 # define LUL_OS_linux 1 -#elif defined(__ANDROID__) && defined(__arm__) -# define LUL_PLAT_arm_android 1 -# define LUL_ARCH_arm 1 -# define LUL_OS_android 1 - -#elif defined(__ANDROID__) && defined(__i386__) -# define LUL_PLAT_x86_android 1 -# define LUL_ARCH_x86 1 -# define LUL_OS_android 1 - #else # error "Unsupported platform" #endif From 407a983af1bec5d37c690627990d296f51706598 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Mon, 22 Mar 2021 09:37:12 +0000 Subject: [PATCH 2/9] Issue #1751 - Remove MacOS support from configure --- build/macosx/build-cctools.sh | 26 - build/macosx/cross-mozconfig.common | 47 - build/macosx/local-mozconfig.common | 46 - build/macosx/mozconfig.common | 5 - build/macosx/permissions/chown_revert.c | 20 - build/macosx/permissions/chown_root.c | 14 - build/macosx/universal/mozconfig | 11 - build/macosx/universal/mozconfig.common | 55 - build/macosx/universal/unify | 1525 ----------------------- old-configure.in | 224 +--- 10 files changed, 38 insertions(+), 1935 deletions(-) delete mode 100644 build/macosx/build-cctools.sh delete mode 100644 build/macosx/cross-mozconfig.common delete mode 100644 build/macosx/local-mozconfig.common delete mode 100644 build/macosx/mozconfig.common delete mode 100644 build/macosx/permissions/chown_revert.c delete mode 100644 build/macosx/permissions/chown_root.c delete mode 100644 build/macosx/universal/mozconfig delete mode 100644 build/macosx/universal/mozconfig.common delete mode 100644 build/macosx/universal/unify diff --git a/build/macosx/build-cctools.sh b/build/macosx/build-cctools.sh deleted file mode 100644 index af0b36221b..0000000000 --- a/build/macosx/build-cctools.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -set -e - -if ! git remote -v | grep origin | grep -q cctools-port; then - echo "must be in a cctools-port checkout" - exit 1 -fi - -mkdir build-cctools -cd build-cctools - -CFLAGS='-mcpu=generic -mtune=generic' MACOSX_DEPLOYMENT_TARGET=10.7 ../cctools/configure --target=x86_64-apple-darwin11 -env MACOSX_DEPLOYMENT_TARGET=10.7 make -s -j4 - -if test ! -e ld64/src/ld/ld; then - echo "ld did not get built" - exit 1 -fi - -gtar jcf cctools.tar.bz2 ld64/src/ld/ld --transform 's#ld64/src/ld#cctools/bin#' - -cd ../ - -echo "build from $(git show --pretty=format:%H -s HEAD) complete!" -echo "upload the build-cctools/cctools.tar.bz2 file to tooltool" diff --git a/build/macosx/cross-mozconfig.common b/build/macosx/cross-mozconfig.common deleted file mode 100644 index 8e56394d00..0000000000 --- a/build/macosx/cross-mozconfig.common +++ /dev/null @@ -1,47 +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 http://mozilla.org/MPL/2.0/. - -MOZ_AUTOMATION_L10N_CHECK=0 - -if [ "x$IS_NIGHTLY" = "xyes" ]; then - # Some nightlies (eg: Mulet) don't want these set. - MOZ_AUTOMATION_UPDATE_PACKAGING=${MOZ_AUTOMATION_UPDATE_PACKAGING-1} - MOZ_AUTOMATION_SDK=${MOZ_AUTOMATION_SDK-1} -fi -. "$topsrcdir/build/mozconfig.common" - -# ld needs libLTO.so from llvm -mk_add_options "export LD_LIBRARY_PATH=$topsrcdir/clang/lib" - -CROSS_CCTOOLS_PATH=$topsrcdir/cctools -CROSS_SYSROOT=$topsrcdir/MacOSX10.7.sdk -CROSS_PRIVATE_FRAMEWORKS=$CROSS_SYSROOT/System/Library/PrivateFrameworks -FLAGS="-target x86_64-apple-darwin10 -mlinker-version=136 -B $CROSS_CCTOOLS_PATH/bin -isysroot $CROSS_SYSROOT" - -export CC="$topsrcdir/clang/bin/clang $FLAGS" -export CXX="$topsrcdir/clang/bin/clang++ $FLAGS" -export CPP="$topsrcdir/clang/bin/clang $FLAGS -E" -export LLVMCONFIG=$topsrcdir/clang/bin/llvm-config -export LDFLAGS="-Wl,-syslibroot,$CROSS_SYSROOT -Wl,-dead_strip" -export TOOLCHAIN_PREFIX=$CROSS_CCTOOLS_PATH/bin/x86_64-apple-darwin10- -export DSYMUTIL=$topsrcdir/clang/bin/llvm-dsymutil -export GENISOIMAGE=$topsrcdir/genisoimage/genisoimage -export DMG_TOOL=$topsrcdir/dmg/dmg - -export HOST_CC="$topsrcdir/clang/bin/clang" -export HOST_CXX="$topsrcdir/clang/bin/clang++" -export HOST_CPP="$topsrcdir/clang/bin/clang -E" -export HOST_CFLAGS="-g" -export HOST_CXXFLAGS="-g" -export HOST_LDFLAGS="-g" - -ac_add_options --target=x86_64-apple-darwin -ac_add_options --with-macos-private-frameworks=$CROSS_PRIVATE_FRAMEWORKS - -# Enable static analysis checks by default on OSX cross builds. -ac_add_options --enable-clang-plugin - -. "$topsrcdir/build/mozconfig.cache" - -export SOCORRO_SYMBOL_UPLOAD_TOKEN_FILE=/builds/crash-stats-api.token diff --git a/build/macosx/local-mozconfig.common b/build/macosx/local-mozconfig.common deleted file mode 100644 index 02a09d2fe0..0000000000 --- a/build/macosx/local-mozconfig.common +++ /dev/null @@ -1,46 +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 http://mozilla.org/MPL/2.0/. - -if [ "x$IS_NIGHTLY" = "xyes" ]; then - # Some nightlies (eg: Mulet) don't want these set. - MOZ_AUTOMATION_UPLOAD_SYMBOLS=${MOZ_AUTOMATION_UPLOAD_SYMBOLS-1} - MOZ_AUTOMATION_UPDATE_PACKAGING=${MOZ_AUTOMATION_UPDATE_PACKAGING-1} - MOZ_AUTOMATION_SDK=${MOZ_AUTOMATION_SDK-1} -fi -. "$topsrcdir/build/mozconfig.common" - -if [ -d "$topsrcdir/clang" ]; then - # mozilla-central based build - export CC=$topsrcdir/clang/bin/clang - export CXX=$topsrcdir/clang/bin/clang++ - export LLVMCONFIG=$topsrcdir/clang/bin/llvm-config - export DSYMUTIL=$topsrcdir/clang/bin/llvm-dsymutil - # Use an updated linker. - ldflags="-B$topsrcdir/cctools/bin" -elif [ -d "$topsrcdir/../clang" ]; then - # comm-central based build - export CC=$topsrcdir/../clang/bin/clang - export CXX=$topsrcdir/../clang/bin/clang++ - export LLVMCONFIG=$topsrcdir/../clang/bin/llvm-config - export DSYMUTIL=$topsrcdir/../clang/bin/llvm-dsymutil - # Use an updated linker. - ldflags="-B$topsrcdir/../cctools/bin" -fi - -# Ensure the updated linker doesn't generate things our older build tools -# don't understand. -ldflags="$ldflags -Wl,-no_data_in_code_info" -export LDFLAGS="$ldflags" - -# If not set use the system default clang -if [ -z "$CC" ]; then - export CC=clang -fi - -# If not set use the system default clang++ -if [ -z "$CXX" ]; then - export CXX=clang++ -fi - -export SOCORRO_SYMBOL_UPLOAD_TOKEN_FILE=/builds/crash-stats-api.token diff --git a/build/macosx/mozconfig.common b/build/macosx/mozconfig.common deleted file mode 100644 index 27634b7f31..0000000000 --- a/build/macosx/mozconfig.common +++ /dev/null @@ -1,5 +0,0 @@ -if test `uname -s` = Linux; then - . $topsrcdir/build/macosx/cross-mozconfig.common -else - . $topsrcdir/build/macosx/local-mozconfig.common -fi diff --git a/build/macosx/permissions/chown_revert.c b/build/macosx/permissions/chown_revert.c deleted file mode 100644 index 2cf3e37c3f..0000000000 --- a/build/macosx/permissions/chown_revert.c +++ /dev/null @@ -1,20 +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 http://mozilla.org/MPL/2.0/. */ - -#include -#include - -int main(int argc, char **argv) -{ - if (argc != 2) - return 1; - - uid_t realuser = getuid(); - char uidstring[20]; - snprintf(uidstring, 19, "%i", realuser); - uidstring[19] = '\0'; - - return execl("/usr/sbin/chown", - "/usr/sbin/chown", "-R", "-h", uidstring, argv[1], (char*) 0); -} diff --git a/build/macosx/permissions/chown_root.c b/build/macosx/permissions/chown_root.c deleted file mode 100644 index c9b13a5308..0000000000 --- a/build/macosx/permissions/chown_root.c +++ /dev/null @@ -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 http://mozilla.org/MPL/2.0/. */ - -#include - -int main(int argc, char **argv) -{ - if (argc != 2) - return 1; - - return execl("/usr/sbin/chown", - "/usr/sbin/chown", "-R", "-h", "root:admin", argv[1], (char*) 0); -} diff --git a/build/macosx/universal/mozconfig b/build/macosx/universal/mozconfig deleted file mode 100644 index 32ab66f2df..0000000000 --- a/build/macosx/universal/mozconfig +++ /dev/null @@ -1,11 +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 http://mozilla.org/MPL/2.0/. - -# i386/x86-64 Universal Build mozconfig - -# As used here, arguments in $MOZ_BUILD_PROJECTS are suitable as arguments -# to gcc's -arch parameter. -mk_add_options MOZ_BUILD_PROJECTS="x86_64 i386" - -. $topsrcdir/build/macosx/universal/mozconfig.common diff --git a/build/macosx/universal/mozconfig.common b/build/macosx/universal/mozconfig.common deleted file mode 100644 index bb54bc6c43..0000000000 --- a/build/macosx/universal/mozconfig.common +++ /dev/null @@ -1,55 +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 http://mozilla.org/MPL/2.0/. - -mk_add_options MOZ_UNIFY_BDATE=1 - -DARWIN_VERSION=10 -ac_add_app_options i386 --target=i386-apple-darwin$DARWIN_VERSION -ac_add_app_options x86_64 --target=x86_64-apple-darwin$DARWIN_VERSION -ac_add_app_options i386 --with-unify-dist=../x86_64/dist -ac_add_app_options x86_64 --with-unify-dist=../i386/dist - -if ! test `uname -s` = Linux; then - # Cross-universal builds already do the equivalent of this by setting -isysroot directly - ac_add_options --with-macos-sdk=/Developer/SDKs/MacOSX10.7.sdk -fi - -. $topsrcdir/build/macosx/mozconfig.common - -# $MOZ_BUILD_APP is only defined when sourced by configure. That's not a -# problem, because the variables it affects only need to be set for -# configure. -if test -n "$MOZ_BUILD_APP" ; then -if test "$MOZ_BUILD_APP" = "i386" -o "$MOZ_BUILD_APP" = "x86_64"; then - TARGET_CPU=$MOZ_BUILD_APP - - # $HOST_CXX is presently unused. $HOST_CC will only be used during a cross - # compile. - HOST_CC=$CC - HOST_CXX=$CXX - - NATIVE_CPU=`$topsrcdir/build/autoconf/config.guess | cut -f1 -d-` - - # It's not strictly necessary to specify -arch during native builds, but it - # makes the merged about:buildconfig easier to follow, and it reduces - # conditionalized differences between builds. - CC="$CC -arch $TARGET_CPU" - CXX="$CXX -arch $TARGET_CPU" - - # These must be set for cross builds, and don't hurt straight builds. - RANLIB="${TOOLCHAIN_PREFIX}ranlib" - AR="${TOOLCHAIN_PREFIX}ar" - AS=$CC - LD=ld - STRIP="${TOOLCHAIN_PREFIX}strip" - OTOOL="${TOOLCHAIN_PREFIX}otool" - - # Each per-CPU build should be entirely oblivious to the fact that a - # universal binary will be produced. The exception is packager.mk, which - # needs to know to look for universal bits when building the .dmg. - UNIVERSAL_BINARY=1 - - export CC CXX HOST_CC HOST_CXX RANLIB AR AS LD STRIP OTOOL -fi -fi diff --git a/build/macosx/universal/unify b/build/macosx/universal/unify deleted file mode 100644 index 38dd354145..0000000000 --- a/build/macosx/universal/unify +++ /dev/null @@ -1,1525 +0,0 @@ -#!/usr/bin/perl -# 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 http://mozilla.org/MPL/2.0/. - -use strict; -use warnings; - -=pod - -=head1 NAME - -B - Mac OS X universal binary packager - -=head1 SYNOPSIS - -B -I -I -I -[B<--dry-run>] -[B<--only-one> I] -[B<--verbosity> I] -[B<--unify-with-sort> I] - -=head1 DESCRIPTION - -I merges any two architecture-specific files or directory trees -into a single file or tree suitable for use on either architecture as a -"fat" or "universal binary." - -Architecture-specific Mach-O files will be merged into fat Mach-O files -using L. Non-Mach-O files in the architecture-specific trees -are compared to ensure that they are equivalent before copying. Symbolic -links are permitted in the architecture-specific trees and will cause -identical links to be created in the merged tree, provided that the source -links have identical targets. Directories are processed recursively. - -If the architecture-specific source trees contain zip archives (including -jar files) that are not identical according to a byte-for-byte check, they -are still assumed to be equivalent if both archives contain exactly the -same members with identical checksums and sizes. - -Behavior when one architecture-specific tree contains files that the other -does not is controlled by the B<--only-one> option. - -If Mach-O files cannot be merged using L, zip archives are not -equivalent, regular files are not identical, or any other error occurs, -B will fail with an exit status of 1. Diagnostic messages are -typically printed to stderr; this behavior can be controlled with the -B<--verbosity> option. - -=head1 OPTIONS - -=over 5 - -=item I - -=item I - -The paths to directory trees containing PowerPC and x86 builds, -respectively. I and I are permitted to contain files -that are already "fat," and only the appropriate architecture's images will -be used. - -I and I are also permitted to both be files, in which -case B operates solely on those files, and produces an appropriate -merged file at I. - -=item I - -The path to the merged file or directory tree. This path will be created, -and it must not exist prior to running B. - -=item B<--dry-run> - -When specified, the commands that would be executed are printed, without -actually executing them. Note that B<--dry-run> and the equivalent -B<--verbosity> level during "wet" runs may print equivalent commands when -no commands are in fact executed: certain operations are handled internally -within B, and an approximation of a command that performs a similar -task is printed. - -=item B<--only-one> I - -Controls handling of files that are only present in one of the two source -trees. I may be: - skip - These files are skipped. - copy - These files are copied from the tree in which they exist. - fail - When this condition occurs, it is treated as an error. - -The default I is copy. - -=item B<--verbosity> I - -Adjusts the level of loudness of B. The possible values for -I are: - 0 - B never prints anything. - (Other programs that B calls may still print messages.) - 1 - Fatal error messages are printed to stderr. - 2 - Nonfatal warnings are printed to stderr. - 3 - Commands are printed to stdout as they are executed. - -The default I is 2. - -=item B<--unify-with-sort> I - -Allows merging files matching I that differ only by the ordering -of the lines contained within them. The unified file will have its contents -sorted. This option may be given multiple times to specify multiple -regexes for matching files. - -=back - -=head1 EXAMPLES - -=over 5 - -=item Create a universal .app bundle from two architecture-specific .app -bundles: - -unify --only-one copy ppc/dist/firefox/Firefox.app - x86/dist/firefox/Firefox.app universal/Firefox.app - --verbosity 3 - -=item Merge two identical architecture-specific trees: - -unify --only-one fail /usr/local /nfs/x86/usr/local - /tmp/usrlocal.fat - -=back - -=head1 REQUIREMENTS - -The only esoteric requirement of B is that the L command -be available. It is present on Mac OS X systems at least as early as -10.3.9, and probably earlier. Mac OS X 10.4 ("Tiger") or later are -recommended. - -=head1 LICENSE - -MPL 2. - -=head1 AUTHOR - -The software was initially written by Mark Mentovai; copyright 2006 -Google Inc. - -=head1 SEE ALSO - -L, L, L - -=cut - -use Archive::Zip(':ERROR_CODES'); -use Errno; -use Fcntl; -use File::Compare; -use File::Copy; -use Getopt::Long; - -my (%gConfig, $gDryRun, $gOnlyOne, $gVerbosity, @gSortMatches); - -sub argumentEscape(@); -sub command(@); -sub compareZipArchives($$); -sub complain($$@); -sub copyIfIdentical($$$); -sub slurp($); -sub get_sorted($); -sub compare_sorted($$); -sub copyIfIdenticalWhenSorted($$$); -sub createUniqueFile($$); -sub makeUniversal($$$); -sub makeUniversalDirectory($$$); -sub makeUniversalInternal($$$$); -sub makeUniversalFile($$$); -sub usage(); -sub readZipCRCs($); - -{ - package FileAttrCache; - - sub new($$); - - sub isFat($); - sub isMachO($); - sub isZip($); - sub lIsDir($); - sub lIsExecutable($); - sub lIsRegularFile($); - sub lIsSymLink($); - sub lstat($); - sub lstatMode($); - sub lstatType($); - sub magic($); - sub magic2($); - sub path($); - sub stat($); - sub statSize($); -} - -%gConfig = ( - 'cmd_lipo' => 'lipo', - 'cmd_rm' => 'rm', -); - -$gDryRun = 0; -$gOnlyOne = 'copy'; -$gVerbosity = 2; -@gSortMatches = (); - -Getopt::Long::Configure('pass_through'); -GetOptions('dry-run' => \$gDryRun, - 'only-one=s' => \$gOnlyOne, - 'verbosity=i' => \$gVerbosity, - 'unify-with-sort=s' => \@gSortMatches, - 'config=s' => \%gConfig); # "hidden" option not in usage() - -if (scalar(@ARGV) != 3 || $gVerbosity < 0 || $gVerbosity > 3 || - ($gOnlyOne ne 'skip' && $gOnlyOne ne 'copy' && $gOnlyOne ne 'fail')) { - usage(); - exit(1); -} - -if (!makeUniversal($ARGV[0],$ARGV[1],$ARGV[2])) { - # makeUniversal or something it called will have printed an error. - exit(1); -} - -exit(0); - -# argumentEscape(@arguments) -# -# Takes a list of @arguments and makes them shell-safe. -sub argumentEscape(@) { - my (@arguments); - @arguments = @_; - - my ($argument, @argumentsOut); - foreach $argument (@arguments) { - $argument =~ s%([^A-Za-z0-9_\-/.=+,])%\\$1%g; - push(@argumentsOut, $argument); - } - - return @argumentsOut; -} - -# command(@arguments) -# -# Runs the specified command by calling system(@arguments). If $gDryRun -# is true, the command is printed but not executed, and 0 is returned. -# if $gVerbosity is greater than 1, the command is printed before being -# executed. When the command is executed, the system() return value will -# be returned. stdout and stderr are left connected for command output. -sub command(@) { - my (@arguments); - @arguments = @_; - if ($gVerbosity >= 3 || $gDryRun) { - print(join(' ', argumentEscape(@arguments))."\n"); - } - if ($gDryRun) { - return 0; - } - return system(@arguments); -} - -# compareZipArchives($zip1, $zip2) -# -# Given two pathnames to zip archives, determines whether or not they are -# functionally identical. Returns true if they are, false if they differ in -# some substantial way, and undef if an error occurs. If the zip files -# differ, diagnostic messages are printed indicating how they differ. -# -# Zip files will differ if any of the members are different as defined by -# readZipCRCs, which consider CRCs, sizes, and file types as stored in the -# file header. Timestamps are not considered. Zip files also differ if one -# file contains members that the other one does not. $gOnlyOne has no -# effect on this behavior. -sub compareZipArchives($$) { - my ($zip1, $zip2); - ($zip1, $zip2) = @_; - - my ($CRCHash1, $CRCHash2); - if (!defined($CRCHash1 = readZipCRCs($zip1))) { - # readZipCRCs printed an error. - return undef; - } - if (!defined($CRCHash2 = readZipCRCs($zip2))) { - # readZipCRCs printed an error. - return undef; - } - - my (@diffCRCs, @onlyInZip1); - @diffCRCs = (); - @onlyInZip1 = (); - - my ($memberName); - foreach $memberName (keys(%$CRCHash1)) { - if (!exists($$CRCHash2{$memberName})) { - # The member is present in $zip1 but not $zip2. - push(@onlyInZip1, $memberName); - } - elsif ($$CRCHash1{$memberName} ne $$CRCHash2{$memberName}) { - # The member is present in both archives but its CRC or some other - # other critical attribute isn't identical. - push(@diffCRCs, $memberName); - } - delete($$CRCHash2{$memberName}); - } - - # If any members remain in %CRCHash2, it's because they're not present - # in $zip1. - my (@onlyInZip2); - @onlyInZip2 = keys(%$CRCHash2); - - if (scalar(@onlyInZip1) + scalar(@onlyInZip2) + scalar(@diffCRCs)) { - complain(1, 'compareZipArchives: zip archives differ:', - $zip1, - $zip2); - if (scalar(@onlyInZip1)) { - complain(1, 'compareZipArchives: members only in former:', - @onlyInZip1); - } - if (scalar(@onlyInZip2)) { - complain(1, 'compareZipArchives: members only in latter:', - @onlyInZip2); - } - if (scalar(@diffCRCs)) { - complain(1, 'compareZipArchives: members differ:', - @diffCRCs); - } - return 0; - } - - return 1; -} - -# complain($severity, $message, @list) -# -# Prints $message to stderr if $gVerbosity allows it for severity level -# $severity. @list is a list of words that will be shell-escaped and printed -# after $message, one per line, intended to be used, for example, to list -# arguments to a call that failed. -# -# Expected severity levels are 1 for hard errors and 2 for non-fatal warnings. -# -# Always returns false as a convenience, so callers can return complain's -# return value when it is used to signal errors. -sub complain($$@) { - my ($severity, $message, @list); - ($severity, $message, @list) = @_; - - if ($gVerbosity >= $severity) { - print STDERR ($0.': '.$message."\n"); - - my ($item); - while ($item = shift(@list)) { - print STDERR (' '.(argumentEscape($item))[0]. - (scalar(@list)?',':'')."\n"); - } - } - - return 0; -} - -# copyIfIdentical($source1, $source2, $target) -# -# $source1 and $source2 are FileAttrCache objects that are compared, and if -# identical, copied to path string $target. The comparison is initially -# done as a byte-for-byte comparison, but if the files differ and appear to -# be zip archives, compareZipArchives is called to determine whether -# files that are not byte-for-byte identical are equivalent archives. -# -# Returns true on success, false for files that are not identical or -# equivalent archives, and undef if an error occurs. -# -# One of $source1 and $source2 is permitted to be undef. In this event, -# whichever source is defined is copied directly to $target without performing -# any comparisons. This enables the $gOnlyOne = 'copy' mode, which is -# driven by makeUniversalDirectory and makeUniversalInternal. -sub copyIfIdentical($$$) { - my ($source1, $source2, $target); - ($source1, $source2, $target) = @_; - - if (!defined($source1)) { - # If there's only one source file, make it the first file. Order - # isn't important here, and this makes it possible to use - # defined($source2) as the switch, and to always copy from $source1. - $source1 = $source2; - $source2 = undef; - } - - if (defined($source2)) { - # Only do the comparisons if there are two source files. If there's - # only one source file, skip the comparisons and go straight to the - # copy operation. - if ($gVerbosity >= 3 || $gDryRun) { - print('cmp -s '. - join(' ',argumentEscape($source1->path(), $source2->path()))."\n"); - } - my ($comparison); - if (!defined($comparison = compare($source1->path(), $source2->path())) || - $comparison == -1) { - return complain(1, 'copyIfIdentical: compare: '.$!.' while comparing:', - $source1->path(), - $source2->path()); - } - elsif ($comparison != 0) { - my ($zip1, $zip2); - if (defined($zip1 = $source1->isZip()) && - defined($zip2 = $source2->isZip()) && - $zip1 && $zip2) { - my ($zipComparison); - if (!defined($zipComparison = compareZipArchives($source1->path(), - $source2->path)) || - !$zipComparison) { - # An error occurred or the zip files aren't sufficiently identical. - # compareZipArchives will have printed an error message. - return 0; - } - # The zip files were compared successfully, and they both contain - # all of the same members, and all of their members' CRCs are - # identical. For the purposes of this script, the zip files can be - # treated as identical, so reset $comparison. - $comparison = 0; - } - } - if ($comparison != 0) { - return complain(1, 'copyIfIdentical: files differ:', - $source1->path(), - $source2->path()); - } - } - - if ($gVerbosity >= 3 || $gDryRun) { - print('cp '. - join(' ',argumentEscape($source1->path(), $target))."\n"); - } - - if (!$gDryRun) { - my ($isExecutable); - - # Set the execute bits (as allowed by the umask) on the new file if any - # execute bit is set on either old file. - $isExecutable = $source1->lIsExecutable() || - (defined($source2) && $source2->lIsExecutable()); - - if (!createUniqueFile($target, $isExecutable ? 0777 : 0666)) { - # createUniqueFile printed an error. - return 0; - } - - if (!copy($source1->path(), $target)) { - complain(1, 'copyIfIdentical: copy: '.$!.' while copying', - $source1->path(), - $target); - unlink($target); - return 0; - } - } - - return 1; -} - -# slurp($file) -# -# Read the contents of $file into an array and return it. -# Returns undef on error. -sub slurp($) { - my $file = $_[0]; - open FILE, $file or return undef; - my @lines = ; - close FILE; - return @lines; -} - -# get_sorted($file) -# Get the sorted lines of a file as a list, normalizing a newline on the last line if necessary. -sub get_sorted($) { - my ($file) = @_; - my @lines = slurp($file); - my $lastline = $lines[-1]; - if (!($lastline =~ /\n/)) { - $lines[-1] = $lastline . "\n"; - } - return sort(@lines); -} - -# compare_sorted($file1, $file2) -# -# Read the contents of both files into arrays, sort the arrays, -# and then compare the two arrays for equality. -# -# Returns 0 if the sorted array contents are equal, or 1 if not. -# Returns undef on error. -sub compare_sorted($$) { - my ($file1, $file2) = @_; - my @lines1 = get_sorted($file1); - my @lines2 = get_sorted($file2); - - return undef if !@lines1 || !@lines2; - return 1 unless scalar @lines1 == scalar @lines2; - - for (my $i = 0; $i < scalar @lines1; $i++) { - return 1 if $lines1[$i] ne $lines2[$i]; - } - return 0; -} - -# copyIfIdenticalWhenSorted($source1, $source2, $target) -# -# $source1 and $source2 are FileAttrCache objects that are compared, and if -# identical, copied to path string $target. The comparison is done by -# sorting the individual lines within the two files and comparing the results. -# -# Returns true on success, false for files that are not equivalent, -# and undef if an error occurs. -sub copyIfIdenticalWhenSorted($$$) { - my ($source1, $source2, $target); - ($source1, $source2, $target) = @_; - - if ($gVerbosity >= 3 || $gDryRun) { - print('cmp -s '. - join(' ',argumentEscape($source1->path(), $source2->path()))."\n"); - } - my ($comparison); - if (!defined($comparison = compare_sorted($source1->path(), - $source2->path())) || - $comparison == -1) { - return complain(1, 'copyIfIdenticalWhenSorted: compare: '.$! - .' while comparing:', - $source1->path(), - $source2->path()); - } - if ($comparison != 0) { - return complain(1, 'copyIfIdenticalWhenSorted: files differ:', - $source1->path(), - $source2->path()); - } - - if ($gVerbosity >= 3 || $gDryRun) { - print('cp '. - join(' ',argumentEscape($source1->path(), $target))."\n"); - } - - if (!$gDryRun) { - my ($isExecutable); - - # Set the execute bits (as allowed by the umask) on the new file if any - # execute bit is set on either old file. - $isExecutable = $source1->lIsExecutable() || - (defined($source2) && $source2->lIsExecutable()); - - if (!createUniqueFile($target, $isExecutable ? 0777 : 0666)) { - # createUniqueFile printed an error. - return 0; - } - - if (!copy($source1->path(), $target)) { - complain(1, 'copyIfIdenticalWhenSorted: copy: '.$! - .' while copying', - $source1->path(), - $target); - unlink($target); - return 0; - } - } - - return 1; -} - -# createUniqueFile($path, $mode) -# -# Creates a new plain empty file at pathname $path, provided it does not -# yet exist. $mode is used as the file mode. The actual file's mode will -# be modified by the effective umask. Returns false if the file could -# not be created, setting $! to the error. An error message is printed -# in the event of failure. -sub createUniqueFile($$) { - my ($path, $mode); - ($path, $mode) = @_; - - my ($fh); - if (!sysopen($fh, $path, O_WRONLY | O_CREAT | O_EXCL, $mode)) { - return complain(1, 'createUniqueFile: open: '.$!.' for:', - $path); - } - close($fh); - - return 1; -} - -# makeUniversal($pathPPC, $pathX86, $pathTarget) -# -# The top-level call. $pathPPC, $pathX86, and $pathTarget are strings -# identifying the ppc and x86 files or directories to merge and the location -# to merge them to. Returns false on failure and true on success. -sub makeUniversal($$$) { - my ($pathTarget, $pathPPC, $pathX86); - ($pathPPC, $pathX86, $pathTarget) = @_; - - my ($filePPC, $fileX86); - $filePPC = FileAttrCache->new($pathPPC); - $fileX86 = FileAttrCache->new($pathX86); - - return makeUniversalInternal(1, $filePPC, $fileX86, $pathTarget); -} - -# makeUniversalDirectory($dirPPC, $dirX86, $dirTarget) -# -# This is part of the heart of recursion. $dirPPC and $dirX86 are -# FileAttrCache objects designating the source ppc and x86 directories to -# merge into a universal directory at $dirTarget, a string. For each file -# in $dirPPC and $dirX86, makeUniversalInternal is called. -# makeUniversalInternal will call back into makeUniversalDirectory for -# directories, thus completing the recursion. If a failure is encountered -# in ths function or in makeUniversalInternal or anything that it calls, -# false is returned, otherwise, true is returned. -# -# If there are files present in one source directory but not both, the -# value of $gOnlyOne controls the behavior. If $gOnlyOne is 'copy', the -# single source file is copied into $pathTarget. If it is 'skip', it is -# skipped. If it is 'fail', such files will trigger makeUniversalDirectory -# to fail. -# -# If either source directory is undef, it is treated as having no files. -# This facilitates deep recursion when entire directories are only present -# in one source when $gOnlyOne = 'copy'. -sub makeUniversalDirectory($$$) { - my ($dirPPC, $dirX86, $dirTarget); - ($dirPPC, $dirX86, $dirTarget) = @_; - - my ($dh, @filesPPC, @filesX86); - - @filesPPC = (); - if (defined($dirPPC)) { - if (!opendir($dh, $dirPPC->path())) { - return complain(1, 'makeUniversalDirectory: opendir ppc: '.$!.' for:', - $dirPPC->path()); - } - @filesPPC = readdir($dh); - closedir($dh); - } - - @filesX86 = (); - if (defined($dirX86)) { - if (!opendir($dh, $dirX86->path())) { - return complain(1, 'makeUniversalDirectory: opendir x86: '.$!.' for:', - $dirX86->path()); - } - @filesX86 = readdir($dh); - closedir($dh); - } - - my (%common, $file, %onlyPPC, %onlyX86); - - %onlyPPC = (); - foreach $file (@filesPPC) { - if ($file eq '.' || $file eq '..') { - next; - } - $onlyPPC{$file}=1; - } - - %common = (); - %onlyX86 = (); - foreach $file (@filesX86) { - if ($file eq '.' || $file eq '..') { - next; - } - if ($onlyPPC{$file}) { - delete $onlyPPC{$file}; - $common{$file}=1; - } - else { - $onlyX86{$file}=1; - } - } - - # First, handle files common to both. - foreach $file (sort(keys(%common))) { - if (!makeUniversalInternal(0, - FileAttrCache->new($dirPPC->path().'/'.$file), - FileAttrCache->new($dirX86->path().'/'.$file), - $dirTarget.'/'.$file)) { - # makeUniversalInternal will have printed an error. - return 0; - } - } - - # Handle files found only in a single directory here. There are three - # options, dictated by $gOnlyOne: fail if files are only present in - # one directory, skip any files only present in one directory, or copy - # these files straight over to the target directory. In any event, - # a message will be printed indicating that the file trees don't match - # exactly. - if (keys(%onlyPPC)) { - complain(($gOnlyOne eq 'fail' ? 1 : 2), - ($gOnlyOne ne 'fail' ? 'warning: ' : ''). - 'makeUniversalDirectory: only in ppc '. - (argumentEscape($dirPPC->path()))[0].':', - argumentEscape(keys(%onlyPPC))); - } - - if (keys(%onlyX86)) { - complain(($gOnlyOne eq 'fail' ? 1 : 2), - ($gOnlyOne ne 'fail' ? 'warning: ' : ''). - 'makeUniversalDirectory: only in x86 '. - (argumentEscape($dirX86->path()))[0].':', - argumentEscape(keys(%onlyX86))); - } - - if ($gOnlyOne eq 'fail' && (keys(%onlyPPC) || keys(%onlyX86))) { - # Error message(s) printed above. - return 0; - } - - if ($gOnlyOne eq 'copy') { - foreach $file (sort(keys(%onlyPPC))) { - if (!makeUniversalInternal(0, - FileAttrCache->new($dirPPC->path().'/'.$file), - undef, - $dirTarget.'/'.$file)) { - # makeUniversalInternal will have printed an error. - return 0; - } - } - - foreach $file (sort(keys(%onlyX86))) { - if (!makeUniversalInternal(0, - undef, - FileAttrCache->new($dirX86->path().'/'.$file), - $dirTarget.'/'.$file)) { - # makeUniversalInternal will have printed an error. - return 0; - } - } - } - - return 1; -} - -# makeUniversalFile($sourcePPC, $sourceX86, $targetPath) -# -# Creates a universal file at pathname $targetPath based on a ppc image at -# $sourcePPC and an x86 image at $sourceX86. $sourcePPC and $sourceX86 are -# both FileAttrCache objects. Returns true on success and false on failure. -# On failure, diagnostics will be printed to stderr. -# -# The source files may be either thin Mach-O images of the appropriate -# architecture, or fat Mach-O files that contain images of the appropriate -# architecture. -# -# This function wraps the lipo utility, see lipo(1). -sub makeUniversalFile($$$) { - my ($sourcePPC, $sourceX86, $targetPath, @tempThinFiles, $thinPPC, $thinX86); - ($sourcePPC, $sourceX86, $targetPath) = @_; - $thinPPC = $sourcePPC; - $thinX86 = $sourceX86; - - @tempThinFiles = (); - - # The source files might already be fat. They should be thinned out to only - # contain a single architecture. - - my ($isFatPPC, $isFatX86); - - if(!defined($isFatPPC = $sourcePPC->isFat())) { - # isFat printed its own error - return 0; - } - elsif($isFatPPC) { - $thinPPC = FileAttrCache->new($targetPath.'.ppc'); - push(@tempThinFiles, $thinPPC->path()); - if (command($gConfig{'cmd_lipo'}, '-thin', 'ppc', - $sourcePPC->path(), '-output', $thinPPC->path()) != 0) { - unlink(@tempThinFiles); - return complain(1, 'lipo thin ppc failed for:', - $sourcePPC->path(), - $thinPPC->path()); - } - } - - if(!defined($isFatX86 = $sourceX86->isFat())) { - # isFat printed its own error - unlink(@tempThinFiles); - return 0; - } - elsif($isFatX86) { - $thinX86 = FileAttrCache->new($targetPath.'.x86'); - push(@tempThinFiles, $thinX86->path()); - if (command($gConfig{'cmd_lipo'}, '-thin', 'i386', - $sourceX86->path(), '-output', $thinX86->path()) != 0) { - unlink(@tempThinFiles); - return complain(1, 'lipo thin x86 failed for:', - $sourceX86->path(), - $thinX86->path()); - } - } - - # The image for each architecture in the fat file will be aligned on - # a specific boundary, default 4096 bytes, see lipo(1) -segalign. - # Since there's no tail-padding, the fat file will consume the least - # space on disk if the image that comes last exceeds the segment size - # by the smallest amount. - # - # This saves an average of 1kB per fat file over the naive approach of - # always putting one architecture first: average savings is 2kB per - # file, but the naive approach would have gotten it right half of the - # time. - - my ($sizePPC, $sizeX86, $thinPPCForStat, $thinX86ForStat); - - if (!$gDryRun) { - $thinPPCForStat = $thinPPC; - $thinX86ForStat = $thinX86; - } - else { - # Normally, fat source files will have been converted into temporary - # thin files. During a dry run, that doesn't happen, so fake it up - # a little bit by always using the source file, fat or thin, for the - # stat. - $thinPPCForStat = $sourcePPC; - $thinX86ForStat = $sourceX86; - } - - if (!defined($sizePPC = $thinPPCForStat->statSize())) { - unlink(@tempThinFiles); - return complain(1, 'stat ppc: '.$!.' for:', - $thinPPCForStat->path()); - } - if (!defined($sizeX86 = $thinX86ForStat->statSize())) { - unlink(@tempThinFiles); - return complain(1, 'stat x86: '.$!.' for:', - $thinX86ForStat->path()); - } - - $sizePPC = $sizePPC % 4096; - $sizeX86 = $sizeX86 % 4096; - - my (@thinFiles); - - if ($sizePPC == 0) { - # PPC image ends on an alignment boundary, there will be no padding before - # starting the x86 image. - @thinFiles = ($thinPPC->path(), $thinX86->path()); - } - elsif ($sizeX86 == 0 || $sizeX86 > $sizePPC) { - # x86 image ends on an alignment boundary, there will be no padding before - # starting the PPC image, or the x86 image exceeds its alignment boundary - # by more than the PPC image, so there will be less padding if the x86 - # comes first. - @thinFiles = ($thinX86->path(), $thinPPC->path()); - } - else { - # PPC image exceeds its alignment boundary by more than the x86 image, so - # there will be less padding if the PPC comes first. - @thinFiles = ($thinPPC->path(), $thinX86->path()); - } - - my ($isExecutable); - $isExecutable = $sourcePPC->lIsExecutable() || - $sourceX86->lIsExecutable(); - - if (!$gDryRun) { - # Ensure that the file does not yet exist. - - # Set the execute bits (as allowed by the umask) on the new file if any - # execute bit is set on either old file. Yes, it is possible to have - # proper Mach-O files without x-bits: think object files (.o) and static - # archives (.a). - if (!createUniqueFile($targetPath, $isExecutable ? 0777 : 0666)) { - # createUniqueFile printed an error. - unlink(@tempThinFiles); - return 0; - } - } - - # Create the fat file. - if (command($gConfig{'cmd_lipo'}, '-create', @thinFiles, - '-output', $targetPath) != 0) { - unlink(@tempThinFiles, $targetPath); - return complain(1, 'lipo create fat failed for:', - @thinFiles, - $targetPath); - } - - unlink(@tempThinFiles); - - if (!$gDryRun) { - # lipo seems to think that it's free to set its own file modes that - # ignore the umask, which is bogus when the rest of this script - # respects the umask. - if (!chmod(($isExecutable ? 0777 : 0666) & ~umask(), $targetPath)) { - complain(1, 'makeUniversalFile: chmod: '.$!.' for', - $targetPath); - unlink($targetPath); - return 0; - } - } - - return 1; -} - -# makeUniversalInternal($isToplevel, $filePPC, $fileX86, $fileTargetPath) -# -# Given FileAttrCache objects $filePPC and $fileX86, compares filetypes -# and performs the appropriate action to produce a universal file at -# path string $fileTargetPath. $isToplevel should be true if this is -# the recursive base and false otherwise; this controls cleanup behavior -# (cleanup is only performed at the base, because cleanup itself is -# recursive). -# -# This handles regular files by determining whether they are Mach-O files -# and calling makeUniversalFile if so and copyIfIdentical otherwise. Symbolic -# links are handled directly in this function by ensuring that the source link -# targets are identical and creating a new link with the same target -# at $fileTargetPath. Directories are handled by calling -# makeUniversalDirectory. -# -# One of $filePPC and $fileX86 is permitted to be undef. In that case, -# the defined source file is copied directly to the target if a regular -# file, and symlinked appropriately if a symbolic link. This facilitates -# use of $gOnlyOne = 'copy', although no $gOnlyOne checks are made in this -# function, they are all handled in makeUniversalDirectory. -# -# Returns true on success. Returns false on failure, including failures -# in other functions called. -sub makeUniversalInternal($$$$) { - my ($filePPC, $fileTargetPath, $fileX86, $isToplevel); - ($isToplevel, $filePPC, $fileX86, $fileTargetPath) = @_; - - my ($typePPC, $typeX86); - if (defined($filePPC) && !defined($typePPC = $filePPC->lstatType())) { - return complain(1, 'makeUniversal: lstat ppc: '.$!.' for:', - $filePPC->path()); - } - if (defined($fileX86) && !defined($typeX86 = $fileX86->lstatType())) { - return complain(1, 'makeUniversal: lstat x86: '.$!.' for:', - $fileX86->path()); - } - - if (defined($filePPC) && defined($fileX86) && $typePPC != $typeX86) { - return complain(1, 'makeUniversal: incompatible types:', - $filePPC->path(), - $fileX86->path()); - } - - # $aSourceFile will contain a FileAttrCache object that will return - # the correct type data. It's used because it's possible for one of - # the two source files to be undefined (indicating a straight copy). - my ($aSourceFile); - if (defined($filePPC)) { - $aSourceFile = $filePPC; - } - else { - $aSourceFile = $fileX86; - } - - if ($aSourceFile->lIsDir()) { - if ($gVerbosity >= 3 || $gDryRun) { - print('mkdir '.(argumentEscape($fileTargetPath))[0]."\n"); - } - if (!$gDryRun && !mkdir($fileTargetPath)) { - return complain(1, 'makeUniversal: mkdir: '.$!.' for:', - $fileTargetPath); - } - - my ($rv); - - if (!($rv = makeUniversalDirectory($filePPC, $fileX86, $fileTargetPath))) { - # makeUniversalDirectory printed an error. - if ($isToplevel) { - command($gConfig{'cmd_rm'},'-rf','--',$fileTargetPath); - } - } - else { - # Touch the directory when leaving it. If unify is being run on an - # .app bundle, the .app might show up without an icon because the - # system might have found the .app before it was completely built. - # Touching it dirties it in LaunchServices' mind. - if ($gVerbosity >= 3) { - print('touch '.(argumentEscape($fileTargetPath))[0]."\n"); - } - utime(undef, undef, $fileTargetPath); - } - - return $rv; - } - elsif ($aSourceFile->lIsSymLink()) { - my ($linkPPC, $linkX86); - if (defined($filePPC) && !defined($linkPPC=readlink($filePPC->path()))) { - return complain(1, 'makeUniversal: readlink ppc: '.$!.' for:', - $filePPC->path()); - } - if (defined($fileX86) && !defined($linkX86=readlink($fileX86->path()))) { - return complain(1, 'makeUniversal: readlink x86: '.$!.' for:', - $fileX86->path()); - } - if (defined($filePPC) && defined($fileX86) && $linkPPC ne $linkX86) { - return complain(1, 'makeUniversal: symbolic links differ:', - $filePPC->path(), - $fileX86->path()); - } - - # $aLink here serves the same purpose as $aSourceFile in the enclosing - # block: it refers to the target of the symbolic link, whether there - # is one valid source or two. - my ($aLink); - if (defined($linkPPC)) { - $aLink = $linkPPC; - } - else { - $aLink = $linkX86; - } - - if ($gVerbosity >= 3 || $gDryRun) { - print('ln -s '. - join(' ',argumentEscape($aLink, $fileTargetPath))."\n"); - } - if (!$gDryRun && !symlink($aLink, $fileTargetPath)) { - return complain(1, 'makeUniversal: symlink: '.$!.' for:', - $aLink, - $fileTargetPath); - } - - return 1; - } - elsif($aSourceFile->lIsRegularFile()) { - my ($machPPC, $machX86, $fileName); - if (!defined($filePPC) || !defined($fileX86)) { - # One of the source files isn't present. The right thing to do is - # to just copy what does exist straight over, so skip Mach-O checks. - $machPPC = 0; - $machX86 = 0; - if (defined($filePPC)) { - $fileName = $filePPC; - } elsif (defined($fileX86)) { - $fileName = $fileX86; - } else { - complain(1, "The file must exist in at least one directory"); - exit(1); - } - } - else { - # both files exist, pick the name of one. - $fileName = $fileX86; - if (!defined($machPPC=$filePPC->isMachO())) { - return complain(1, 'makeUniversal: isFileMachO ppc failed for:', - $filePPC->path()); - } - if (!defined($machX86=$fileX86->isMachO())) { - return complain(1, 'makeUniversal: isFileMachO x86 failed for:', - $fileX86->path()); - } - } - - if ($machPPC != $machX86) { - return complain(1, 'makeUniversal: variant Mach-O attributes:', - $filePPC->path(), - $fileX86->path()); - } - - if ($machPPC) { - # makeUniversalFile will print an error if it fails. - return makeUniversalFile($filePPC, $fileX86, $fileTargetPath); - } - - if (grep { $fileName->path() =~ m/$_/; } @gSortMatches) { - # Regular files, but should be compared with sorting first. - # copyIfIdenticalWhenSorted will print an error if it fails. - return copyIfIdenticalWhenSorted($filePPC, $fileX86, $fileTargetPath); - } - - # Regular file. copyIfIdentical will print an error if it fails. - return copyIfIdentical($filePPC, $fileX86, $fileTargetPath); - } - - # Special file, don't know how to handle. - return complain(1, 'makeUniversal: cannot handle special file:', - $filePPC->path(), - $fileX86->path()); -} - -# usage() -# -# Give the user a hand. -sub usage() { - print STDERR ( -"usage: unify \n". -" [--dry-run] (print what would be done)\n". -" [--only-one ] (skip, copy, fail; default=copy)\n". -" [--verbosity ] (0, 1, 2, 3; default=2)\n"); - return; -} - -# readZipCRCs($zipFile) -# -# $zipFile is the pathname to a zip file whose directory will be read. -# A reference to a hash is returned, with the member pathnames from the -# zip file as keys, and reasonably unique identifiers as values. The -# format of the values is not specified exactly, but does include the -# member CRCs and sizes and differentiates between files and directories. -# It specifically does not distinguish between modification times. On -# failure, prints a message and returns undef. -sub readZipCRCs($) { - my ($zipFile); - ($zipFile) = @_; - - my ($ze, $zip); - $zip = Archive::Zip->new(); - - if (($ze = $zip->read($zipFile)) != AZ_OK) { - complain(1, 'readZipCRCs: read error '.$ze.' for:', - $zipFile); - return undef; - } - - my ($member, %memberCRCs, @memberList); - %memberCRCs = (); - @memberList = $zip->members(); - - foreach $member (@memberList) { - # Take a few of the attributes that identify the file and stuff them into - # the members hash. Directories will show up with size 0 and crc32 0, - # so isDirectory() is used to distinguish them from empty files. - $memberCRCs{$member->fileName()} = join(',', $member->isDirectory() ? 1 : 0, - $member->uncompressedSize(), - $member->crc32String()); - } - - return {%memberCRCs}; -} - -{ - # FileAttrCache allows various attributes about a file to be cached - # so that if they are needed again after first use, no system calls - # will be made and the program won't need to hit the disk. - - package FileAttrCache; - - # from /usr/include/mach-o/loader.h - use constant MH_MAGIC => 0xfeedface; - use constant MH_CIGAM => 0xcefaedfe; - use constant MH_MAGIC_64 => 0xfeedfacf; - use constant MH_CIGAM_64 => 0xcffaedfe; - - use Fcntl(':DEFAULT', ':mode'); - - # FileAttrCache->new($path) - # - # Creates a new FileAttrCache object for the file at path $path and - # returns it. The cache is not primed at creation time, values are - # fetched lazily as they are needed. - sub new($$) { - my ($class, $path, $proto, $this); - ($proto, $path) = @_; - if (!($class = ref($proto))) { - $class = $proto; - } - $this = { - 'path' => $path, - 'lstat' => undef, - 'lstatErrno' => 0, - 'lstatInit' => 0, - 'magic' => undef, - 'magic2' => undef, - 'magicErrno' => 0, - 'magicErrMsg' => undef, - 'magicInit' => 0, - 'stat' => undef, - 'statErrno' => 0, - 'statInit' => 0, - }; - bless($this, $class); - return($this); - } - - # $FileAttrCache->isFat() - # - # Returns true if the file is a fat Mach-O file, false if it's not, and - # undef if an error occurs. See /usr/include/mach-o/fat.h. - sub isFat($) { - my ($magic, $magic2, $this); - ($this) = @_; - - # magic() caches, there's no separate cache because isFat() doesn't hit - # the disk other than by calling magic(). - - if (!defined($magic = $this->magic())) { - return undef; - } - $magic2 = $this->magic2(); - - # We have to sanity check the second four bytes, because Java class - # files use the same magic number as Mach-O fat binaries. - # This logic is adapted from file(1), which says that Mach-O uses - # these bytes to count the number of architectures within, while - # Java uses it for a version number. Conveniently, there are only - # 18 labelled Mach-O architectures, and Java's first released - # class format used the version 43.0. - if ($magic == 0xcafebabe && $magic2 < 20) { - return 1; - } - - return 0; - } - - # $FileAttrCache->isMachO() - # - # Returns true if the file is a Mach-O image (including a fat file), false - # if it's not, and undef if an error occurs. See - # /usr/include/mach-o/loader.h and /usr/include/mach-o/fat.h. - sub isMachO($) { - my ($magic, $this); - ($this) = @_; - - # magic() caches, there's no separate cache because isMachO() doesn't hit - # the disk other than by calling magic(). - - if (!defined($magic = $this->magic())) { - return undef; - } - - # Accept Mach-O fat files or Mach-O thin files of either endianness. - if ($magic == MH_MAGIC || - $magic == MH_CIGAM || - $magic == MH_MAGIC_64 || - $magic == MH_CIGAM_64 || - $this->isFat()) { - return 1; - } - - return 0; - } - - # $FileAttrCache->isZip() - # - # Returns true if the file is a zip file, false if it's not, and undef if - # an error occurs. See http://www.pkware.com/business_and_developers/developer/popups/appnote.txt . - sub isZip($) { - my ($magic, $this); - ($this) = @_; - - # magic() caches, there's no separate cache because isFat() doesn't hit - # the disk other than by calling magic(). - - if (!defined($magic = $this->magic())) { - return undef; - } - - if ($magic == 0x504b0304) { - return 1; - } - - return 0; - } - - # $FileAttrCache->lIsExecutable() - # - # Wraps $FileAttrCache->lstat(), returning true if the file is has any, - # execute bit set, false if none are set, or undef if an error occurs. - # On error, $! is set to lstat's errno. - sub lIsExecutable($) { - my ($mode, $this); - ($this) = @_; - - if (!defined($mode = $this->lstatMode())) { - return undef; - } - - return $mode & (S_IXUSR | S_IXGRP | S_IXOTH); - } - - # $FileAttrCache->lIsDir() - # - # Wraps $FileAttrCache->lstat(), returning true if the file is a directory, - # false if it isn't, or undef if an error occurs. Because lstat is used, - # this will return false even if the file is a symlink pointing to a - # directory. On error, $! is set to lstat's errno. - sub lIsDir($) { - my ($type, $this); - ($this) = @_; - - if (!defined($type = $this->lstatType())) { - return undef; - } - - return S_ISDIR($type); - } - - # $FileAttrCache->lIsRegularFile() - # - # Wraps $FileAttrCache->lstat(), returning true if the file is a regular, - # file, false if it isn't, or undef if an error occurs. Because lstat is - # used, this will return false even if the file is a symlink pointing to a - # regular file. On error, $! is set to lstat's errno. - sub lIsRegularFile($) { - my ($type, $this); - ($this) = @_; - - if (!defined($type = $this->lstatType())) { - return undef; - } - - return S_ISREG($type); - } - - # $FileAttrCache->lIsSymLink() - # - # Wraps $FileAttrCache->lstat(), returning true if the file is a symbolic, - # link, false if it isn't, or undef if an error occurs. On error, $! is - # set to lstat's errno. - sub lIsSymLink($) { - my ($type, $this); - ($this) = @_; - - if (!defined($type = $this->lstatType())) { - return undef; - } - - return S_ISLNK($type); - } - - # $FileAttrCache->lstat() - # - # Wraps the lstat system call, providing a cache to speed up multiple - # lstat calls for the same file. See lstat(2) and lstat in perlfunc(1). - sub lstat($) { - my (@stat, $this); - ($this) = @_; - - # Use the cached lstat result. - if ($$this{'lstatInit'}) { - if (defined($$this{'lstatErrno'})) { - $! = $$this{'lstatErrno'}; - } - return @{$$this{'lstat'}}; - } - $$this{'lstatInit'} = 1; - - if (!(@stat = CORE::lstat($$this{'path'}))) { - $$this{'lstatErrno'} = $!; - } - - $$this{'lstat'} = [@stat]; - return @stat; - } - - # $FileAttrCache->lstatMode() - # - # Wraps $FileAttrCache->lstat(), returning the mode bits from the st_mode - # field, or undef if an error occurs. On error, $! is set to lstat's - # errno. - sub lstatMode($) { - my (@stat, $this); - ($this) = @_; - - if (!(@stat = $this->lstat())) { - return undef; - } - - return S_IMODE($stat[2]); - } - - # $FileAttrCache->lstatType() - # - # Wraps $FileAttrCache->lstat(), returning the type bits from the st_mode - # field, or undef if an error occurs. On error, $! is set to lstat's - # errno. - sub lstatType($) { - my (@stat, $this); - ($this) = @_; - - if (!(@stat = $this->lstat())) { - return undef; - } - - return S_IFMT($stat[2]); - } - - # $FileAttrCache->magic() - # - # Returns the "magic number" for the file by reading its first four bytes - # as a big-endian unsigned 32-bit integer and returning the result. If an - # error occurs, returns undef and prints diagnostic messages to stderr. If - # the file is shorter than 32 bits, returns -1. A cache is provided to - # speed multiple magic calls for the same file. - sub magic($) { - my ($this); - ($this) = @_; - - # Use the cached magic result. - if ($$this{'magicInit'}) { - if (defined($$this{'magicErrno'})) { - if (defined($$this{'magicErrMsg'})) { - main::complain(1, 'FileAttrCache::magic: '.$$this{'magicErrMsg'}.' for:', - $$this{'path'}); - } - $! = $$this{'magicErrno'}; - } - return $$this{'magic'}; - } - - $$this{'magicInit'} = 1; - - my ($fh); - if (!sysopen($fh, $$this{'path'}, O_RDONLY)) { - $$this{'magicErrno'} = $!; - $$this{'magicErrMsg'} = 'open "'.$$this{'path'}.'": '.$!; - main::complain(1, 'FileAttrCache::magic: '.$$this{'magicErrMsg'}.' for:', - $$this{'path'}); - return undef; - } - - $! = 0; - my ($bytes, $magic, $bytes2, $magic2); - if (!defined($bytes = sysread($fh, $magic, 4))) { - $$this{'magicErrno'} = $!; - $$this{'magicErrMsg'} = 'read "'.$$this{'path'}.'": '.$!; - main::complain(1, 'FileAttrCache::magic: '.$$this{'magicErrMsg'}.' for:', - $$this{'path'}); - close($fh); - return undef; - } - else { - $bytes2 = sysread($fh, $magic2, 4); - } - - close($fh); - - if ($bytes != 4) { - # The file is too short, didn't read a magic number. This isn't really - # an error. Return an unlikely value. - $$this{'magic'} = -1; - $$this{'magic2'} = -1; - return -1; - } - if ($bytes2 != 4) { - # File is too short to read a second 4 bytes. - $magic2 = -1; - } - - $$this{'magic'} = unpack('N', $magic); - $$this{'magic2'} = unpack('N', $magic2); - return $$this{'magic'}; - } - - # $FileAttrCache->magic2() - # - # Returns the second four bytes of the file as a 32-bit little endian number. - # See magic(), above for more info. - sub magic2($) { - my ($this); - ($this) = @_; - - # we do the actual work (and cache it) in magic(). - if (!$$this{'magicInit'}) { - my $magic = $$this->magic(); - } - - return $$this{'magic2'}; - } - - # $FileAttrCache->path() - # - # Returns the file's pathname. - sub path($) { - my ($this); - ($this) = @_; - return $$this{'path'}; - } - - # $FileAttrCache->stat() - # - # Wraps the stat system call, providing a cache to speed up multiple - # stat calls for the same file. If lstat() has already been called and - # the file is not a symbolic link, the cached lstat() result will be used. - # See stat(2) and lstat in perlfunc(1). - sub stat($) { - my (@stat, $this); - ($this) = @_; - - # Use the cached stat result. - if ($$this{'statInit'}) { - if (defined($$this{'statErrno'})) { - $! = $$this{'statErrno'}; - } - return @{$$this{'stat'}}; - } - - $$this{'statInit'} = 1; - - # If lstat has already been called, and the file isn't a symbolic link, - # use the cached lstat result. - if ($$this{'lstatInit'} && !$$this{'lstatErrno'} && - !S_ISLNK(${$$this{'lstat'}}[2])) { - $$this{'stat'} = $$this{'lstat'}; - return @{$$this{'stat'}}; - } - - if (!(@stat = CORE::stat($$this{'path'}))) { - $$this{'statErrno'} = $!; - } - - $$this{'stat'} = [@stat]; - return @stat; - } - - # $FileAttrCache->statSize() - # - # Wraps $FileAttrCache->stat(), returning the st_size field, or undef - # undef if an error occurs. On error, $! is set to stat's errno. - sub statSize($) { - my (@stat, $this); - ($this) = @_; - - if (!(@stat = $this->lstat())) { - return undef; - } - - return $stat[7]; - } -} diff --git a/old-configure.in b/old-configure.in index a2a65ae282..91d53d06e2 100644 --- a/old-configure.in +++ b/old-configure.in @@ -96,12 +96,6 @@ case "$target" in ;; esac -case "$target" in -*-apple-darwin*) - MOZ_IOS_SDK - ;; -esac - AC_SUBST(ANDROID_SOURCE) AC_SUBST(ANDROID_PACKAGE_NAME) AC_SUBST(OBJCOPY) @@ -738,11 +732,6 @@ case "$host" in esac ;; -*-darwin*) - HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX -DXP_MACOSX" - HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O3}" - ;; - *-linux*|*-kfreebsd*-gnu|*-gnu*) HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX" HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O3}" @@ -779,76 +768,6 @@ dnl System overrides of the defaults for target dnl ======================================================== case "$target" in -*-darwin*) - MKSHLIB='$(CXX) $(CXXFLAGS) $(DSO_PIC_CFLAGS) $(DSO_LDOPTS) -o $@' - MKCSHLIB='$(CC) $(CFLAGS) $(DSO_PIC_CFLAGS) $(DSO_LDOPTS) -o $@' - MOZ_OPTIMIZE_FLAGS="-O3" - CXXFLAGS="$CXXFLAGS -stdlib=libc++" - DLL_SUFFIX=".dylib" - DSO_LDOPTS='' - STRIP_FLAGS="$STRIP_FLAGS -x -S" - # Ensure that if we're targeting iOS an SDK was provided. - AC_CACHE_CHECK(for iOS target, - ac_cv_ios_target, - [AC_TRY_COMPILE([#include -#if !(TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) -#error not iOS -#endif], - [], - ac_cv_ios_target="yes", - ac_cv_ios_target="no")]) - if test "$ac_cv_ios_target" = "yes" -a -z $MOZ_IOS; then - AC_MSG_ERROR([targeting iOS but not using an iOS SDK?]) - fi - if test -n "$MOZ_IOS"; then - direct_nspr_config=1 - else - # The ExceptionHandling framework is needed for Objective-C exception - # logging code in nsObjCExceptions.h. Currently we only use that in debug - # builds. - MOZ_DEBUG_LDFLAGS="$MOZ_DEBUG_LDFLAGS -framework ExceptionHandling"; - fi - - if test "x$lto_is_enabled" = "xyes"; then - echo "Skipping -dead_strip because lto is enabled." - dnl DTrace and -dead_strip don't interact well. See bug 403132. - dnl =================================================================== - elif test "x$enable_dtrace" = "xyes"; then - echo "Skipping -dead_strip because DTrace is enabled. See bug 403132." - else - dnl check for the presence of the -dead_strip linker flag - AC_MSG_CHECKING([for -dead_strip option to ld]) - _SAVE_LDFLAGS=$LDFLAGS - LDFLAGS="$LDFLAGS -Wl,-dead_strip" - AC_TRY_LINK(,[return 0;],_HAVE_DEAD_STRIP=1,_HAVE_DEAD_STRIP=) - if test -n "$_HAVE_DEAD_STRIP" ; then - AC_MSG_RESULT([yes]) - MOZ_OPTIMIZE_LDFLAGS="-Wl,-dead_strip" - else - AC_MSG_RESULT([no]) - fi - - LDFLAGS=$_SAVE_LDFLAGS - fi - - dnl With newer linkers we need to pass -allow_heap_execute because of - dnl Microsoft Silverlight (5.1.10411.0 at least). - AC_MSG_CHECKING([for -allow_heap_execute option to ld]) - _SAVE_LDFLAGS=$LDFLAGS - LDFLAGS="$LDFLAGS -Wl,-allow_heap_execute" - AC_TRY_LINK(,[return 0;],_HAVE_ALLOW_HEAP_EXECUTE=1, - _HAVE_ALLOW_HEAP_EXECUTE=) - if test -n "$_HAVE_ALLOW_HEAP_EXECUTE" ; then - AC_MSG_RESULT([yes]) - MOZ_ALLOW_HEAP_EXECUTE_FLAGS="-Wl,-allow_heap_execute" - else - AC_MSG_RESULT([no]) - fi - LDFLAGS=$_SAVE_LDFLAGS - - MOZ_FIX_LINK_PATHS="-Wl,-executable_path,${DIST}/bin" - ;; - *-*linux*) if test "$GNU_CC" -o "$GNU_CXX"; then MOZ_PGO_OPTIMIZE_FLAGS="-O3" @@ -1209,9 +1128,6 @@ case "$target" in *-linux*|*-kfreebsd*-gnu|*-gnu*) MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-Wl,--version-script -Wl,$(BUILD_TOOLS)/gnu-ld-scripts/components-version-script' ;; - *-darwin*) - MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-Wl,-exported_symbols_list -Wl,$(BUILD_TOOLS)/gnu-ld-scripts/components-export-list' - ;; *-mingw*) if test -n "$GNU_CC"; then MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-Wl,--version-script,$(BUILD_TOOLS)/gnu-ld-scripts/components-version-script' @@ -1246,8 +1162,6 @@ MOZ_CXX11 AC_LANG_C case "${OS_TARGET}" in -Darwin) - ;; *) STL_FLAGS="-I${DIST}/stl_wrappers" WRAP_STL_INCLUDES=1 @@ -1329,15 +1243,7 @@ dnl Checks for libraries. dnl ======================================================== AC_CHECK_LIB(c_r, gethostbyname_r) -dnl We don't want to link with libdl even if it's present on OS X, since -dnl it's not used and not part of the default installation. OS/2 has dlfcn -dnl in libc. -dnl We don't want to link against libm or libpthread on Darwin since -dnl they both are just symlinks to libSystem and explicitly linking -dnl against libSystem causes issues when debugging (see bug 299601). case $target in -*-darwin*) - ;; *) AC_SEARCH_LIBS(dlopen, dl, MOZ_CHECK_HEADER(dlfcn.h, @@ -1413,27 +1319,20 @@ AC_SUBST_LIST(XSS_LIBS) dnl ======================================================== dnl = pthread support -dnl = Start by checking whether the system support pthreads dnl ======================================================== -case "$target_os" in -darwin*) - MOZ_USE_PTHREADS=1 - ;; -*) - AC_CHECK_LIB(pthreads, pthread_create, - MOZ_USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads", - AC_CHECK_LIB(pthread, pthread_create, - MOZ_USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread", - AC_CHECK_LIB(c_r, pthread_create, - MOZ_USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r", - AC_CHECK_LIB(c, pthread_create, - MOZ_USE_PTHREADS=1 - ) + +AC_CHECK_LIB(pthreads, pthread_create, + MOZ_USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads", + AC_CHECK_LIB(pthread, pthread_create, + MOZ_USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread", + AC_CHECK_LIB(c_r, pthread_create, + MOZ_USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r", + AC_CHECK_LIB(c, pthread_create, + MOZ_USE_PTHREADS=1 ) ) ) - ;; -esac +) dnl ======================================================== dnl Check the command line for --with-pthreads @@ -1533,35 +1432,27 @@ AC_FUNC_MEMCMP AC_CHECK_FUNCS(stat64 lstat64 truncate64 statvfs64 statvfs statfs64 statfs getpagesize gmtime_r localtime_r arc4random arc4random_buf mallinfo gettid lchown setpriority strerror syscall) dnl check for clock_gettime(), the CLOCK_MONOTONIC clock -dnl avoid this on Darwin, since depending on your system config, we may think -dnl it exists but it really doesn't -case "$OS_TARGET" in -Darwin) - ;; -*) - AC_CACHE_CHECK(for clock_gettime(CLOCK_MONOTONIC), - ac_cv_clock_monotonic, - [for libs in "" -lrt; do - _SAVE_LIBS="$LIBS" - LIBS="$LIBS $libs" - AC_TRY_LINK([#include ], - [ struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); ], - ac_cv_clock_monotonic=$libs - LIBS="$_SAVE_LIBS" - break, - ac_cv_clock_monotonic=no) - LIBS="$_SAVE_LIBS" - done]) - if test "$ac_cv_clock_monotonic" != "no"; then - HAVE_CLOCK_MONOTONIC=1 - REALTIME_LIBS=$ac_cv_clock_monotonic - AC_DEFINE(HAVE_CLOCK_MONOTONIC) - AC_SUBST(HAVE_CLOCK_MONOTONIC) - AC_SUBST_LIST(REALTIME_LIBS) - fi - ;; -esac +AC_CACHE_CHECK(for clock_gettime(CLOCK_MONOTONIC), + ac_cv_clock_monotonic, + [for libs in "" -lrt; do + _SAVE_LIBS="$LIBS" + LIBS="$LIBS $libs" + AC_TRY_LINK([#include ], + [ struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); ], + ac_cv_clock_monotonic=$libs + LIBS="$_SAVE_LIBS" + break, + ac_cv_clock_monotonic=no) + LIBS="$_SAVE_LIBS" + done]) +if test "$ac_cv_clock_monotonic" != "no"; then + HAVE_CLOCK_MONOTONIC=1 + REALTIME_LIBS=$ac_cv_clock_monotonic + AC_DEFINE(HAVE_CLOCK_MONOTONIC) + AC_SUBST(HAVE_CLOCK_MONOTONIC) + AC_SUBST_LIST(REALTIME_LIBS) +fi AC_CACHE_CHECK(for pthread_cond_timedwait_monotonic_np, ac_cv_pthread_cond_timedwait_monotonic_np, @@ -1633,11 +1524,6 @@ AC_LANG_CPLUSPLUS ICONV_LIBS= -case $target_os in - darwin*|mingw*) - ;; - *) - AC_CHECK_LIB(c, iconv, [ICONV_LIBS=], AC_CHECK_LIB(iconv, iconv, [ICONV_LIBS="-liconv"], AC_CHECK_LIB(iconv, libiconv, [ICONV_LIBS="-liconv"]))) @@ -1685,9 +1571,6 @@ if test "$ac_cv_func_iconv" = "yes"; then fi LIBS=$_SAVE_LIBS - ;; -esac - AC_SUBST_LIST(ICONV_LIBS) AM_LANGINFO_CODESET @@ -1970,7 +1853,7 @@ dnl ======================================================== MOZ_ARG_HEADER(External Packages) case "$OS_TARGET" in -WINNT|Darwin|Android) +WINNT) MOZ_FOLD_LIBS=1 ;; *) @@ -2604,7 +2487,7 @@ dnl --enable-webrtc to override. Can disable for everything in dnl the master list above. if test -n "$MOZ_WEBRTC"; then case "$target" in - *-linux*|*-mingw*|*-darwin*|*-dragonfly*|*-freebsd*|*-netbsd*|*-openbsd*) + *-linux*|*-mingw*|*-dragonfly*|*-freebsd*|*-netbsd*|*-openbsd*) dnl Leave enabled ;; *) @@ -2750,11 +2633,11 @@ dnl = Client drawing in titlebar dnl ======================================================== if test -n "$MOZ_CAN_DRAW_IN_TITLEBAR"; then case "$OS_TARGET" in - WINNT|Darwin) + WINNT) AC_DEFINE(MOZ_CAN_DRAW_IN_TITLEBAR) ;; *) - AC_MSG_ERROR([Drawing in the titlebar is only supported on Windows and Macintosh targets]) + AC_MSG_ERROR([Drawing in the titlebar is only supported on Windows targets]) ;; esac fi @@ -2914,14 +2797,6 @@ if test -z "$MOZ_SYSTEM_LIBVPX"; then dnl See if we have assembly on this platform. case "$OS_ARCH:$CPU_ARCH" in - Darwin:x86) - VPX_USE_YASM=1 - VPX_X86_ASM=1 - ;; - Darwin:x86_64) - VPX_USE_YASM=1 - VPX_X86_ASM=1 - ;; WINNT:x86_64) VPX_USE_YASM=1 VPX_X86_ASM=1 @@ -3046,7 +2921,7 @@ dnl ======================================================== dnl If using Desktop Linux, ensure that the PA library is available case "$OS_TARGET" in -WINNT|Darwin|Android|OpenBSD) +WINNT) ;; *) MOZ_PULSEAUDIO=1 @@ -3326,11 +3201,6 @@ MOZ_ARG_ENABLE_BOOL(gamepad, if test "$MOZ_GAMEPAD"; then case "$OS_TARGET" in - Darwin) - if test -z "$MOZ_IOS"; then - MOZ_GAMEPAD_BACKEND=cocoa - fi - ;; WINNT) MOZ_GAMEPAD_BACKEND=windows ;; @@ -3378,14 +3248,6 @@ if test -n "$MOZ_LIBJPEG_TURBO" -a -n "$COMPILE_ENVIRONMENT"; then dnl Do we support libjpeg-turbo on this platform? case "$OS_ARCH:$CPU_ARCH" in - Darwin:x86) - LIBJPEG_TURBO_ASFLAGS="-DPIC -DMACHO" - ;; - Darwin:x86_64) - LIBJPEG_TURBO_ASFLAGS="-D__x86_64__ -DPIC -DMACHO" - ;; - Darwin:arm*) - ;; WINNT:x86) LIBJPEG_TURBO_ASFLAGS="-DPIC -DWIN32" ;; @@ -3465,9 +3327,6 @@ if test -n "$MOZ_LIBAV_FFT" -a -n "$COMPILE_ENVIRONMENT"; then AC_DEFINE(MOZ_LIBAV_FFT) dnl Do we support libav-fft on this platform? case "$OS_ARCH:$CPU_ARCH" in - Darwin:x86_64) - LIBAV_FFT_ASFLAGS="-D__x86_64__ -DPIC -DMACHO" - ;; WINNT:x86) LIBAV_FFT_ASFLAGS="-DPIC -DWIN32" ;; @@ -3878,11 +3737,11 @@ if test -n "$MOZ_DEBUG"; then fi case "${OS_TARGET}" in -Android|WINNT|Darwin) +WINNT) MOZ_GLUE_IN_PROGRAM= ;; *) - dnl On !Android !Windows !OSX, we only want to link executables against mozglue + dnl On !Windows, we only want to link executables against mozglue MOZ_GLUE_IN_PROGRAM=1 AC_DEFINE(MOZ_GLUE_IN_PROGRAM) ;; @@ -4852,13 +4711,6 @@ MOZ_ARG_DISABLE_BOOL(necko-wifi, if test "$MOZ_NECKO_WIFI"; then case "$OS_TARGET" in - Android) - ;; - Darwin) - if test -z "$MOZ_IOS"; then - NECKO_WIFI=1 - fi - ;; DragonFly|FreeBSD|WINNT) NECKO_WIFI=1 ;; From da2461fa57602a2009090ce33b0c7057e9b51257 Mon Sep 17 00:00:00 2001 From: athenian200 Date: Tue, 23 Mar 2021 02:14:40 -0500 Subject: [PATCH 3/9] Issue #1752 - Implement "prefers-color-scheme" as a user preference. This PR passes all current tests for this feature, and implements the "prefers-color-scheme" media query as an enumerated keyword that is controlled by an integer preference. Currently, the possible options are 0 to see a website's fallback code and essentially behave like this isn't implemented (our current behavior), 1 to express a preference for a light theme (the default for spec reasons), and 2 to express a preference for a dark theme. Over time, this list may expand to include other preferences like a preference for a sepia theme or something, and this leaves us prepared for that future. --- dom/base/nsGkAtomList.h | 1 + layout/style/nsCSSKeywordList.h | 2 ++ layout/style/nsMediaFeatures.cpp | 34 ++++++++++++++++++++++++++++++++ layout/style/nsStyleConsts.h | 4 ++++ modules/libpref/init/all.js | 4 ++++ 5 files changed, 45 insertions(+) diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h index 08f5c4fc1d..f56efc34d4 100644 --- a/dom/base/nsGkAtomList.h +++ b/dom/base/nsGkAtomList.h @@ -2240,6 +2240,7 @@ GK_ATOM(scrollbar_end_backward, "scrollbar-end-backward") GK_ATOM(scrollbar_end_forward, "scrollbar-end-forward") GK_ATOM(scrollbar_thumb_proportional, "scrollbar-thumb-proportional") GK_ATOM(overlay_scrollbars, "overlay-scrollbars") +GK_ATOM(prefers_color_scheme, "prefers-color-scheme") GK_ATOM(windows_accent_color_applies, "windows-accent-color-applies") GK_ATOM(windows_accent_color_is_dark, "windows-accent-color-is-dark") GK_ATOM(windows_default_theme, "windows-default-theme") diff --git a/layout/style/nsCSSKeywordList.h b/layout/style/nsCSSKeywordList.h index 689ff47eb6..be1691e629 100644 --- a/layout/style/nsCSSKeywordList.h +++ b/layout/style/nsCSSKeywordList.h @@ -224,6 +224,7 @@ CSS_KEY(crosshair, crosshair) CSS_KEY(currentcolor, currentcolor) CSS_KEY(cursive, cursive) CSS_KEY(cyclic, cyclic) +CSS_KEY(dark, dark) CSS_KEY(darken, darken) CSS_KEY(dashed, dashed) CSS_KEY(dense, dense) @@ -364,6 +365,7 @@ CSS_KEY(last baseline, last_baseline) // only used for DevTools auto-completion CSS_KEY(layout, layout) CSS_KEY(left, left) CSS_KEY(legacy, legacy) +CSS_KEY(light, light) CSS_KEY(lighten, lighten) CSS_KEY(lighter, lighter) CSS_KEY(line-through, line_through) diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp index 0c166ac21d..74f5c962c6 100644 --- a/layout/style/nsMediaFeatures.cpp +++ b/layout/style/nsMediaFeatures.cpp @@ -20,6 +20,7 @@ #include "nsIDocument.h" #include "nsIWidget.h" #include "nsContentUtils.h" +#include "mozilla/Preferences.h" #include "mozilla/StyleSheet.h" #include "mozilla/StyleSheetInlines.h" @@ -45,6 +46,12 @@ static const nsCSSProps::KTableEntry kDisplayModeKeywords[] = { { eCSSKeyword_UNKNOWN, -1 } }; +static const nsCSSProps::KTableEntry kPrefersColorSchemeKeywords[] = { + { eCSSKeyword_light, NS_STYLE_PREFERS_COLOR_SCHEME_LIGHT }, + { eCSSKeyword_dark, NS_STYLE_PREFERS_COLOR_SCHEME_DARK }, + { eCSSKeyword_UNKNOWN, -1 }, +}; + #ifdef XP_WIN struct WindowsThemeName { LookAndFeel::WindowsTheme id; @@ -457,6 +464,25 @@ GetOperatingSystemVersion(nsPresContext* aPresContext, const nsMediaFeature* aFe return NS_OK; } +static nsresult +GetPrefersColorScheme(nsPresContext* aPresContext, const nsMediaFeature* aFeature, + nsCSSValue& aResult) +{ + switch(Preferences::GetInt("browser.display.prefers_color_scheme", 1)) { + case 1: + aResult.SetIntValue(NS_STYLE_PREFERS_COLOR_SCHEME_LIGHT, + eCSSUnit_Enumerated); + break; + case 2: + aResult.SetIntValue(NS_STYLE_PREFERS_COLOR_SCHEME_DARK, + eCSSUnit_Enumerated); + break; + default: + aResult.Reset(); + } + return NS_OK; +} + static nsresult GetIsGlyph(nsPresContext* aPresContext, const nsMediaFeature* aFeature, nsCSSValue& aResult) @@ -556,6 +582,14 @@ nsMediaFeatures::features[] = { { nullptr }, GetMonochrome }, + { + &nsGkAtoms::prefers_color_scheme, + nsMediaFeature::eMinMaxNotAllowed, + nsMediaFeature::eEnumerated, + nsMediaFeature::eNoRequirements, + { kPrefersColorSchemeKeywords }, + GetPrefersColorScheme + }, { &nsGkAtoms::resolution, nsMediaFeature::eMinMaxAllowed, diff --git a/layout/style/nsStyleConsts.h b/layout/style/nsStyleConsts.h index 308a66647b..60377928b0 100644 --- a/layout/style/nsStyleConsts.h +++ b/layout/style/nsStyleConsts.h @@ -1306,6 +1306,10 @@ enum class StyleDisplay : uint8_t { #define NS_STYLE_DISPLAY_MODE_STANDALONE 2 #define NS_STYLE_DISPLAY_MODE_FULLSCREEN 3 +// prefers-color-scheme +#define NS_STYLE_PREFERS_COLOR_SCHEME_LIGHT 0 +#define NS_STYLE_PREFERS_COLOR_SCHEME_DARK 1 + } // namespace mozilla #endif /* nsStyleConsts_h___ */ diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index ba0351ede4..5e202cdc82 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -266,6 +266,10 @@ pref("browser.display.use_document_fonts", 1); // 0 = never, 1 = quick, 2 = al // 1 = always // 2 = never pref("browser.display.document_color_use", 0); +// 0 = feature disabled +// 1 = default: light theme preferred +// 2 = dark theme preferred +pref("browser.display.prefers_color_scheme", 1); pref("browser.display.use_system_colors", false); pref("browser.display.foreground_color", "#000000"); pref("browser.display.background_color", "#FFFFFF"); From 43ebe6d86f80efabcf3b87fcbc0a1b8e6f9bbf9e Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 24 Mar 2021 11:41:58 +0000 Subject: [PATCH 4/9] [docshell] Stop loading of the document if network load is stopped. After all, stop means stop. --- docshell/base/nsDocShell.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 0ceb70a304..c40fbd7a10 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -5449,11 +5449,19 @@ nsDocShell::Stop(uint32_t aStopFlags) } if (nsIWebNavigation::STOP_CONTENT & aStopFlags) { - // Stop the document loading + // Stop the document loading and animations if (mContentViewer) { nsCOMPtr cv = mContentViewer; cv->Stop(); } + } else if (nsIWebNavigation::STOP_NETWORK & aStopFlags) { + // Stop the document loading only + if (mContentViewer) { + RefPtr doc = mContentViewer->GetDocument(); + if (doc) { + doc->StopDocumentLoad(); + } + } } if (nsIWebNavigation::STOP_NETWORK & aStopFlags) { From bdfe49f178777d66c70325b3a588ac739b8e9334 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 24 Mar 2021 12:16:08 +0000 Subject: [PATCH 5/9] [WebGL] Only allow texture uploads from pixelbuffer if bound. Throw an error if it mismatches. --- dom/canvas/WebGLContextTextures.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/dom/canvas/WebGLContextTextures.cpp b/dom/canvas/WebGLContextTextures.cpp index 30716438f5..66138361ab 100644 --- a/dom/canvas/WebGLContextTextures.cpp +++ b/dom/canvas/WebGLContextTextures.cpp @@ -390,6 +390,16 @@ WebGLContext::TexImage(const char* funcName, uint8_t funcDims, GLenum rawTarget, if (!ValidateTexImageTarget(this, funcName, funcDims, rawTarget, &target, &tex)) return; + const bool isUploadFromPbo = bool(src.mPboOffset); + const bool isPboBound = bool(mBoundPixelUnpackBuffer); + if (isUploadFromPbo != isPboBound) { + SynthesizeGLError(LOCAL_GL_INVALID_OPERATION, + "Tex upload from %s but PIXEL_UNPACK_BUFFER %s bound.", + isUploadFromPbo ? "PBO" : "non-PBO", + isPboBound ? "was" : "was not"); + return; + } + const webgl::PackingInfo pi = {unpackFormat, unpackType}; tex->TexImage(funcName, target, level, internalFormat, width, height, depth, border, pi, src); @@ -407,6 +417,16 @@ WebGLContext::TexSubImage(const char* funcName, uint8_t funcDims, GLenum rawTarg if (!ValidateTexImageTarget(this, funcName, funcDims, rawTarget, &target, &tex)) return; + const bool isUploadFromPbo = bool(src.mPboOffset); + const bool isPboBound = bool(mBoundPixelUnpackBuffer); + if (isUploadFromPbo != isPboBound) { + SynthesizeGLError(LOCAL_GL_INVALID_OPERATION, + "Tex upload from %s but PIXEL_UNPACK_BUFFER %s bound.", + isUploadFromPbo ? "PBO" : "non-PBO", + isPboBound ? "was" : "was not"); + return; + } + const webgl::PackingInfo pi = {unpackFormat, unpackType}; tex->TexSubImage(funcName, target, level, xOffset, yOffset, zOffset, width, height, depth, pi, src); From cfadb0bc6fd72f4ba4f73c0ff6afe7ee6a7b495a Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 24 Mar 2021 18:04:20 +0000 Subject: [PATCH 6/9] [WebRTC] Apply port restrictions to peerconnections. --- .../src/peerconnection/PeerConnectionImpl.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp index f31e2edb35..3b4363a13c 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp @@ -17,6 +17,8 @@ #include "nss.h" #include "pk11pub.h" +#include "nsNetUtil.h" // for NS_CheckPortSafety + #include "nsNetCID.h" #include "nsIProperty.h" #include "nsIPropertyBag2.h" @@ -494,6 +496,13 @@ PeerConnectionConfiguration::Init(const RTCConfiguration& aSrc) return NS_OK; } +// list of known acceptable ports for webrtc +int16_t gGoodWebrtcPortList[] = { + 3478, // stun or turn + 5349, // stuns or turns + 0, // Sentinel value: This MUST be zero +}; + nsresult PeerConnectionConfiguration::AddIceServer(const RTCIceServer &aServer) { @@ -567,6 +576,21 @@ PeerConnectionConfiguration::AddIceServer(const RTCIceServer &aServer) if (port == -1) port = (isStuns || isTurns)? 5349 : 3478; + // First check the known good ports for webrtc + bool knownGoodPort = false; + for (int i = 0; !knownGoodPort && gGoodWebrtcPortList[i]; i++) { + if (port == gGoodWebrtcPortList[i]) { + knownGoodPort = true; + } + } + + // if not in the list of known good ports for webrtc, check + // the generic block list using NS_CheckPortSafety. + if (!knownGoodPort) { + rv = NS_CheckPortSafety(port, nullptr); + NS_ENSURE_SUCCESS(rv, rv); + } + if (isTurn || isTurns) { NS_ConvertUTF16toUTF8 credential(aServer.mCredential.Value()); NS_ConvertUTF16toUTF8 username(aServer.mUsername.Value()); From d88f98c22634b38a36ffb297a18ebbeb6d3c50f2 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 24 Mar 2021 09:58:48 +0000 Subject: [PATCH 7/9] [Basilisk] Don't try to force x-icon image type for search engine icon. If it's not actually an image, then throw a warning in the console and bail. --- .../basilisk/components/search/service/nsSearchService.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/application/basilisk/components/search/service/nsSearchService.js b/application/basilisk/components/search/service/nsSearchService.js index 100905150c..3cd2531006 100644 --- a/application/basilisk/components/search/service/nsSearchService.js +++ b/application/basilisk/components/search/service/nsSearchService.js @@ -1371,8 +1371,12 @@ Engine.prototype = { } let type = chan.contentType; - if (!type.startsWith("image/")) - type = "image/x-icon"; + if (!type.startsWith("image/")) { + console.warn( + "Search service: Unable to set icon, content type is not an image", + contentType); + return; + } let dataURL = "data:" + type + ";base64," + btoa(String.fromCharCode.apply(null, aByteArray)); From 0006a4612d2a5497012c378c1dd5f9fa2e58583f Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 16 Mar 2021 10:55:54 +0000 Subject: [PATCH 8/9] [Pale-Moon] Remove stray Android conditional --- application/palemoon/app/nsBrowserApp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/palemoon/app/nsBrowserApp.cpp b/application/palemoon/app/nsBrowserApp.cpp index faf82f710a..03cb1d867a 100644 --- a/application/palemoon/app/nsBrowserApp.cpp +++ b/application/palemoon/app/nsBrowserApp.cpp @@ -40,7 +40,7 @@ #include "mozilla/Telemetry.h" #include "mozilla/WindowsDllBlocklist.h" -#if !defined(MOZ_WIDGET_COCOA) && !defined(MOZ_WIDGET_ANDROID) +#if !defined(MOZ_WIDGET_COCOA) #define MOZ_BROWSER_CAN_BE_CONTENTPROC #include "../../ipc/contentproc/plugin-container.cpp" #endif From a984b1dd93a85041db2c84581e6e34af5b771dee Mon Sep 17 00:00:00 2001 From: Moonchild Date: Mon, 22 Mar 2021 12:02:28 +0000 Subject: [PATCH 9/9] [Pale-Moon] Issue #1865 - Remove XP_MACOSX conditional blocks. --- application/palemoon/app/nsBrowserApp.cpp | 21 --- application/palemoon/app/profile/palemoon.js | 45 ----- .../palemoon/base/content/aboutDialog.js | 6 - .../palemoon/base/content/aboutDialog.xul | 12 -- .../palemoon/base/content/autocomplete.xml | 24 +-- .../palemoon/base/content/baseMenuOverlay.xul | 36 ---- .../base/content/browser-fullScreen.js | 11 -- .../palemoon/base/content/browser-menubar.inc | 64 ------- .../palemoon/base/content/browser-places.js | 4 - .../palemoon/base/content/browser-sets.inc | 32 ---- .../base/content/browser-tabPreviews.js | 3 - .../base/content/browser-tabPreviews.xml | 4 - application/palemoon/base/content/browser.css | 10 - application/palemoon/base/content/browser.js | 176 ------------------ application/palemoon/base/content/browser.xul | 52 ------ .../palemoon/base/content/hiddenWindow.xul | 12 -- .../palemoon/base/content/nsContextMenu.js | 18 +- application/palemoon/base/content/sanitize.js | 4 - .../palemoon/base/content/tabbrowser.xml | 33 ---- .../palemoon/base/content/urlbarBindings.xml | 4 - .../palemoon/base/content/utilityOverlay.js | 8 - .../base/content/viewSourceOverlay.xul | 4 - application/palemoon/base/jar.mn | 11 -- .../palemoon/components/build/nsModule.cpp | 13 -- .../content/allDownloadsViewOverlay.xul | 5 - .../content/contentAreaDownloadsView.xul | 3 - .../components/downloads/content/download.xml | 8 - .../components/downloads/content/downloads.js | 4 - .../downloads/content/downloadsOverlay.xul | 5 - .../palemoon/components/feeds/FeedWriter.js | 11 -- .../palemoon/components/newtab/page.js | 6 - .../palemoon/components/nsBrowserGlue.js | 6 +- .../palemoon/components/pageinfo/pageInfo.xul | 12 -- .../places/content/browserPlacesViews.js | 28 --- .../places/content/downloadsViewOverlay.xul | 3 - .../places/content/history-panel.xul | 3 - .../components/places/content/menu.xml | 13 -- .../components/places/content/places.js | 21 --- .../components/places/content/places.xul | 51 ----- .../components/places/content/sidebarUtils.js | 4 - .../preferences/applicationManager.js | 5 - .../components/preferences/applications.js | 11 -- .../components/preferences/colors.xul | 7 - .../components/preferences/connection.xul | 4 - .../components/preferences/cookies.js | 6 +- .../components/preferences/cookies.xul | 2 - .../palemoon/components/preferences/fonts.xul | 3 - .../components/preferences/languages.xul | 3 - .../palemoon/components/preferences/main.xul | 5 - .../components/preferences/permissions.js | 6 +- .../components/preferences/preferences.xul | 14 -- .../content/aboutPrivateBrowsing.xhtml | 6 - .../components/search/content/search.xml | 2 - .../components/sessionstore/SessionStore.jsm | 12 -- .../content/aboutSessionRestore.js | 4 - .../components/shell/ShellService.jsm | 2 +- .../shell/content/setDesktopBackground.js | 52 ------ .../shell/content/setDesktopBackground.xul | 28 --- .../palemoon/installer/package-manifest.in | 37 ---- .../palemoon/installer/removed-files.in | 21 +-- 60 files changed, 9 insertions(+), 1011 deletions(-) diff --git a/application/palemoon/app/nsBrowserApp.cpp b/application/palemoon/app/nsBrowserApp.cpp index 03cb1d867a..bfe9a6f352 100644 --- a/application/palemoon/app/nsBrowserApp.cpp +++ b/application/palemoon/app/nsBrowserApp.cpp @@ -40,16 +40,11 @@ #include "mozilla/Telemetry.h" #include "mozilla/WindowsDllBlocklist.h" -#if !defined(MOZ_WIDGET_COCOA) #define MOZ_BROWSER_CAN_BE_CONTENTPROC #include "../../ipc/contentproc/plugin-container.cpp" -#endif using namespace mozilla; -#ifdef XP_MACOSX -#define kOSXResourcesFolder "Resources" -#endif #define kDesktopFolder "browser" static void Output(const char *fmt, ... ) @@ -236,9 +231,6 @@ static int do_main(int argc, char* argv[], char* envp[], nsIFile *xreDirectory) nsCOMPtr greDir; exeFile->GetParent(getter_AddRefs(greDir)); -#ifdef XP_MACOSX - greDir->SetNativeLeafName(NS_LITERAL_CSTRING(kOSXResourcesFolder)); -#endif nsCOMPtr appSubdir; greDir->Clone(getter_AddRefs(appSubdir)); appSubdir->Append(NS_LITERAL_STRING(kDesktopFolder)); @@ -317,10 +309,6 @@ InitXPCOMGlue(const char *argv0, nsIFile **xreDirectory) if (xreDirectory) { // chop XPCOM_DLL off exePath *lastSlash = '\0'; -#ifdef XP_MACOSX - lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]); - strcpy(lastSlash + 1, kOSXResourcesFolder); -#endif #ifdef XP_WIN rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), false, xreDirectory); @@ -385,14 +373,5 @@ int main(int argc, char* argv[], char* envp[]) NS_LogTerm(); -#ifdef XP_MACOSX - // Allow writes again. While we would like to catch writes from static - // destructors to allow early exits to use _exit, we know that there is - // at least one such write that we don't control (see bug 826029). For - // now we enable writes again and early exits will have to use exit instead - // of _exit. - XRE_StopLateWriteChecks(); -#endif - return result; } diff --git a/application/palemoon/app/profile/palemoon.js b/application/palemoon/app/profile/palemoon.js index 5b4648d130..bde0a28dff 100644 --- a/application/palemoon/app/profile/palemoon.js +++ b/application/palemoon/app/profile/palemoon.js @@ -16,10 +16,8 @@ # #ifdef XP_UNIX -#ifndef XP_MACOSX #define UNIX_BUT_NOT_MAC #endif -#endif pref("browser.chromeURL","chrome://browser/content/"); pref("browser.hiddenWindowChromeURL", "chrome://browser/content/hiddenWindow.xul"); @@ -427,13 +425,7 @@ pref("browser.link.open_newwindow.restriction", 2); // If true, this pref causes windows opened by window.open to be forced into new // tabs (rather than potentially opening separate windows, depending on // window.open arguments) when the browser is in fullscreen mode. -// We set this differently on Mac because the fullscreen implementation there is -// different. -#ifdef XP_MACOSX -pref("browser.link.open_newwindow.disabled_in_fullscreen", true); -#else pref("browser.link.open_newwindow.disabled_in_fullscreen", false); -#endif // Tabbed browser pref("browser.tabs.autoHide", false); @@ -588,13 +580,8 @@ pref("browser.gesture.swipe.left", "Browser:BackOrBackDuplicate"); pref("browser.gesture.swipe.right", "Browser:ForwardOrForwardDuplicate"); pref("browser.gesture.swipe.up", "cmd_scrollTop"); pref("browser.gesture.swipe.down", "cmd_scrollBottom"); -#ifdef XP_MACOSX -pref("browser.gesture.pinch.latched", true); -pref("browser.gesture.pinch.threshold", 150); -#else pref("browser.gesture.pinch.latched", false); pref("browser.gesture.pinch.threshold", 25); -#endif #ifdef XP_WIN // Enabled for touch input display zoom. pref("browser.gesture.pinch.out", "cmd_fullZoomEnlarge"); @@ -622,27 +609,9 @@ pref("browser.snapshots.limit", 0); // 2: Go back or go forward, in your history // 3: Zoom in or out // 4: Scroll contents with X and Y swapped -#ifdef XP_MACOSX -// On OS X, if the wheel has one axis only, shift+wheel comes through as a -// horizontal scroll event. Thus, we can't assign anything other than normal -// scrolling to shift+wheel. -pref("mousewheel.with_alt.action", 2); -pref("mousewheel.with_shift.action", 1); -// On MacOS X, control+wheel is typically handled by system and we don't -// receive the event. So, command key which is the main modifier key for -// acceleration is the best modifier for zoom-in/out. However, we should keep -// the control key setting for backward compatibility. -pref("mousewheel.with_meta.action", 3); // command key on Mac -// Disable control-/meta-modified horizontal mousewheel events, since -// those are used on Mac as part of modified swipe gestures (e.g. -// Left swipe+Cmd = go back in a new tab). -pref("mousewheel.with_control.action.override_x", 0); -pref("mousewheel.with_meta.action.override_x", 0); -#else pref("mousewheel.with_alt.action", 1); pref("mousewheel.with_shift.action", 2); pref("mousewheel.with_meta.action", 1); // win key on Win, Super/Hyper on Linux -#endif pref("mousewheel.with_control.action",3); pref("mousewheel.with_win.action", 1); @@ -709,11 +678,7 @@ pref("browser.preferences.instantApply", false); #else pref("browser.preferences.instantApply", true); #endif -#ifdef XP_MACOSX -pref("browser.preferences.animateFadeIn", true); -#else pref("browser.preferences.animateFadeIn", false); -#endif pref("browser.download.show_plugins_in_list", true); pref("browser.download.hide_plugins_without_extensions", true); @@ -965,19 +930,9 @@ pref("browser.bookmarks.editDialog.firstEditField", "namePicker"); pref("signon.startup.prompt", false); // Whether to use a panel that looks like an OS X sheet for customization -#ifdef XP_MACOSX -pref("toolbar.customization.usesheet", true); -#else pref("toolbar.customization.usesheet", false); -#endif -#ifdef XP_MACOSX -// On mac, the default pref is per-architecture -pref("dom.ipc.plugins.enabled.i386", true); -pref("dom.ipc.plugins.enabled.x86_64", true); -#else pref("dom.ipc.plugins.enabled", true); -#endif pref("browser.tabs.remote", false); diff --git a/application/palemoon/base/content/aboutDialog.js b/application/palemoon/base/content/aboutDialog.js index 4fdeab9a82..cce96f96d4 100644 --- a/application/palemoon/base/content/aboutDialog.js +++ b/application/palemoon/base/content/aboutDialog.js @@ -44,12 +44,6 @@ function init(aEvent) document.getElementById("aboutVersion").textContent += " (" + buildDate + ")"; } -#ifdef XP_MACOSX - // it may not be sized at this point, and we need its width to calculate its position - window.sizeToContent(); - window.moveTo((screen.availWidth / 2) - (window.outerWidth / 2), screen.availHeight / 5); -#endif - // get release notes URL from prefs var formatter = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"] .getService(Components.interfaces.nsIURLFormatter); diff --git a/application/palemoon/base/content/aboutDialog.xul b/application/palemoon/base/content/aboutDialog.xul index 6edfc21555..ceeef5dae4 100644 --- a/application/palemoon/base/content/aboutDialog.xul +++ b/application/palemoon/base/content/aboutDialog.xul @@ -15,20 +15,12 @@ %aboutDialogDTD; ]> -#ifdef XP_MACOSX - -#endif - @@ -83,8 +75,4 @@ - -#ifdef XP_MACOSX -#include browserMountPoints.inc -#endif diff --git a/application/palemoon/base/content/autocomplete.xml b/application/palemoon/base/content/autocomplete.xml index a9a4d9a831..b3250199dd 100644 --- a/application/palemoon/base/content/autocomplete.xml +++ b/application/palemoon/base/content/autocomplete.xml @@ -450,13 +450,8 @@ var cancel = false; // Catch any keys that could potentially move the caret. Ctrl can be - // used in combination with these keys on Windows and Linux; and Alt - // can be used on OS X, so make sure the unused one isn't used. -#ifdef XP_MACOSX - let metaKey = aEvent.ctrlKey; -#else + // used in combination with these keys on Windows and Linux. let metaKey = aEvent.altKey; -#endif if (!this.disableKeyNavigation && !metaKey) { switch (aEvent.keyCode) { case KeyEvent.DOM_VK_LEFT: @@ -494,11 +489,6 @@ cancel = this.mController.handleEscape(); break; case KeyEvent.DOM_VK_RETURN: -#ifdef XP_MACOSX - // Prevent the default action, since it will beep on Mac - if (aEvent.metaKey) - aEvent.preventDefault(); -#endif this.mEnterEvent = aEvent; if (this.mController.selection) { this._selectionDetails = { @@ -509,19 +499,9 @@ cancel = this.handleEnter(); break; case KeyEvent.DOM_VK_DELETE: -#ifdef XP_MACOSX - if (!aEvent.shiftKey) { - break; - } -#endif cancel = this.handleDelete(); break; case KeyEvent.DOM_VK_BACK_SPACE: -#ifdef XP_MACOSX - if (aEvent.shiftKey) { - cancel = this.handleDelete(); - } -#endif break; case KeyEvent.DOM_VK_DOWN: case KeyEvent.DOM_VK_UP: @@ -529,9 +509,7 @@ this.toggleHistoryPopup(); break; case KeyEvent.DOM_VK_F4: -#ifndef XP_MACOSX this.toggleHistoryPopup(); -#endif break; } diff --git a/application/palemoon/base/content/baseMenuOverlay.xul b/application/palemoon/base/content/baseMenuOverlay.xul index bccdec2650..d07c647fac 100644 --- a/application/palemoon/base/content/baseMenuOverlay.xul +++ b/application/palemoon/base/content/baseMenuOverlay.xul @@ -16,22 +16,6 @@