xref: /aosp_15_r20/external/pigweed/pw_ide/py/cpp_test.py (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2022 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14"""Tests for pw_ide.cpp"""
15
16import json
17from pathlib import Path
18from typing import cast
19import unittest
20
21# pylint: disable=protected-access
22from pw_ide.cpp import (
23    COMPDB_FILE_NAME,
24    command_parts,
25    path_to_executable,
26    CppCompilationDatabase,
27    CppCompilationDatabasesMap,
28    CppCompileCommand,
29    CppCompileCommandDict,
30    CppIdeFeaturesTarget,
31    CppIdeFeaturesState,
32    infer_target,
33    _infer_target_pos,
34)
35
36from pw_ide.exceptions import UnresolvablePathException
37
38from test_cases import PwIdeTestCase
39
40
41class TestPathToExecutable(PwIdeTestCase):
42    """Tests path_to_executable"""
43
44    def test_valid_absolute_path_in_env_returns_same_path(self):
45        executable_path = self.temp_dir_path / 'clang'
46        query_drivers = [f'{self.temp_dir_path}/*']
47        result = path_to_executable(
48            str(executable_path.absolute()), path_globs=query_drivers
49        )
50        self.assertIsNotNone(result)
51        self.assertEqual(str(result), str(executable_path.absolute()))
52
53    def test_valid_absolute_path_outside_env_returns_same_path(self):
54        executable_path = Path('/usr/bin/clang')
55        query_drivers = ['/**/*']
56        result = path_to_executable(
57            str(executable_path.absolute()), path_globs=query_drivers
58        )
59        self.assertIsNotNone(result)
60        self.assertEqual(str(result), str(executable_path.absolute()))
61
62    def test_valid_relative_path_returns_same_path(self):
63        executable_path = Path('../clang')
64        query_drivers = [f'{self.temp_dir_path}/*']
65        result = path_to_executable(
66            str(executable_path), path_globs=query_drivers
67        )
68        self.assertIsNotNone(result)
69        self.assertEqual(str(result), str(executable_path))
70
71    def test_valid_no_path_returns_new_path(self):
72        executable_path = Path('clang')
73        query_drivers = [f'{self.temp_dir_path}/*']
74        expected_path = self.temp_dir_path / executable_path
75        self.touch_temp_file(expected_path)
76        result = path_to_executable(
77            str(executable_path), path_globs=query_drivers
78        )
79        self.assertIsNotNone(result)
80        self.assertEqual(str(result), str(expected_path))
81
82    def test_invalid_absolute_path_in_env_returns_same_path(self):
83        executable_path = self.temp_dir_path / '_pw_invalid_exe'
84        query_drivers = [f'{self.temp_dir_path}/*']
85        result = path_to_executable(
86            str(executable_path.absolute()), path_globs=query_drivers
87        )
88        self.assertIsNone(result)
89
90    def test_invalid_absolute_path_outside_env_returns_same_path(self):
91        executable_path = Path('/usr/bin/_pw_invalid_exe')
92        query_drivers = ['/**/*']
93        result = path_to_executable(
94            str(executable_path.absolute()), path_globs=query_drivers
95        )
96        self.assertIsNone(result)
97
98    def test_invalid_relative_path_returns_same_path(self):
99        executable_path = Path('../_pw_invalid_exe')
100        query_drivers = [f'{self.temp_dir_path}/*']
101        result = path_to_executable(
102            str(executable_path), path_globs=query_drivers
103        )
104        self.assertIsNone(result)
105
106    def test_invalid_no_path_returns_new_path(self):
107        executable_path = Path('_pw_invalid_exe')
108        query_drivers = [f'{self.temp_dir_path}/*']
109        expected_path = self.temp_dir_path / executable_path
110        self.touch_temp_file(expected_path)
111        result = path_to_executable(
112            str(executable_path), path_globs=query_drivers
113        )
114        self.assertIsNone(result)
115
116
117class TestInferTarget(unittest.TestCase):
118    """Tests infer_target"""
119
120    def test_infer_target_pos(self):
121        test_cases = [
122            ('?', [0]),
123            ('*/?', [1]),
124            ('*/*/?', [2]),
125            ('*/?/?', [1, 2]),
126        ]
127
128        for glob, result in test_cases:
129            self.assertEqual(_infer_target_pos(glob), result)
130
131    def test_infer_target(self):
132        test_cases = [
133            ('?', 'target/thing.o', 'target'),
134            ('*/?', 'variants/target/foo/bar/thing.o', 'target'),
135            ('*/*/*/*/?', 'foo/bar/baz/hi/target/obj/thing.o', 'target'),
136            ('*/?/?', 'variants/target/foo/bar/thing.o', 'target_foo'),
137        ]
138
139        for glob, output_path, result in test_cases:
140            self.assertEqual(
141                infer_target(glob, Path(''), Path(output_path)), result
142            )
143
144
145class TestCppCompileCommand(PwIdeTestCase):
146    """Tests CppCompileCommand"""
147
148    def run_process_test_with_valid_commands(
149        self, command: str, expected_executable: str | None
150    ) -> None:
151        compile_command = CppCompileCommand(
152            command=command, file='', directory=''
153        )
154        processed_compile_command = cast(
155            CppCompileCommand,
156            compile_command.process(default_path=self.temp_dir_path),
157        )
158        self.assertIsNotNone(processed_compile_command)
159        self.assertEqual(
160            processed_compile_command.executable_name, expected_executable
161        )
162
163    def run_process_test_with_invalid_commands(self, command: str) -> None:
164        compile_command = CppCompileCommand(
165            command=command, file='', directory=''
166        )
167
168        with self.assertRaises(UnresolvablePathException):
169            compile_command.process(default_path=self.temp_dir_path)
170
171    def test_process_valid_with_gn_compile_command(self) -> None:
172        """Test output against typical GN-generated compile commands."""
173
174        cases: list[dict[str, str]] = [
175            {
176                # pylint: disable=line-too-long
177                'command': 'arm-none-eabi-g++ -MMD -MF  stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o.d  -Wno-psabi -mabi=aapcs -mthumb --sysroot=../environment/cipd/packages/arm -specs=nano.specs -specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Og -Wshadow -Wredundant-decls -u_printf_float -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -DPW_ARMV7M_ENABLE_FPU=1  -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/assert_compatibility_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o  stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
178                # pylint: enable=line-too-long
179                'executable': 'arm-none-eabi-g++',
180            },
181            {
182                # pylint: disable=line-too-long
183                'command': '../environment/cipd/packages/pigweed/bin/clang++ -MMD -MF  pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d  -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1  -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o  pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
184                # pylint: enable=line-too-long
185                'executable': 'clang++',
186            },
187        ]
188
189        for case in cases:
190            self.run_process_test_with_valid_commands(
191                case['command'], case['executable']
192            )
193
194    def test_process_invalid_with_gn_compile_command(self) -> None:
195        """Test output against typical GN-generated compile commands."""
196
197        # pylint: disable=line-too-long
198        command = "python ../pw_toolchain/py/pw_toolchain/clang_tidy.py  --source-exclude 'third_party/.*' --source-exclude '.*packages/mbedtls.*' --source-exclude '.*packages/boringssl.*'  --skip-include-path 'mbedtls/include' --skip-include-path 'mbedtls' --skip-include-path 'boringssl/src/include' --skip-include-path 'boringssl' --skip-include-path 'pw_tls_client/generate_test_data' --source-file ../pw_allocator/freelist.cc --source-root '../' --export-fixes  pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/freelist.freelist.cc.o.yaml -- ../environment/cipd/packages/pigweed/bin/clang++ END_OF_INVOKER -MMD -MF  pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/freelist.freelist.cc.o.d  -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1  -I../pw_allocator/public -I../pw_containers/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/freelist.cc -o  pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/freelist.freelist.cc.o && touch  pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/freelist.freelist.cc.o"
199        # pylint: enable=line-too-long
200
201        compile_command = CppCompileCommand(
202            command=command, file='', directory=''
203        )
204        self.assertIsNone(
205            compile_command.process(default_path=self.temp_dir_path)
206        )
207
208    def test_process_unresolvable_with_gn_compile_command(self) -> None:
209        """Test output against typical GN-generated compile commands."""
210
211        # pylint: disable=line-too-long
212        command = 'clang++ -MMD -MF  pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d  -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1  -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o  pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o'
213        # pylint: enable=line-too-long
214
215        compile_command = CppCompileCommand(
216            command=command, file='', directory=''
217        )
218
219        processed_compile_command = cast(
220            CppCompileCommand, compile_command.process()
221        )
222        self.assertIsNotNone(processed_compile_command)
223        self.assertIsNotNone(processed_compile_command.command)
224        # .split() to avoid failing on whitespace differences.
225        self.assertCountEqual(
226            cast(str, processed_compile_command.command).split(),
227            command.split(),
228        )
229
230    def test_process_unresolvable_strict_with_gn_compile_command(self) -> None:
231        """Test output against typical GN-generated compile commands."""
232
233        # pylint: disable=line-too-long
234        command = 'clang++ -MMD -MF  pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d  -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1  -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o  pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o'
235        # pylint: enable=line-too-long
236
237        compile_command = CppCompileCommand(
238            command=command, file='', directory=''
239        )
240
241        with self.assertRaises(UnresolvablePathException):
242            compile_command.process(strict=True)
243
244    def test_process_blank_with_gn_compile_command(self) -> None:
245        """Test output against typical GN-generated compile commands."""
246
247        command = ''
248        compile_command = CppCompileCommand(
249            command=command, file='', directory=''
250        )
251
252        result = compile_command.process(default_path=self.temp_dir_path)
253        self.assertIsNone(result)
254
255
256class TestCommandParts(unittest.TestCase):
257    """Test command_parts"""
258
259    def test_command_parts(self):
260        """Test command_parts"""
261
262        # pylint: disable=line-too-long
263        test_cases = [
264            "python ../pw_toolchain/py/pw_toolchain/clang_tidy.py --source-exclude 'third_party/.*' --source-exclude '.*packages/mbedtls.*' --source-exclude '.*packages/boringssl.*' --skip-include-path 'mbedtls/include' --skip-include-path 'mbedtls' --skip-include-path 'boringssl/src/include' --skip-include-path 'boringssl' --skip-include-path 'pw_tls_client/generate_test_data' --source-file ../pw_allocator/block.cc --source-root '../' --export-fixes  pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o.yaml -- ../environment/cipd/packages/pigweed/bin/clang++ END_OF_INVOKER -MMD -MF pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o && touch pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o",
265            'arm-none-eabi-g++ -MMD -MF stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o.d -Wno-psabi -mabi=aapcs -mthumb --sysroot=../environment/cipd/packages/arm -specs=nano.specs -specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Og -Wshadow -Wredundant-decls -u_printf_float -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -DPW_ARMV7M_ENABLE_FPU=1  -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/assert_compatibility_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
266            '../environment/cipd/packages/pigweed/bin/isosceles-clang++ -MMD -MF isosceles_debug/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o isosceles_debug/obj/pw_allocator/block.block.cc.o',
267            '../environment/cipd/packages/pigweed/bin/clang++ -MMD -MF pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o  pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
268            'ccache arm-none-eabi-g++ -MMD -MF stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o.d -Wno-psabi -mabi=aapcs -mthumb --sysroot=../environment/cipd/packages/arm -specs=nano.specs -specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Og -Wshadow -Wredundant-decls -u_printf_float -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -DPW_ARMV7M_ENABLE_FPU=1  -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/assert_compatibility_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
269            'ccache ../environment/cipd/packages/pigweed/bin/isosceles-clang++ -MMD -MF isosceles_debug/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o isosceles_debug/obj/pw_allocator/block.block.cc.o',
270            'ccache ../environment/cipd/packages/pigweed/bin/clang++ -MMD -MF pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o  pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
271            'ccache debug=true max_size=10G arm-none-eabi-g++ -MMD -MF stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o.d -Wno-psabi -mabi=aapcs -mthumb --sysroot=../environment/cipd/packages/arm -specs=nano.specs -specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Og -Wshadow -Wredundant-decls -u_printf_float -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -DPW_ARMV7M_ENABLE_FPU=1  -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/assert_compatibility_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
272            'ccache debug=true max_size=10G ../environment/cipd/packages/pigweed/bin/isosceles-clang++ -MMD -MF isosceles_debug/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o isosceles_debug/obj/pw_allocator/block.block.cc.o',
273            'ccache debug=true max_size=10G ../environment/cipd/packages/pigweed/bin/clang++ -MMD -MF pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o  pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
274            "ccache python ../pw_toolchain/py/pw_toolchain/clang_tidy.py --source-exclude 'third_party/.*' --source-exclude '.*packages/mbedtls.*' --source-exclude '.*packages/boringssl.*' --skip-include-path 'mbedtls/include' --skip-include-path 'mbedtls' --skip-include-path 'boringssl/src/include' --skip-include-path 'boringssl' --skip-include-path 'pw_tls_client/generate_test_data' --source-file ../pw_allocator/block.cc --source-root '../' --export-fixes  pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o.yaml -- ../environment/cipd/packages/pigweed/bin/clang++ END_OF_INVOKER -MMD -MF pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o && touch pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o",
275        ]
276
277        expected_results = [
278            (
279                None,
280                'python',
281                [
282                    '../pw_toolchain/py/pw_toolchain/clang_tidy.py',
283                    '--source-exclude',
284                    "'third_party/.*'",
285                    '--source-exclude',
286                    "'.*packages/mbedtls.*'",
287                    '--source-exclude',
288                    "'.*packages/boringssl.*'",
289                    '--skip-include-path',
290                    "'mbedtls/include'",
291                    '--skip-include-path',
292                    "'mbedtls'",
293                    '--skip-include-path',
294                    "'boringssl/src/include'",
295                    '--skip-include-path',
296                    "'boringssl'",
297                    '--skip-include-path',
298                    "'pw_tls_client/generate_test_data'",
299                    '--source-file',
300                    '../pw_allocator/block.cc',
301                    '--source-root',
302                    "'../'",
303                    '--export-fixes',
304                    'pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o.yaml',
305                    '--',
306                    '../environment/cipd/packages/pigweed/bin/clang++',
307                    'END_OF_INVOKER',
308                    '-MMD',
309                    '-MF',
310                    'pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o.d',
311                    '-g3',
312                    '--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk',
313                    '-Og',
314                    '-Wshadow',
315                    '-Wredundant-decls',
316                    '-Wthread-safety',
317                    '-Wswitch-enum',
318                    '-fdiagnostics-color',
319                    '-g',
320                    '-fno-common',
321                    '-fno-exceptions',
322                    '-ffunction-sections',
323                    '-fdata-sections',
324                    '-Wall',
325                    '-Wextra',
326                    '-Wimplicit-fallthrough',
327                    '-Wcast-qual',
328                    '-Wundef',
329                    '-Wpointer-arith',
330                    '-Werror',
331                    '-Wno-error=cpp',
332                    '-Wno-error=deprecated-declarations',
333                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
334                    '-ffile-prefix-map=/pigweed/pigweed/=',
335                    '-ffile-prefix-map=../=',
336                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
337                    '-Wextra-semi',
338                    '-fno-rtti',
339                    '-Wnon-virtual-dtor',
340                    '-std=c++17',
341                    '-Wno-register',
342                    '-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1',
343                    '-DPW_STATUS_CFG_CHECK_IF_USED=1',
344                    '-I../pw_allocator/public',
345                    '-I../pw_assert/public',
346                    '-I../pw_assert/print_and_abort_assert_public_overrides',
347                    '-I../pw_preprocessor/public',
348                    '-I../pw_assert_basic/public_overrides',
349                    '-I../pw_assert_basic/public',
350                    '-I../pw_span/public',
351                    '-I../pw_polyfill/public',
352                    '-I../pw_polyfill/standard_library_public',
353                    '-I../pw_status/public',
354                    '-c',
355                    '../pw_allocator/block.cc',
356                    '-o',
357                    'pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o',
358                    '&&',
359                    'touch',
360                    'pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o',
361                ],
362            ),
363            (
364                None,
365                'arm-none-eabi-g++',
366                [
367                    '-MMD',
368                    '-MF',
369                    'stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o.d',
370                    '-Wno-psabi',
371                    '-mabi=aapcs',
372                    '-mthumb',
373                    '--sysroot=../environment/cipd/packages/arm',
374                    '-specs=nano.specs',
375                    '-specs=nosys.specs',
376                    '-mcpu=cortex-m4',
377                    '-mfloat-abi=hard',
378                    '-mfpu=fpv4-sp-d16',
379                    '-Og',
380                    '-Wshadow',
381                    '-Wredundant-decls',
382                    '-u_printf_float',
383                    '-fdiagnostics-color',
384                    '-g',
385                    '-fno-common',
386                    '-fno-exceptions',
387                    '-ffunction-sections',
388                    '-fdata-sections',
389                    '-Wall',
390                    '-Wextra',
391                    '-Wimplicit-fallthrough',
392                    '-Wcast-qual',
393                    '-Wundef',
394                    '-Wpointer-arith',
395                    '-Werror',
396                    '-Wno-error=cpp',
397                    '-Wno-error=deprecated-declarations',
398                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
399                    '-ffile-prefix-map=/pigweed/pigweed/=',
400                    '-ffile-prefix-map=../=',
401                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
402                    '-fno-rtti',
403                    '-Wnon-virtual-dtor',
404                    '-std=c++17',
405                    '-Wno-register',
406                    '-DPW_ARMV7M_ENABLE_FPU=1',
407                    '-I../pw_allocator/public',
408                    '-I../pw_assert/public',
409                    '-I../pw_assert/assert_compatibility_public_overrides',
410                    '-I../pw_preprocessor/public',
411                    '-I../pw_assert_basic/public_overrides',
412                    '-I../pw_assert_basic/public',
413                    '-I../pw_span/public',
414                    '-I../pw_polyfill/public',
415                    '-I../pw_polyfill/standard_library_public',
416                    '-I../pw_status/public',
417                    '-c',
418                    '../pw_allocator/block.cc',
419                    '-o',
420                    'stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
421                ],
422            ),
423            (
424                None,
425                '../environment/cipd/packages/pigweed/bin/isosceles-clang++',
426                [
427                    '-MMD',
428                    '-MF',
429                    'isosceles_debug/obj/pw_allocator/block.block.cc.o.d',
430                    '-g3',
431                    '--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk',
432                    '-Og',
433                    '-Wshadow',
434                    '-Wredundant-decls',
435                    '-Wthread-safety',
436                    '-Wswitch-enum',
437                    '-fdiagnostics-color',
438                    '-g',
439                    '-fno-common',
440                    '-fno-exceptions',
441                    '-ffunction-sections',
442                    '-fdata-sections',
443                    '-Wall',
444                    '-Wextra',
445                    '-Wimplicit-fallthrough',
446                    '-Wcast-qual',
447                    '-Wundef',
448                    '-Wpointer-arith',
449                    '-Werror',
450                    '-Wno-error=cpp',
451                    '-Wno-error=deprecated-declarations',
452                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
453                    '-ffile-prefix-map=/pigweed/pigweed/=',
454                    '-ffile-prefix-map=../=',
455                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
456                    '-Wextra-semi',
457                    '-fno-rtti',
458                    '-Wnon-virtual-dtor',
459                    '-std=c++17',
460                    '-Wno-register',
461                    '-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1',
462                    '-DPW_STATUS_CFG_CHECK_IF_USED=1',
463                    '-I../pw_allocator/public',
464                    '-I../pw_assert/public',
465                    '-I../pw_assert/print_and_abort_assert_public_overrides',
466                    '-I../pw_preprocessor/public',
467                    '-I../pw_assert_basic/public_overrides',
468                    '-I../pw_assert_basic/public',
469                    '-I../pw_span/public',
470                    '-I../pw_polyfill/public',
471                    '-I../pw_polyfill/standard_library_public',
472                    '-I../pw_status/public',
473                    '-c',
474                    '../pw_allocator/block.cc',
475                    '-o',
476                    'isosceles_debug/obj/pw_allocator/block.block.cc.o',
477                ],
478            ),
479            (
480                None,
481                '../environment/cipd/packages/pigweed/bin/clang++',
482                [
483                    '-MMD',
484                    '-MF',
485                    'pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d',
486                    '-g3',
487                    '--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk',
488                    '-Og',
489                    '-Wshadow',
490                    '-Wredundant-decls',
491                    '-Wthread-safety',
492                    '-Wswitch-enum',
493                    '-fdiagnostics-color',
494                    '-g',
495                    '-fno-common',
496                    '-fno-exceptions',
497                    '-ffunction-sections',
498                    '-fdata-sections',
499                    '-Wall',
500                    '-Wextra',
501                    '-Wimplicit-fallthrough',
502                    '-Wcast-qual',
503                    '-Wundef',
504                    '-Wpointer-arith',
505                    '-Werror',
506                    '-Wno-error=cpp',
507                    '-Wno-error=deprecated-declarations',
508                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
509                    '-ffile-prefix-map=/pigweed/pigweed/=',
510                    '-ffile-prefix-map=../=',
511                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
512                    '-Wextra-semi',
513                    '-fno-rtti',
514                    '-Wnon-virtual-dtor',
515                    '-std=c++17',
516                    '-Wno-register',
517                    '-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1',
518                    '-DPW_STATUS_CFG_CHECK_IF_USED=1',
519                    '-I../pw_allocator/public',
520                    '-I../pw_assert/public',
521                    '-I../pw_assert/print_and_abort_assert_public_overrides',
522                    '-I../pw_preprocessor/public',
523                    '-I../pw_assert_basic/public_overrides',
524                    '-I../pw_assert_basic/public',
525                    '-I../pw_span/public',
526                    '-I../pw_polyfill/public',
527                    '-I../pw_polyfill/standard_library_public',
528                    '-I../pw_status/public',
529                    '-c',
530                    '../pw_allocator/block.cc',
531                    '-o',
532                    'pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
533                ],
534            ),
535            (
536                'ccache',
537                'arm-none-eabi-g++',
538                [
539                    '-MMD',
540                    '-MF',
541                    'stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o.d',
542                    '-Wno-psabi',
543                    '-mabi=aapcs',
544                    '-mthumb',
545                    '--sysroot=../environment/cipd/packages/arm',
546                    '-specs=nano.specs',
547                    '-specs=nosys.specs',
548                    '-mcpu=cortex-m4',
549                    '-mfloat-abi=hard',
550                    '-mfpu=fpv4-sp-d16',
551                    '-Og',
552                    '-Wshadow',
553                    '-Wredundant-decls',
554                    '-u_printf_float',
555                    '-fdiagnostics-color',
556                    '-g',
557                    '-fno-common',
558                    '-fno-exceptions',
559                    '-ffunction-sections',
560                    '-fdata-sections',
561                    '-Wall',
562                    '-Wextra',
563                    '-Wimplicit-fallthrough',
564                    '-Wcast-qual',
565                    '-Wundef',
566                    '-Wpointer-arith',
567                    '-Werror',
568                    '-Wno-error=cpp',
569                    '-Wno-error=deprecated-declarations',
570                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
571                    '-ffile-prefix-map=/pigweed/pigweed/=',
572                    '-ffile-prefix-map=../=',
573                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
574                    '-fno-rtti',
575                    '-Wnon-virtual-dtor',
576                    '-std=c++17',
577                    '-Wno-register',
578                    '-DPW_ARMV7M_ENABLE_FPU=1',
579                    '-I../pw_allocator/public',
580                    '-I../pw_assert/public',
581                    '-I../pw_assert/assert_compatibility_public_overrides',
582                    '-I../pw_preprocessor/public',
583                    '-I../pw_assert_basic/public_overrides',
584                    '-I../pw_assert_basic/public',
585                    '-I../pw_span/public',
586                    '-I../pw_polyfill/public',
587                    '-I../pw_polyfill/standard_library_public',
588                    '-I../pw_status/public',
589                    '-c',
590                    '../pw_allocator/block.cc',
591                    '-o',
592                    'stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
593                ],
594            ),
595            (
596                'ccache',
597                '../environment/cipd/packages/pigweed/bin/isosceles-clang++',
598                [
599                    '-MMD',
600                    '-MF',
601                    'isosceles_debug/obj/pw_allocator/block.block.cc.o.d',
602                    '-g3',
603                    '--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk',
604                    '-Og',
605                    '-Wshadow',
606                    '-Wredundant-decls',
607                    '-Wthread-safety',
608                    '-Wswitch-enum',
609                    '-fdiagnostics-color',
610                    '-g',
611                    '-fno-common',
612                    '-fno-exceptions',
613                    '-ffunction-sections',
614                    '-fdata-sections',
615                    '-Wall',
616                    '-Wextra',
617                    '-Wimplicit-fallthrough',
618                    '-Wcast-qual',
619                    '-Wundef',
620                    '-Wpointer-arith',
621                    '-Werror',
622                    '-Wno-error=cpp',
623                    '-Wno-error=deprecated-declarations',
624                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
625                    '-ffile-prefix-map=/pigweed/pigweed/=',
626                    '-ffile-prefix-map=../=',
627                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
628                    '-Wextra-semi',
629                    '-fno-rtti',
630                    '-Wnon-virtual-dtor',
631                    '-std=c++17',
632                    '-Wno-register',
633                    '-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1',
634                    '-DPW_STATUS_CFG_CHECK_IF_USED=1',
635                    '-I../pw_allocator/public',
636                    '-I../pw_assert/public',
637                    '-I../pw_assert/print_and_abort_assert_public_overrides',
638                    '-I../pw_preprocessor/public',
639                    '-I../pw_assert_basic/public_overrides',
640                    '-I../pw_assert_basic/public',
641                    '-I../pw_span/public',
642                    '-I../pw_polyfill/public',
643                    '-I../pw_polyfill/standard_library_public',
644                    '-I../pw_status/public',
645                    '-c',
646                    '../pw_allocator/block.cc',
647                    '-o',
648                    'isosceles_debug/obj/pw_allocator/block.block.cc.o',
649                ],
650            ),
651            (
652                'ccache',
653                '../environment/cipd/packages/pigweed/bin/clang++',
654                [
655                    '-MMD',
656                    '-MF',
657                    'pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d',
658                    '-g3',
659                    '--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk',
660                    '-Og',
661                    '-Wshadow',
662                    '-Wredundant-decls',
663                    '-Wthread-safety',
664                    '-Wswitch-enum',
665                    '-fdiagnostics-color',
666                    '-g',
667                    '-fno-common',
668                    '-fno-exceptions',
669                    '-ffunction-sections',
670                    '-fdata-sections',
671                    '-Wall',
672                    '-Wextra',
673                    '-Wimplicit-fallthrough',
674                    '-Wcast-qual',
675                    '-Wundef',
676                    '-Wpointer-arith',
677                    '-Werror',
678                    '-Wno-error=cpp',
679                    '-Wno-error=deprecated-declarations',
680                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
681                    '-ffile-prefix-map=/pigweed/pigweed/=',
682                    '-ffile-prefix-map=../=',
683                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
684                    '-Wextra-semi',
685                    '-fno-rtti',
686                    '-Wnon-virtual-dtor',
687                    '-std=c++17',
688                    '-Wno-register',
689                    '-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1',
690                    '-DPW_STATUS_CFG_CHECK_IF_USED=1',
691                    '-I../pw_allocator/public',
692                    '-I../pw_assert/public',
693                    '-I../pw_assert/print_and_abort_assert_public_overrides',
694                    '-I../pw_preprocessor/public',
695                    '-I../pw_assert_basic/public_overrides',
696                    '-I../pw_assert_basic/public',
697                    '-I../pw_span/public',
698                    '-I../pw_polyfill/public',
699                    '-I../pw_polyfill/standard_library_public',
700                    '-I../pw_status/public',
701                    '-c',
702                    '../pw_allocator/block.cc',
703                    '-o',
704                    'pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
705                ],
706            ),
707            (
708                'ccache debug=true max_size=10G',
709                'arm-none-eabi-g++',
710                [
711                    '-MMD',
712                    '-MF',
713                    'stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o.d',
714                    '-Wno-psabi',
715                    '-mabi=aapcs',
716                    '-mthumb',
717                    '--sysroot=../environment/cipd/packages/arm',
718                    '-specs=nano.specs',
719                    '-specs=nosys.specs',
720                    '-mcpu=cortex-m4',
721                    '-mfloat-abi=hard',
722                    '-mfpu=fpv4-sp-d16',
723                    '-Og',
724                    '-Wshadow',
725                    '-Wredundant-decls',
726                    '-u_printf_float',
727                    '-fdiagnostics-color',
728                    '-g',
729                    '-fno-common',
730                    '-fno-exceptions',
731                    '-ffunction-sections',
732                    '-fdata-sections',
733                    '-Wall',
734                    '-Wextra',
735                    '-Wimplicit-fallthrough',
736                    '-Wcast-qual',
737                    '-Wundef',
738                    '-Wpointer-arith',
739                    '-Werror',
740                    '-Wno-error=cpp',
741                    '-Wno-error=deprecated-declarations',
742                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
743                    '-ffile-prefix-map=/pigweed/pigweed/=',
744                    '-ffile-prefix-map=../=',
745                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
746                    '-fno-rtti',
747                    '-Wnon-virtual-dtor',
748                    '-std=c++17',
749                    '-Wno-register',
750                    '-DPW_ARMV7M_ENABLE_FPU=1',
751                    '-I../pw_allocator/public',
752                    '-I../pw_assert/public',
753                    '-I../pw_assert/assert_compatibility_public_overrides',
754                    '-I../pw_preprocessor/public',
755                    '-I../pw_assert_basic/public_overrides',
756                    '-I../pw_assert_basic/public',
757                    '-I../pw_span/public',
758                    '-I../pw_polyfill/public',
759                    '-I../pw_polyfill/standard_library_public',
760                    '-I../pw_status/public',
761                    '-c',
762                    '../pw_allocator/block.cc',
763                    '-o',
764                    'stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
765                ],
766            ),
767            (
768                'ccache debug=true max_size=10G',
769                '../environment/cipd/packages/pigweed/bin/isosceles-clang++',
770                [
771                    '-MMD',
772                    '-MF',
773                    'isosceles_debug/obj/pw_allocator/block.block.cc.o.d',
774                    '-g3',
775                    '--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk',
776                    '-Og',
777                    '-Wshadow',
778                    '-Wredundant-decls',
779                    '-Wthread-safety',
780                    '-Wswitch-enum',
781                    '-fdiagnostics-color',
782                    '-g',
783                    '-fno-common',
784                    '-fno-exceptions',
785                    '-ffunction-sections',
786                    '-fdata-sections',
787                    '-Wall',
788                    '-Wextra',
789                    '-Wimplicit-fallthrough',
790                    '-Wcast-qual',
791                    '-Wundef',
792                    '-Wpointer-arith',
793                    '-Werror',
794                    '-Wno-error=cpp',
795                    '-Wno-error=deprecated-declarations',
796                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
797                    '-ffile-prefix-map=/pigweed/pigweed/=',
798                    '-ffile-prefix-map=../=',
799                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
800                    '-Wextra-semi',
801                    '-fno-rtti',
802                    '-Wnon-virtual-dtor',
803                    '-std=c++17',
804                    '-Wno-register',
805                    '-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1',
806                    '-DPW_STATUS_CFG_CHECK_IF_USED=1',
807                    '-I../pw_allocator/public',
808                    '-I../pw_assert/public',
809                    '-I../pw_assert/print_and_abort_assert_public_overrides',
810                    '-I../pw_preprocessor/public',
811                    '-I../pw_assert_basic/public_overrides',
812                    '-I../pw_assert_basic/public',
813                    '-I../pw_span/public',
814                    '-I../pw_polyfill/public',
815                    '-I../pw_polyfill/standard_library_public',
816                    '-I../pw_status/public',
817                    '-c',
818                    '../pw_allocator/block.cc',
819                    '-o',
820                    'isosceles_debug/obj/pw_allocator/block.block.cc.o',
821                ],
822            ),
823            (
824                'ccache debug=true max_size=10G',
825                '../environment/cipd/packages/pigweed/bin/clang++',
826                [
827                    '-MMD',
828                    '-MF',
829                    'pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d',
830                    '-g3',
831                    '--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk',
832                    '-Og',
833                    '-Wshadow',
834                    '-Wredundant-decls',
835                    '-Wthread-safety',
836                    '-Wswitch-enum',
837                    '-fdiagnostics-color',
838                    '-g',
839                    '-fno-common',
840                    '-fno-exceptions',
841                    '-ffunction-sections',
842                    '-fdata-sections',
843                    '-Wall',
844                    '-Wextra',
845                    '-Wimplicit-fallthrough',
846                    '-Wcast-qual',
847                    '-Wundef',
848                    '-Wpointer-arith',
849                    '-Werror',
850                    '-Wno-error=cpp',
851                    '-Wno-error=deprecated-declarations',
852                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
853                    '-ffile-prefix-map=/pigweed/pigweed/=',
854                    '-ffile-prefix-map=../=',
855                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
856                    '-Wextra-semi',
857                    '-fno-rtti',
858                    '-Wnon-virtual-dtor',
859                    '-std=c++17',
860                    '-Wno-register',
861                    '-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1',
862                    '-DPW_STATUS_CFG_CHECK_IF_USED=1',
863                    '-I../pw_allocator/public',
864                    '-I../pw_assert/public',
865                    '-I../pw_assert/print_and_abort_assert_public_overrides',
866                    '-I../pw_preprocessor/public',
867                    '-I../pw_assert_basic/public_overrides',
868                    '-I../pw_assert_basic/public',
869                    '-I../pw_span/public',
870                    '-I../pw_polyfill/public',
871                    '-I../pw_polyfill/standard_library_public',
872                    '-I../pw_status/public',
873                    '-c',
874                    '../pw_allocator/block.cc',
875                    '-o',
876                    'pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
877                ],
878            ),
879            (
880                'ccache',
881                'python',
882                [
883                    '../pw_toolchain/py/pw_toolchain/clang_tidy.py',
884                    '--source-exclude',
885                    "'third_party/.*'",
886                    '--source-exclude',
887                    "'.*packages/mbedtls.*'",
888                    '--source-exclude',
889                    "'.*packages/boringssl.*'",
890                    '--skip-include-path',
891                    "'mbedtls/include'",
892                    '--skip-include-path',
893                    "'mbedtls'",
894                    '--skip-include-path',
895                    "'boringssl/src/include'",
896                    '--skip-include-path',
897                    "'boringssl'",
898                    '--skip-include-path',
899                    "'pw_tls_client/generate_test_data'",
900                    '--source-file',
901                    '../pw_allocator/block.cc',
902                    '--source-root',
903                    "'../'",
904                    '--export-fixes',
905                    'pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o.yaml',
906                    '--',
907                    '../environment/cipd/packages/pigweed/bin/clang++',
908                    'END_OF_INVOKER',
909                    '-MMD',
910                    '-MF',
911                    'pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o.d',
912                    '-g3',
913                    '--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk',
914                    '-Og',
915                    '-Wshadow',
916                    '-Wredundant-decls',
917                    '-Wthread-safety',
918                    '-Wswitch-enum',
919                    '-fdiagnostics-color',
920                    '-g',
921                    '-fno-common',
922                    '-fno-exceptions',
923                    '-ffunction-sections',
924                    '-fdata-sections',
925                    '-Wall',
926                    '-Wextra',
927                    '-Wimplicit-fallthrough',
928                    '-Wcast-qual',
929                    '-Wundef',
930                    '-Wpointer-arith',
931                    '-Werror',
932                    '-Wno-error=cpp',
933                    '-Wno-error=deprecated-declarations',
934                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
935                    '-ffile-prefix-map=/pigweed/pigweed/=',
936                    '-ffile-prefix-map=../=',
937                    '-ffile-prefix-map=/pigweed/pigweed/out=out',
938                    '-Wextra-semi',
939                    '-fno-rtti',
940                    '-Wnon-virtual-dtor',
941                    '-std=c++17',
942                    '-Wno-register',
943                    '-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1',
944                    '-DPW_STATUS_CFG_CHECK_IF_USED=1',
945                    '-I../pw_allocator/public',
946                    '-I../pw_assert/public',
947                    '-I../pw_assert/print_and_abort_assert_public_overrides',
948                    '-I../pw_preprocessor/public',
949                    '-I../pw_assert_basic/public_overrides',
950                    '-I../pw_assert_basic/public',
951                    '-I../pw_span/public',
952                    '-I../pw_polyfill/public',
953                    '-I../pw_polyfill/standard_library_public',
954                    '-I../pw_status/public',
955                    '-c',
956                    '../pw_allocator/block.cc',
957                    '-o',
958                    'pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o',
959                    '&&',
960                    'touch',
961                    'pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o',
962                ],
963            ),
964        ]
965        # pylint: enable=line-too-long
966
967        for test_case, expected in zip(test_cases, expected_results):
968            self.assertEqual(command_parts(test_case), expected)
969
970
971class TestCppCompilationDatabase(PwIdeTestCase):
972    """Tests CppCompilationDatabase"""
973
974    def setUp(self):
975        self.root_dir = Path('/pigweed/pigweed/out')
976
977        self.fixture: list[CppCompileCommandDict] = [
978            {
979                # pylint: disable=line-too-long
980                'command': 'arm-none-eabi-g++ -MMD -MF stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o.d -Wno-psabi -mabi=aapcs -mthumb --sysroot=../environment/cipd/packages/arm -specs=nano.specs -specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Og -Wshadow -Wredundant-decls -u_printf_float -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -DPW_ARMV7M_ENABLE_FPU=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/assert_compatibility_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
981                # pylint: enable=line-too-long
982                'directory': '/pigweed/pigweed/out',
983                'file': '../pw_allocator/block.cc',
984            },
985            {
986                # pylint: disable=line-too-long
987                'command': '../environment/cipd/packages/pigweed/bin/clang++ -MMD -MF pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
988                # pylint: enable=line-too-long
989                'directory': '/pigweed/pigweed/out',
990                'file': '../pw_allocator/block.cc',
991            },
992        ]
993
994        self.expected: list[CppCompileCommandDict] = [
995            {
996                **self.fixture[0],
997                # pylint: disable=line-too-long
998                'output': 'stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
999                # pylint: enable=line-too-long
1000            },
1001            {
1002                **self.fixture[1],
1003                # pylint: disable=line-too-long
1004                'output': 'pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
1005                # pylint: enable=line-too-long
1006            },
1007        ]
1008
1009        self.fixture_merge_1 = [
1010            {
1011                # pylint: disable=line-too-long
1012                'command': 'g++ -MMD -MF  pw_strict_host_gcc_debug/obj/pw_allocator/block.block.cc.o.d  -Wno-psabi -Og -Wshadow -Wredundant-decls -Wswitch-enum -Wpedantic -Wno-c++20-designator -Wno-gnu-zero-variadic-macro-arguments -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -DPW_SPAN_ENABLE_ASSERTS=true -DPW_STATUS_CFG_CHECK_IF_USED=1  -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o  pw_strict_host_gcc_debug/obj/pw_allocator/block.block.cc.o',
1013                'directory': '/pigweed/pigweed/out',
1014                'file': '../pw_allocator/block.cc',
1015                'output': 'pw_strict_host_gcc_debug/obj/pw_allocator/block.block.cc.o',
1016                # pylint: enable=line-too-long
1017            },
1018            {
1019                # pylint: disable=line-too-long
1020                'command': 'g++ -MMD -MF  pw_strict_host_gcc_debug/obj/pw_allocator/freelist.freelist.cc.o.d  -Wno-psabi -Og -Wshadow -Wredundant-decls -Wswitch-enum -Wpedantic -Wno-c++20-designator -Wno-gnu-zero-variadic-macro-arguments -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=//pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -DPW_SPAN_ENABLE_ASSERTS=true -DPW_STATUS_CFG_CHECK_IF_USED=1  -I../pw_allocator/public -I../pw_containers/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_span/public -I../pw_status/public -c ../pw_allocator/freelist.cc -o  pw_strict_host_gcc_debug/obj/pw_allocator/freelist.freelist.cc.o',
1021                'directory': '/pigweed/pigweed/out',
1022                'file': '../pw_allocator/freelist.cc',
1023                'output': 'pw_strict_host_gcc_debug/obj/pw_allocator/freelist.freelist.cc.o',
1024                # pylint: enable=line-too-long
1025            },
1026        ]
1027
1028        self.fixture_merge_2 = [
1029            {
1030                # pylint: disable=line-too-long
1031                'command': 'g++ -MMD -MF  pw_strict_host_gcc_debug/obj/pw_base64/pw_base64.base64.cc.o.d  -Wno-psabi -Og -Wshadow -Wredundant-decls -Wswitch-enum -Wpedantic -Wno-c++20-designator -Wno-gnu-zero-variadic-macro-arguments -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -DPW_SPAN_ENABLE_ASSERTS=true  -I../pw_base64/public -I../pw_string/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_span/public -c ../pw_base64/base64.cc -o  pw_strict_host_gcc_debug/obj/pw_base64/pw_base64.base64.cc.o',
1032                'directory': '/pigweed/pigweed/out',
1033                'file': '../pw_base64/base64.cc',
1034                'output': 'pw_strict_host_gcc_debug/obj/pw_base64/pw_base64.base64.cc.o',
1035                # pylint: enable=line-too-long
1036            },
1037            {
1038                # pylint: disable=line-too-long
1039                'command': 'g++ -MMD -MF  pw_strict_host_gcc_debug/obj/pw_checksum/pw_checksum.crc32.cc.o.d  -Wno-psabi -Og -Wshadow -Wredundant-decls -Wswitch-enum -Wpedantic -Wno-c++20-designator -Wno-gnu-zero-variadic-macro-arguments -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -DPW_SPAN_ENABLE_ASSERTS=true -DPW_STATUS_CFG_CHECK_IF_USED=1  -I../pw_checksum/public -I../pw_bytes/public -I../pw_containers/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_preprocessor/public -I../pw_span/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_status/public -c ../pw_checksum/crc32.cc -o  pw_strict_host_gcc_debug/obj/pw_checksum/pw_checksum.crc32.cc.o',
1040                'directory': 'pigweed/pigweed/out',
1041                'file': '../pw_checksum/crc32.cc',
1042                'output': 'pw_strict_host_gcc_debug/obj/pw_checksum/pw_checksum.crc32.cc.o',
1043                # pylint: enable=line-too-long
1044            },
1045        ]
1046
1047        return super().setUp()
1048
1049    def test_merge(self):
1050        compdb1 = CppCompilationDatabase.load(
1051            self.fixture_merge_1, self.root_dir
1052        )
1053        compdb2 = CppCompilationDatabase.load(
1054            self.fixture_merge_2, self.root_dir
1055        )
1056        compdb1.merge(compdb2)
1057        result = [compile_command.as_dict() for compile_command in compdb1]
1058        expected = [*self.fixture_merge_1, *self.fixture_merge_2]
1059        self.assertCountEqual(result, expected)
1060
1061    def test_merge_no_dupes(self):
1062        compdb1 = CppCompilationDatabase.load(
1063            self.fixture_merge_1, self.root_dir
1064        )
1065        fixture_combo = [*self.fixture_merge_1, *self.fixture_merge_2]
1066        compdb2 = CppCompilationDatabase.load(fixture_combo, self.root_dir)
1067        compdb1.merge(compdb2)
1068        result = [compile_command.as_dict() for compile_command in compdb1]
1069        expected = [*self.fixture_merge_1, *self.fixture_merge_2]
1070        self.assertCountEqual(result, expected)
1071
1072    def test_load_from_dicts(self):
1073        compdb = CppCompilationDatabase.load(self.fixture, self.root_dir)
1074        self.assertCountEqual(compdb.as_dicts(), self.expected)
1075
1076    def test_load_from_json(self):
1077        compdb = CppCompilationDatabase.load(
1078            json.dumps(self.fixture), self.root_dir
1079        )
1080        self.assertCountEqual(compdb.as_dicts(), self.expected)
1081
1082    def test_load_from_path(self):
1083        with self.make_temp_file(
1084            COMPDB_FILE_NAME,
1085            json.dumps(self.fixture),
1086        ) as (_, file_path):
1087            path = file_path
1088
1089        compdb = CppCompilationDatabase.load(path, self.root_dir)
1090        self.assertCountEqual(compdb.as_dicts(), self.expected)
1091
1092    def test_load_from_file_handle(self):
1093        with self.make_temp_file(
1094            COMPDB_FILE_NAME,
1095            json.dumps(self.fixture),
1096        ) as (file, _):
1097            compdb = CppCompilationDatabase.load(file, self.root_dir)
1098
1099        self.assertCountEqual(compdb.as_dicts(), self.expected)
1100
1101    def test_process(self):
1102        """Test processing against a typical sample of raw output from GN."""
1103
1104        targets = [
1105            'pw_strict_host_clang_debug',
1106            'stm32f429i_disc1_debug',
1107            'isosceles_debug',
1108        ]
1109
1110        settings = self.make_ide_settings(targets_include=targets)
1111
1112        # pylint: disable=line-too-long
1113        raw_db: list[CppCompileCommandDict] = [
1114            {
1115                'command': 'arm-none-eabi-g++ -MMD -MF stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o.d -Wno-psabi -mabi=aapcs -mthumb --sysroot=../environment/cipd/packages/arm -specs=nano.specs -specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Og -Wshadow -Wredundant-decls -u_printf_float -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -DPW_ARMV7M_ENABLE_FPU=1  -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/assert_compatibility_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
1116                'directory': str(self.root_dir),
1117                'file': '../pw_allocator/block.cc',
1118            },
1119            {
1120                'command': '../environment/cipd/packages/pigweed/bin/isosceles-clang++ -MMD -MF isosceles_debug/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o isosceles_debug/obj/pw_allocator/block.block.cc.o',
1121                'directory': str(self.root_dir),
1122                'file': '../pw_allocator/block.cc',
1123            },
1124            {
1125                'command': 'ccache ../environment/cipd/packages/pigweed/bin/clang++ -MMD -MF pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o  pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
1126                'directory': str(self.root_dir),
1127                'file': '../pw_allocator/block.cc',
1128            },
1129            {
1130                'command': "python ../pw_toolchain/py/pw_toolchain/clang_tidy.py --source-exclude 'third_party/.*' --source-exclude '.*packages/mbedtls.*' --source-exclude '.*packages/boringssl.*' --skip-include-path 'mbedtls/include' --skip-include-path 'mbedtls' --skip-include-path 'boringssl/src/include' --skip-include-path 'boringssl' --skip-include-path 'pw_tls_client/generate_test_data' --source-file ../pw_allocator/block.cc --source-root '../' --export-fixes  pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o.yaml -- ../environment/cipd/packages/pigweed/bin/clang++ END_OF_INVOKER -MMD -MF pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o && touch pw_strict_host_clang_debug.static_analysis/obj/pw_allocator/block.block.cc.o",
1131                'directory': str(self.root_dir),
1132                'file': '../pw_allocator/block.cc',
1133            },
1134        ]
1135
1136        expected_compdbs = {
1137            'isosceles_debug': [
1138                {
1139                    'command':
1140                    # Ensures path format matches OS (e.g. Windows)
1141                    f'{Path("../environment/cipd/packages/pigweed/bin/isosceles-clang++")} -MMD -MF isosceles_debug/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o isosceles_debug/obj/pw_allocator/block.block.cc.o',
1142                    'directory': str(self.root_dir),
1143                    'file': '../pw_allocator/block.cc',
1144                    'output': 'isosceles_debug/obj/pw_allocator/block.block.cc.o',
1145                },
1146            ],
1147            'pw_strict_host_clang_debug': [
1148                {
1149                    'command':
1150                    # Ensures path format matches OS (e.g. Windows)
1151                    f'ccache {Path("../environment/cipd/packages/pigweed/bin/clang++")} -MMD -MF pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o.d -g3 --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Og -Wshadow -Wredundant-decls -Wthread-safety -Wswitch-enum -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -DPW_STATUS_CFG_CHECK_IF_USED=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
1152                    'directory': str(self.root_dir),
1153                    'file': '../pw_allocator/block.cc',
1154                    'output': 'pw_strict_host_clang_debug/obj/pw_allocator/block.block.cc.o',
1155                },
1156            ],
1157            'stm32f429i_disc1_debug': [
1158                {
1159                    'command':
1160                    # Ensures this test avoids the unpathed compiler search
1161                    f'{self.temp_dir_path / "arm-none-eabi-g++"} -MMD -MF stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o.d -Wno-psabi -mabi=aapcs -mthumb --sysroot=../environment/cipd/packages/arm -specs=nano.specs -specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Og -Wshadow -Wredundant-decls -u_printf_float -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register -DPW_ARMV7M_ENABLE_FPU=1 -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/assert_compatibility_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
1162                    'directory': str(self.root_dir),
1163                    'file': '../pw_allocator/block.cc',
1164                    'output': 'stm32f429i_disc1_debug/obj/pw_allocator/block.block.cc.o',
1165                },
1166            ],
1167        }
1168        # pylint: enable=line-too-long
1169
1170        compdbs = CppCompilationDatabase.load(
1171            raw_db, root_dir=self.root_dir
1172        ).process(settings, default_path=self.temp_dir_path)
1173        compdbs_as_dicts = {
1174            target: compdb.as_dicts() for target, compdb in compdbs.items()
1175        }
1176
1177        self.assertCountEqual(
1178            list(compdbs_as_dicts.keys()), list(expected_compdbs.keys())
1179        )
1180        self.assertDictEqual(compdbs_as_dicts, expected_compdbs)
1181
1182
1183class TestCppCompilationDatabasesMap(PwIdeTestCase):
1184    """Tests CppCompilationDatabasesMap"""
1185
1186    def setUp(self):
1187        # pylint: disable=line-too-long
1188        self.fixture_1 = lambda target: [
1189            CppCompileCommand(
1190                **{
1191                    'command': f'g++ -MMD -MF  {target}/obj/pw_allocator/block.block.cc.o.d  -Wno-psabi -Og -Wshadow -Wredundant-decls -Wswitch-enum -Wpedantic -Wno-c++20-designator -Wno-gnu-zero-variadic-macro-arguments -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -DPW_SPAN_ENABLE_ASSERTS=true -DPW_STATUS_CFG_CHECK_IF_USED=1  -I../pw_allocator/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_span/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_status/public -c ../pw_allocator/block.cc -o  pw_strict_host_gcc_debug/obj/pw_allocator/block.block.cc.o',
1192                    'directory': '/pigweed/pigweed/out',
1193                    'file': '../pw_allocator/block.cc',
1194                }
1195            ),
1196            CppCompileCommand(
1197                **{
1198                    'command': f'g++ -MMD -MF  {target}/obj/pw_allocator/freelist.freelist.cc.o.d  -Wno-psabi -Og -Wshadow -Wredundant-decls -Wswitch-enum -Wpedantic -Wno-c++20-designator -Wno-gnu-zero-variadic-macro-arguments -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=//pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -DPW_SPAN_ENABLE_ASSERTS=true -DPW_STATUS_CFG_CHECK_IF_USED=1  -I../pw_allocator/public -I../pw_containers/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_span/public -I../pw_status/public -c ../pw_allocator/freelist.cc -o  pw_strict_host_gcc_debug/obj/pw_allocator/freelist.freelist.cc.o',
1199                    'directory': '/pigweed/pigweed/out',
1200                    'file': '../pw_allocator/freelist.cc',
1201                }
1202            ),
1203        ]
1204
1205        self.fixture_2 = lambda target: [
1206            CppCompileCommand(
1207                **{
1208                    'command': f'g++ -MMD -MF  {target}/obj/pw_base64/pw_base64.base64.cc.o.d  -Wno-psabi -Og -Wshadow -Wredundant-decls -Wswitch-enum -Wpedantic -Wno-c++20-designator -Wno-gnu-zero-variadic-macro-arguments -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -DPW_SPAN_ENABLE_ASSERTS=true  -I../pw_base64/public -I../pw_string/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_preprocessor/public -I../pw_assert_basic/public_overrides -I../pw_assert_basic/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_span/public -c ../pw_base64/base64.cc -o  pw_strict_host_gcc_debug/obj/pw_base64/pw_base64.base64.cc.o',
1209                    'directory': '/pigweed/pigweed/out',
1210                    'file': '../pw_base64/base64.cc',
1211                }
1212            ),
1213            CppCompileCommand(
1214                **{
1215                    'command': f'g++ -MMD -MF  {target}/obj/pw_checksum/pw_checksum.crc32.cc.o.d  -Wno-psabi -Og -Wshadow -Wredundant-decls -Wswitch-enum -Wpedantic -Wno-c++20-designator -Wno-gnu-zero-variadic-macro-arguments -fdiagnostics-color -g -fno-common -fno-exceptions -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough -Wcast-qual -Wundef -Wpointer-arith -Werror -Wno-error=cpp -Wno-error=deprecated-declarations -ffile-prefix-map=/pigweed/pigweed/out=out -ffile-prefix-map=/pigweed/pigweed/= -ffile-prefix-map=../= -ffile-prefix-map=/pigweed/pigweed/out=out  -Wextra-semi -fno-rtti -Wnon-virtual-dtor -std=c++17 -Wno-register  -DPW_SPAN_ENABLE_ASSERTS=true -DPW_STATUS_CFG_CHECK_IF_USED=1  -I../pw_checksum/public -I../pw_bytes/public -I../pw_containers/public -I../pw_polyfill/public -I../pw_polyfill/standard_library_public -I../pw_preprocessor/public -I../pw_span/public -I../pw_assert/public -I../pw_assert/print_and_abort_assert_public_overrides -I../pw_status/public -c ../pw_checksum/crc32.cc -o  pw_strict_host_gcc_debug/obj/pw_checksum/pw_checksum.crc32.cc.o',
1216                    'directory': 'pigweed/pigweed/out',
1217                    'file': '../pw_checksum/crc32.cc',
1218                }
1219            ),
1220        ]
1221        # pylint: enable=line-too-long
1222        super().setUp()
1223
1224    def test_merge_0_db_set(self):
1225        with self.assertRaises(ValueError):
1226            CppCompilationDatabasesMap.merge()
1227
1228    def test_merge_1_db_set(self):
1229        settings = self.make_ide_settings()
1230        target = 'test_target'
1231        db_set = CppCompilationDatabasesMap(settings)
1232        db_set[target] = self.fixture_1(target)
1233        result = CppCompilationDatabasesMap.merge(db_set)
1234        self.assertCountEqual(result._dbs, db_set._dbs)
1235
1236    def test_merge_2_db_sets_different_targets(self):
1237        settings = self.make_ide_settings()
1238        target1 = 'test_target_1'
1239        target2 = 'test_target_2'
1240        db_set1 = CppCompilationDatabasesMap(settings)
1241        db_set1[target1] = self.fixture_1(target1)
1242        db_set2 = CppCompilationDatabasesMap(settings)
1243        db_set2[target2] = self.fixture_2(target2)
1244        result = CppCompilationDatabasesMap.merge(db_set1, db_set2)
1245        self.assertEqual(len(result), 2)
1246        self.assertCountEqual(result._dbs, {**db_set1._dbs, **db_set2._dbs})
1247
1248    def test_merge_2_db_sets_duplicated_targets(self):
1249        settings = self.make_ide_settings()
1250        target1 = 'test_target_1'
1251        target2 = 'test_target_2'
1252        db_set1 = CppCompilationDatabasesMap(settings)
1253        db_set1[target1] = self.fixture_1(target1)
1254        db_set2 = CppCompilationDatabasesMap(settings)
1255        db_set2[target2] = self.fixture_2(target2)
1256        db_set_combo = CppCompilationDatabasesMap.merge(db_set1, db_set2)
1257        result = CppCompilationDatabasesMap.merge(db_set1, db_set_combo)
1258        self.assertEqual(len(result), 2)
1259        self.assertCountEqual(result._dbs, {**db_set1._dbs, **db_set2._dbs})
1260
1261    def test_cascade_disabled(self):
1262        settings = self.make_ide_settings(
1263            cascade_targets=False,
1264            targets_include=['test_target_1', 'test_target_2'],
1265        )
1266        target1 = 'test_target_1'
1267        target2 = 'test_target_2'
1268        db_set = CppCompilationDatabasesMap(settings)
1269        db_set[target1] = self.fixture_1(target1)
1270        db_set[target2] = self.fixture_2(target2)
1271        result = db_set._compdb_to_write(target1)
1272        self.assertCountEqual(result._db, [*db_set[target1]])
1273
1274    def test_cascade_enabled(self):
1275        settings = self.make_ide_settings(
1276            cascade_targets=True,
1277            targets_include=['test_target_1', 'test_target_2'],
1278        )
1279        target1 = 'test_target_1'
1280        target2 = 'test_target_2'
1281        db_set = CppCompilationDatabasesMap(settings)
1282        db_set[target1] = self.fixture_1(target1)
1283        db_set[target2] = self.fixture_2(target2)
1284        result = db_set._compdb_to_write(target1)
1285        self.assertCountEqual(result._db, [*db_set[target1], *db_set[target2]])
1286
1287
1288class TestCppIdeFeaturesState(PwIdeTestCase):
1289    """Test CppIdeFeaturesState"""
1290
1291    def test_targets_all(self):
1292        all_targets = {
1293            "a": CppIdeFeaturesTarget("a", Path("/dev/null"), 1),
1294            "b": CppIdeFeaturesTarget("b", Path("/dev/null"), 1),
1295            "c": CppIdeFeaturesTarget("c", Path("/dev/null"), 1),
1296        }
1297
1298        settings = self.make_ide_settings()
1299        state = CppIdeFeaturesState(settings)
1300        state.targets = all_targets
1301        self.assertListEqual(list(state.targets.keys()), ["a", "b", "c"])
1302
1303    def test_targets_exclude(self):
1304        all_targets = {
1305            "a": CppIdeFeaturesTarget("a", Path("/dev/null"), 1),
1306            "b": CppIdeFeaturesTarget("b", Path("/dev/null"), 1),
1307            "c": CppIdeFeaturesTarget("c", Path("/dev/null"), 1),
1308        }
1309
1310        settings = self.make_ide_settings(targets_exclude=["a"])
1311        state = CppIdeFeaturesState(settings)
1312        state.targets = all_targets
1313        self.assertListEqual(list(state.targets.keys()), ["b", "c"])
1314
1315    def test_targets_include(self):
1316        all_targets = {
1317            "a": CppIdeFeaturesTarget("a", Path("/dev/null"), 1),
1318            "b": CppIdeFeaturesTarget("b", Path("/dev/null"), 1),
1319            "c": CppIdeFeaturesTarget("c", Path("/dev/null"), 1),
1320        }
1321
1322        settings = self.make_ide_settings(targets_include=["a"])
1323        state = CppIdeFeaturesState(settings)
1324        state.targets = all_targets
1325        self.assertListEqual(list(state.targets.keys()), ["a"])
1326
1327
1328if __name__ == '__main__':
1329    unittest.main()
1330