Skip to content

Commit ac5767d

Browse files
perfetto: honor PERFETTO_REGEX_FORCE_STD in regex backend headers (#6072)
#6034 made regex.cc include all backend headers unconditionally so gen_amalgamated can see through them, relying on each header to self-guard. regex_pcre2.h / regex_re2.h guarded only on PERFETTO_BUILDFLAG(PERFETTO_PCRE2/RE2), ignoring PERFETTO_REGEX_FORCE_STD. In the android_tree build config PERFETTO_PCRE2 is defined to 1 globally, so the unconditional include pulled <pcre2.h> into every target, including libperfetto_client_experimental, which sets -DPERFETTO_REGEX_FORCE_STD precisely to avoid pulling in libpcre2 (see gn/perfetto.gni). This broke the Android auto-roll with "'pcre2.h' file not found". Make the header self-guards also honor PERFETTO_REGEX_FORCE_STD, matching the backend-selection priority in regex.cc where FORCE_STD wins over PCRE2/RE2. Fix both headers as the opt-out contract applies symmetrically.
1 parent 0418eff commit ac5767d

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/base/regex/regex_pcre2.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
#include "perfetto/base/build_config.h"
2121

22-
// See note in regex_re2.h.
23-
#if PERFETTO_BUILDFLAG(PERFETTO_PCRE2)
22+
// See note in regex_re2.h. Also honor PERFETTO_REGEX_FORCE_STD: targets that
23+
// define it (e.g. libperfetto_client_experimental) opt out of the optional
24+
// backends and must not pull in <pcre2.h>, even when PERFETTO_PCRE2 is set.
25+
#if PERFETTO_BUILDFLAG(PERFETTO_PCRE2) && !defined(PERFETTO_REGEX_FORCE_STD)
2426

2527
#include <limits>
2628
#include <memory>
@@ -198,6 +200,7 @@ class RegexPcre2 {
198200
} // namespace base
199201
} // namespace perfetto
200202

201-
#endif // PERFETTO_BUILDFLAG(PERFETTO_PCRE2)
203+
#endif // PERFETTO_BUILDFLAG(PERFETTO_PCRE2) &&
204+
// !defined(PERFETTO_REGEX_FORCE_STD)
202205

203206
#endif // SRC_BASE_REGEX_REGEX_PCRE2_H_

src/base/regex/regex_re2.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
#include "perfetto/base/build_config.h"
2121

2222
// Guarded because gen_amalgamated inlines the body even when the include
23-
// site in regex.cc is preprocessed out.
24-
#if PERFETTO_BUILDFLAG(PERFETTO_RE2)
23+
// site in regex.cc is preprocessed out. Also honor PERFETTO_REGEX_FORCE_STD:
24+
// targets that define it opt out of the optional backends and must not pull in
25+
// <re2/re2.h>, even when PERFETTO_RE2 is set.
26+
#if PERFETTO_BUILDFLAG(PERFETTO_RE2) && !defined(PERFETTO_REGEX_FORCE_STD)
2527

2628
#include <memory>
2729
#include <string>
@@ -124,6 +126,7 @@ class RegexRe2 {
124126
} // namespace base
125127
} // namespace perfetto
126128

127-
#endif // PERFETTO_BUILDFLAG(PERFETTO_RE2)
129+
#endif // PERFETTO_BUILDFLAG(PERFETTO_RE2) &&
130+
// !defined(PERFETTO_REGEX_FORCE_STD)
128131

129132
#endif // SRC_BASE_REGEX_REGEX_RE2_H_

src/shared_lib/test/protos/test_messages.pzc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <stdint.h>
2525

2626
#include "perfetto/public/pb_macros.h"
27+
#include "src/shared_lib/test/protos/extensions.pzc.h"
2728
#include "src/shared_lib/test/protos/library.pzc.h"
2829
#include "src/shared_lib/test/protos/other_package/test_messages.pzc.h"
2930
#include "src/shared_lib/test/protos/subpackage/test_messages.pzc.h"

0 commit comments

Comments
 (0)