diff options
author | Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> | 2024-03-20 11:18:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-20 11:18:52 -0700 |
commit | 1ffebb2e37e324a6cec342a4d85b75ddcbaa7f01 (patch) | |
tree | 573ed0a9fd8e03596999764cfb7771c0fc977a17 | |
parent | 03342cee5c8b2db7963a404b2d703b63a4d35b37 (diff) | |
parent | a4d2448d48670bc76747f6333fcaaf7118459265 (diff) | |
download | protobuf-1ffebb2e37e324a6cec342a4d85b75ddcbaa7f01.tar.gz |
Merge pull request #16237 from protocolbuffers/windows-getenv-fix
Fix windows-only issue in our compiler unittests.
-rw-r--r-- | .github/workflows/test_cpp.yml | 6 | ||||
-rw-r--r-- | .github/workflows/test_upb.yml | 4 | ||||
-rw-r--r-- | src/google/protobuf/compiler/mock_code_generator.cc | 19 |
3 files changed, 18 insertions, 11 deletions
diff --git a/.github/workflows/test_cpp.yml b/.github/workflows/test_cpp.yml index 91a344312..7ca1bf574 100644 --- a/.github/workflows/test_cpp.yml +++ b/.github/workflows/test_cpp.yml @@ -19,9 +19,9 @@ jobs: config: - { name: Optimized, flags: --config=opt } - { name: Debug, flags: --config=dbg } - - { name: ASAN, flags: --config=asan, runner: ubuntu-22-large } - - { name: MSAN, flags: --config=docker-msan, runner: ubuntu-22-large } - - { name: TSAN, flags: --config=tsan } + - { name: ASAN, flags: --config=asan, runner: ubuntu-20-large } + - { name: MSAN, flags: --config=docker-msan, runner: ubuntu-20-large } + - { name: TSAN, flags: --config=tsan, runner: ubuntu-20-large } - { name: UBSAN, flags: --config=ubsan } - { name: No-RTTI, flags: --cxxopt=-fno-rtti } include: diff --git a/.github/workflows/test_upb.yml b/.github/workflows/test_upb.yml index cb8545644..3c257356f 100644 --- a/.github/workflows/test_upb.yml +++ b/.github/workflows/test_upb.yml @@ -20,14 +20,14 @@ jobs: - { name: "Bazel 7", bazel_version: "7.0.0" } - { name: "Fastbuild" } - { name: "Optimized", flags: "-c opt" } - - { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/..." } + - { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/...", runner: ubuntu-20-large } - { name: "UBSAN", flags: "--config=ubsan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/... -//lua/..." } - { name: "32-bit", flags: "--copt=-m32 --linkopt=-m32", exclude-targets: "-//benchmarks:benchmark -//python/..." } # TODO: Add 32-bit ASAN test # TODO: Restore the FastTable tests name: ${{ matrix.config.name }} - runs-on: ubuntu-latest + runs-on: ${{ matrix.config.runner || 'ubuntu-latest' }} steps: - name: Checkout pending changes diff --git a/src/google/protobuf/compiler/mock_code_generator.cc b/src/google/protobuf/compiler/mock_code_generator.cc index 665262d71..bcfa093de 100644 --- a/src/google/protobuf/compiler/mock_code_generator.cc +++ b/src/google/protobuf/compiler/mock_code_generator.cc @@ -50,6 +50,7 @@ namespace google { namespace protobuf { namespace compiler { +namespace { // Returns the list of the names of files in all_files in the form of a // comma-separated string. @@ -71,14 +72,20 @@ static constexpr absl::string_view kFirstInsertionPoint = static constexpr absl::string_view kSecondInsertionPoint = " # @@protoc_insertion_point(second_mock_insertion_point) is here\n"; -MockCodeGenerator::MockCodeGenerator(absl::string_view name) : name_(name) { +absl::string_view GetTestCase() { const char* c_key = getenv("TEST_CASE"); - if (c_key == NULL) { + if (c_key == nullptr) { // In Windows, setting 'TEST_CASE=' is equivalent to unsetting - // and therefore c_key can be NULL - c_key = ""; + // and therefore c_key can be nullptr + return ""; } - absl::string_view key(c_key); + return c_key; +} + +} // namespace + +MockCodeGenerator::MockCodeGenerator(absl::string_view name) : name_(name) { + absl::string_view key = GetTestCase(); if (key == "no_editions") { suppressed_features_ |= CodeGenerator::FEATURE_SUPPORTS_EDITIONS; } else if (key == "invalid_features") { @@ -214,7 +221,7 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file, std::string* error) const { // Override minimum/maximum after generating the pool to simulate a plugin // that "works" but doesn't advertise support of the current edition. - absl::string_view test_case = getenv("TEST_CASE"); + absl::string_view test_case = GetTestCase(); if (test_case == "high_minimum") { minimum_edition_ = Edition::EDITION_99997_TEST_ONLY; } else if (test_case == "low_maximum") { |