Skip to content

Commit

Permalink
base: Use BUILDFLAG for OS checking
Browse files Browse the repository at this point in the history
Use BUILDFLAG(IS_XXX) instead of defined(OS_XXX).

Generated by `os_buildflag_migration.py` (https://crrev.com/c/3311983).

R=thakis@chromium.org

Bug: 1234043
Test: No functionality change
Change-Id: If1c46447108fec5f71d26fbba2c900535d338ff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399769
Reviewed-by: Nico Weber <thakis@chromium.org>
Owners-Override: Nico Weber <thakis@chromium.org>
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960809}
  • Loading branch information
xhwang-chromium authored and Chromium LUCI CQ committed Jan 19, 2022
1 parent 805d745 commit 38e4ebb
Show file tree
Hide file tree
Showing 79 changed files with 542 additions and 522 deletions.
4 changes: 2 additions & 2 deletions base/atomicops.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef int32_t Atomic32;
#ifdef ARCH_CPU_64_BITS
// We need to be able to go between Atomic64 and AtomicWord implicitly. This
// means Atomic64 and AtomicWord should be the same type on 64-bit.
#if defined(__ILP32__) || defined(OS_NACL)
#if defined(__ILP32__) || BUILDFLAG(IS_NACL)
// NaCl's intptr_t is not actually 64-bits on 64-bit!
// http://code.google.com/p/nativeclient/issues/detail?id=1162
typedef int64_t Atomic64;
Expand Down Expand Up @@ -133,7 +133,7 @@ Atomic64 Acquire_Load(volatile const Atomic64* ptr);

// On some platforms we need additional declarations to make
// AtomicWord compatible with our other Atomic* types.
#if defined(OS_APPLE) || defined(OS_OPENBSD)
#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_OPENBSD)
#include "base/atomicops_internals_atomicword_compat.h"
#endif

Expand Down
9 changes: 5 additions & 4 deletions base/base_paths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "build/build_config.h"

namespace base {

Expand All @@ -19,26 +20,26 @@ bool PathProvider(int key, FilePath* result) {
return false;
*result = result->DirName();
return true;
#if !defined(OS_FUCHSIA)
#if !BUILDFLAG(IS_FUCHSIA)
case DIR_MODULE:
if (!PathService::Get(FILE_MODULE, result))
return false;
*result = result->DirName();
return true;
case DIR_ASSETS:
return PathService::Get(DIR_MODULE, result);
#endif // !defined(OS_FUCHSIA)
#endif // !BUILDFLAG(IS_FUCHSIA)
case DIR_TEMP:
return GetTempDir(result);
case DIR_HOME:
*result = GetHomeDir();
return true;
case DIR_GEN_TEST_DATA_ROOT:
#if !defined(OS_FUCHSIA)
#if !BUILDFLAG(IS_FUCHSIA)
// On most platforms, all build output is in the same directory, so
// use DIR_MODULE to get the path to the current binary.
return PathService::Get(DIR_MODULE, result);
#endif // !defined(OS_FUCHSIA)
#endif // !BUILDFLAG(IS_FUCHSIA)
case DIR_TEST_DATA: {
FilePath test_data_path;
if (!PathService::Get(DIR_SRC_TEST_DATA_ROOT, &test_data_path))
Expand Down
12 changes: 6 additions & 6 deletions base/base_paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

#include "build/build_config.h"

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
#include "base/base_paths_win.h"
#elif defined(OS_APPLE)
#elif BUILDFLAG(IS_APPLE)
#include "base/base_paths_mac.h"
#elif defined(OS_ANDROID)
#elif BUILDFLAG(IS_ANDROID)
#include "base/base_paths_android.h"
#endif

#if defined(OS_POSIX)
#if BUILDFLAG(IS_POSIX)
#include "base/base_paths_posix.h"
#endif

Expand All @@ -29,7 +29,7 @@ enum BasePathKey {

// The following refer to the current application.
FILE_EXE, // Path and filename of the current executable.
#if !defined(OS_FUCHSIA)
#if !BUILDFLAG(IS_FUCHSIA)
// Prefer keys (e.g., DIR_ASSETS) that are specific to the use case as the
// module location may not work as expected on some platforms. For this
// reason, this key is not defined on Fuchsia. See crbug.com/1263691 for
Expand All @@ -40,7 +40,7 @@ enum BasePathKey {
// example).
#endif
DIR_EXE, // Directory containing FILE_EXE.
#if !defined(OS_FUCHSIA)
#if !BUILDFLAG(IS_FUCHSIA)
// Prefer keys (e.g., DIR_ASSETS) that are specific to the use case as the
// module location may not work as expected on some platforms. For this
// reason, this key is not defined on Fuchsia. See crbug.com/1263691 for
Expand Down
14 changes: 7 additions & 7 deletions base/base_paths_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ bool PathProviderMac(int key, base::FilePath* result) {
case base::DIR_APP_DATA: {
bool success = base::mac::GetUserDirectory(NSApplicationSupportDirectory,
result);
#if defined(OS_IOS)
#if BUILDFLAG(IS_IOS)
// On IOS, this directory does not exist unless it is created explicitly.
if (success && !base::PathExists(*result))
success = base::CreateDirectory(*result);
#endif // defined(OS_IOS)
#endif // BUILDFLAG(IS_IOS)
return success;
}
case base::DIR_SRC_TEST_DATA_ROOT:
#if defined(OS_IOS)
#if BUILDFLAG(IS_IOS)
// On iOS, there is no access to source root, however, the necessary
// resources are packaged into the test as assets.
return PathService::Get(base::DIR_ASSETS, result);
Expand All @@ -105,17 +105,17 @@ bool PathProviderMac(int key, base::FilePath* result) {
*result = result->DirName().DirName();
}
return true;
#endif // !defined(OS_IOS)
#endif // BUILDFLAG(IS_IOS)
case base::DIR_USER_DESKTOP:
#if defined(OS_IOS)
#if BUILDFLAG(IS_IOS)
// iOS does not have desktop directories.
NOTIMPLEMENTED();
return false;
#else
return base::mac::GetUserDirectory(NSDesktopDirectory, result);
#endif
case base::DIR_ASSETS:
#if defined(OS_IOS)
#if BUILDFLAG(IS_IOS)
// On iOS, the assets are located next to the module binary.
return PathService::Get(base::DIR_MODULE, result);
#else
Expand All @@ -125,7 +125,7 @@ bool PathProviderMac(int key, base::FilePath* result) {
*result = base::mac::FrameworkBundlePath().Append(
FILE_PATH_LITERAL("Resources"));
return true;
#endif // !defined(OS_IOS)
#endif // BUILDFLAG(IS_IOS)
case base::DIR_CACHE:
return base::mac::GetUserDirectory(NSCachesDirectory, result);
default:
Expand Down
12 changes: 6 additions & 6 deletions base/base_paths_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#include "base/process/process_metrics.h"
#include "build/build_config.h"

#if defined(OS_FREEBSD)
#if BUILDFLAG(IS_FREEBSD)
#include <sys/param.h>
#include <sys/sysctl.h>
#elif defined(OS_SOLARIS) || defined(OS_AIX)
#elif BUILDFLAG(IS_SOLARIS) || BUILDFLAG(IS_AIX)
#include <stdlib.h>
#endif

Expand All @@ -38,15 +38,15 @@ bool PathProviderPosix(int key, FilePath* result) {
switch (key) {
case FILE_EXE:
case FILE_MODULE: { // TODO(evanm): is this correct?
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
FilePath bin_dir;
if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) {
NOTREACHED() << "Unable to resolve " << kProcSelfExe << ".";
return false;
}
*result = bin_dir;
return true;
#elif defined(OS_FREEBSD)
#elif BUILDFLAG(IS_FREEBSD)
int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
char bin_dir[PATH_MAX + 1];
size_t length = sizeof(bin_dir);
Expand All @@ -59,15 +59,15 @@ bool PathProviderPosix(int key, FilePath* result) {
}
*result = FilePath(FilePath::StringType(bin_dir, length - 1));
return true;
#elif defined(OS_SOLARIS)
#elif BUILDFLAG(IS_SOLARIS)
char bin_dir[PATH_MAX + 1];
if (realpath(getexecname(), bin_dir) == NULL) {
NOTREACHED() << "Unable to resolve " << getexecname() << ".";
return false;
}
*result = FilePath(bin_dir);
return true;
#elif defined(OS_OPENBSD) || defined(OS_AIX)
#elif BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_AIX)
// There is currently no way to get the executable path on OpenBSD
char* cpath;
if ((cpath = getenv("CHROME_EXE_PATH")) != NULL)
Expand Down
10 changes: 5 additions & 5 deletions base/base_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const char kVModule[] = "vmodule";
// Will wait for 60 seconds for a debugger to come to attach to the process.
const char kWaitForDebugger[] = "wait-for-debugger";

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
// Disable high-resolution timer on Windows.
const char kDisableHighResTimer[] = "disable-highres-timer";

Expand All @@ -134,7 +134,7 @@ const char kDisableUsbKeyboardDetect[] = "disable-usb-keyboard-detect";

// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if defined(OS_LINUX) && !BUILDFLAG(IS_CHROMEOS_ASH) && \
#if BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS_ASH) && \
!BUILDFLAG(IS_CHROMEOS_LACROS)
// The /dev/shm partition is too small in certain VM environments, causing
// Chrome to fail or crash (see http://crbug.com/715363). Use this flag to
Expand All @@ -143,14 +143,14 @@ const char kDisableUsbKeyboardDetect[] = "disable-usb-keyboard-detect";
const char kDisableDevShmUsage[] = "disable-dev-shm-usage";
#endif

#if defined(OS_POSIX)
#if BUILDFLAG(IS_POSIX)
// Used for turning on Breakpad crash reporting in a debug environment where
// crash reporting is typically compiled but disabled.
const char kEnableCrashReporterForTesting[] =
"enable-crash-reporter-for-testing";
#endif

#if defined(OS_ANDROID)
#if BUILDFLAG(IS_ANDROID)
// Enables the reached code profiler that samples all threads in all processes
// to determine which functions are almost never executed.
const char kEnableReachedCodeProfiler[] = "enable-reached-code-profiler";
Expand All @@ -170,7 +170,7 @@ const char kForceFieldTrialParams[] = "force-fieldtrial-params";

#endif

#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// Controls whether or not retired instruction counts are surfaced for threads
// in trace events on Linux.
//
Expand Down
10 changes: 5 additions & 5 deletions base/base_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,31 @@ extern const char kV[];
extern const char kVModule[];
extern const char kWaitForDebugger[];

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
extern const char kDisableHighResTimer[];
extern const char kDisableUsbKeyboardDetect[];
#endif

// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if defined(OS_LINUX) && !BUILDFLAG(IS_CHROMEOS_ASH) && \
#if BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS_ASH) && \
!BUILDFLAG(IS_CHROMEOS_LACROS)
extern const char kDisableDevShmUsage[];
#endif

#if defined(OS_POSIX)
#if BUILDFLAG(IS_POSIX)
extern const char kEnableCrashReporterForTesting[];
#endif

#if defined(OS_ANDROID)
#if BUILDFLAG(IS_ANDROID)
extern const char kEnableReachedCodeProfiler[];
extern const char kReachedCodeSamplingIntervalUs[];
extern const char kDefaultCountryCodeAtInstall[];
extern const char kEnableIdleTracing[];
extern const char kForceFieldTrialParams[];
#endif

#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
extern const char kEnableThreadInstructionCount[];

// TODO(crbug.com/1176772): Remove kEnableCrashpad and IsCrashpadEnabled() when
Expand Down
6 changes: 3 additions & 3 deletions base/bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "base/template_util.h"
#include "build/build_config.h"

#if defined(OS_APPLE) && !HAS_FEATURE(objc_arc)
#if BUILDFLAG(IS_APPLE) && !HAS_FEATURE(objc_arc)
#include "base/mac/scoped_block.h"
#endif

Expand Down Expand Up @@ -302,7 +302,7 @@ inline internal::IgnoreResultHelper<T> IgnoreResult(T data) {
return internal::IgnoreResultHelper<T>(std::move(data));
}

#if defined(OS_APPLE) && !HAS_FEATURE(objc_arc)
#if BUILDFLAG(IS_APPLE) && !HAS_FEATURE(objc_arc)

// RetainBlock() is used to adapt an Objective-C block when Automated Reference
// Counting (ARC) is disabled. This is unnecessary when ARC is enabled, as the
Expand All @@ -320,7 +320,7 @@ base::mac::ScopedBlock<R (^)(Args...)> RetainBlock(R (^block)(Args...)) {
base::scoped_policy::RETAIN);
}

#endif // defined(OS_APPLE) && !HAS_FEATURE(objc_arc)
#endif // BUILDFLAG(IS_APPLE) && !HAS_FEATURE(objc_arc)

} // namespace base

Expand Down
18 changes: 9 additions & 9 deletions base/bind_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "base/template_util.h"
#include "build/build_config.h"

#if defined(OS_APPLE) && !HAS_FEATURE(objc_arc)
#if BUILDFLAG(IS_APPLE) && !HAS_FEATURE(objc_arc)
#include "base/mac/scoped_block.h"
#endif

Expand Down Expand Up @@ -56,7 +56,7 @@
// BindState<> -- Stores the curried parameters, and is the main entry point
// into the Bind() system.

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
namespace Microsoft {
namespace WRL {
template <typename>
Expand Down Expand Up @@ -431,7 +431,7 @@ struct FunctorTraits<R (*)(Args...)> {
}
};

#if defined(OS_WIN) && !defined(ARCH_CPU_64_BITS)
#if BUILDFLAG(IS_WIN) && !defined(ARCH_CPU_64_BITS)

// For functions.
template <typename R, typename... Args>
Expand Down Expand Up @@ -461,9 +461,9 @@ struct FunctorTraits<R(__fastcall*)(Args...)> {
}
};

#endif // defined(OS_WIN) && !defined(ARCH_CPU_64_BITS)
#endif // BUILDFLAG(IS_WIN) && !defined(ARCH_CPU_64_BITS)

#if defined(OS_APPLE)
#if BUILDFLAG(IS_APPLE)

// Support for Objective-C blocks. There are two implementation depending
// on whether Automated Reference Counting (ARC) is enabled. When ARC is
Expand Down Expand Up @@ -518,7 +518,7 @@ struct FunctorTraits<base::mac::ScopedBlock<R (^)(Args...)>> {
};

#endif // HAS_FEATURE(objc_arc)
#endif // defined(OS_APPLE)
#endif // BUILDFLAG(IS_APPLE)

// For methods.
template <typename R, typename Receiver, typename... Args>
Expand Down Expand Up @@ -552,7 +552,7 @@ struct FunctorTraits<R (Receiver::*)(Args...) const> {
}
};

#if defined(OS_WIN) && !defined(ARCH_CPU_64_BITS)
#if BUILDFLAG(IS_WIN) && !defined(ARCH_CPU_64_BITS)

// For __stdcall methods.
template <typename R, typename Receiver, typename... Args>
Expand Down Expand Up @@ -586,7 +586,7 @@ struct FunctorTraits<R (__stdcall Receiver::*)(Args...) const> {
}
};

#endif // defined(OS_WIN) && !defined(ARCH_CPU_64_BITS)
#endif // BUILDFLAG(IS_WIN) && !defined(ARCH_CPU_64_BITS)

#ifdef __cpp_noexcept_function_type
// noexcept makes a distinct function type in C++17.
Expand Down Expand Up @@ -1378,7 +1378,7 @@ struct BindUnwrapTraits<internal::PassedWrapper<T>> {
static T Unwrap(const internal::PassedWrapper<T>& o) { return o.Take(); }
};

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
template <typename T>
struct BindUnwrapTraits<Microsoft::WRL::ComPtr<T>> {
static T* Unwrap(const Microsoft::WRL::ComPtr<T>& ptr) { return ptr.Get(); }
Expand Down
2 changes: 1 addition & 1 deletion base/bind_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ TEST_F(BindTest, OnceCallback) {
//
// TODO(ajwong): Is there actually a way to test this?

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
int __fastcall FastCallFunc(int n) {
return n;
}
Expand Down
Loading

0 comments on commit 38e4ebb

Please sign in to comment.