From 99cbd3571f415910a89096d966c1f95ab717eb76 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 11 Apr 2024 11:18:29 -0400 Subject: [PATCH] win: Fix MSVC compile error with cef_color_ids.h (see #3671) Copy and modify ui/color/color_id_macros.inc to include an MSVC workaround for `__VA_ARGS__` expansion. --- include/base/internal/cef_color_id_macros.inc | 56 ++++++++++++++++--- tools/distrib/transfer.cfg | 4 -- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/include/base/internal/cef_color_id_macros.inc b/include/base/internal/cef_color_id_macros.inc index 4522726fa..eb0c3a7cc 100644 --- a/include/base/internal/cef_color_id_macros.inc +++ b/include/base/internal/cef_color_id_macros.inc @@ -1,8 +1,50 @@ -// Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. -// -// Include color id macros from the Chromium source location. When creating a -// CEF binary distribution this file will be replaced with the Chromium version. +// Copyright 2019 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. -#include "ui/color/color_id_macros.inc" +// The following macros are used to declare both the color id enumerations and +// the stringized names of the enumeration elements for use in dump_colors. To +// stringize the element names, define STRINGIZE_COLOR_IDS prior to including +// this file. This file is intended to be included just before and just after +// the enumeration or string array declarations. + +#if !defined(COLOR_ID_MACROS_DEFINED) +#define COLOR_ID_MACROS_DEFINED +#if defined(STRINGIZE_COLOR_IDS) +// Convert first token to string, throw away the rest. +#define D1(enum_name) #enum_name +#define D2(enum_name, enum_value) #enum_name +#else // defined(STRINGIZE_COLOR_IDS) +// Declare enum with optional assigned value. +#define D1(enum_name) enum_name +#define D2(enum_name, enum_value) enum_name = enum_value +#endif // defined(STRINGIZE_COLOR_IDS) +// Select which token in the declaration is the assigned value. +// Use first and optional third token, ignore optional second. +#define E1(enum_name) D1(enum_name) +#define E2(enum_name, old_enum_name) D1(enum_name) +#define E3(enum_name, old_enum_name, enum_value) D2(enum_name, enum_value) +#define GET_E(_1, _2, _3, macro_name, ...) macro_name +#if defined(COMPILER_MSVC) +// Workaround for MSVC not properly expanding __VA_ARGS__. +#define EXPAND(x) x +#define E_CPONLY(...) EXPAND(E(__VA_ARGS__)) +#define E(...) EXPAND(GET_E(__VA_ARGS__, E3, E2, E1)(__VA_ARGS__)), +#else // !defined(COMPILER_MSVC) +#define E_CPONLY(...) E(__VA_ARGS__) +#define E(...) GET_E(__VA_ARGS__, E3, E2, E1)(__VA_ARGS__), +#endif // !defined(COMPILER_MSVC) +#else // !defined(COLOR_ID_MACROS_DEFINED) +#undef D1 +#undef D2 +#undef E1 +#undef E2 +#undef E3 +#if defined(COMPILER_MSVC) +#undef EXPAND +#endif +#undef E_CPONLY +#undef GET_E +#undef E +#undef COLOR_ID_MACROS_DEFINED +#endif // !defined(COLOR_ID_MACROS_DEFINED) diff --git a/tools/distrib/transfer.cfg b/tools/distrib/transfer.cfg index 2ca3736e0..d3a65eaf7 100644 --- a/tools/distrib/transfer.cfg +++ b/tools/distrib/transfer.cfg @@ -14,8 +14,4 @@ 'source' : '../net/base/net_error_list.h', 'target' : 'include/base/internal/cef_net_error_list.h', }, - { - 'source' : '../ui/color/color_id_macros.inc', - 'target' : 'include/base/internal/cef_color_id_macros.inc', - }, ]