| """Recipe for giving include-what-you-use (iwyu) suggestions on the given build.""" |
| |
| # TODO(mingcl): This recipe is WIP |
| |
| import logging |
| from slave import base_recipe |
| from slave import base_step |
| from slave.step import include_what_you_use_step |
| from slave.step import compdb_gen_step |
| from slave.step import cast_shell_step |
| from slave.step import unittest_step |
| from slave.recipe import clang_builder |
| |
| # Note that the keys are Gerrit project names. |
| # TODO(mingcl): Allow configuring build-specific filters to avoid reporting |
| # duplicate clang-tidy suggestions from different builds. |
| PROJECT_CONFIGS = { |
| 'chromecast/internal': { |
| 'deny_list_filter': [ |
| r'vendor/media/google3/(.*)', 'android/prebuilt', |
| r'(.*)/third_party/(.*)' |
| ] |
| }, |
| } |
| |
| BUILD_CONFIGS = { |
| 'audioassistant_x64_eng_iwyu': { |
| 'build_args_product': 'audioassistant_x64_eng', |
| 'build_args_official': False, |
| # TODO(b/145840052): Remove once the build is fast enough. |
| 'timeout_secs_build_gtests': 5 * 60 * 60, |
| # TODO(b/148885147) Remove params below |
| 'build_branding': 'chrome', |
| 'build_product': 'audio', |
| 'build_flavor': 'Debug', |
| 'build_arch': 'clang', |
| 'enable_assistant': True, |
| 'run_gtests': False, |
| }, |
| } |
| |
| # The name of build directory used by actual build recipe. |
| # Since the build directory name could change when the build recipe/script get |
| # changed, the best we can do is to update this dictionary when needed. |
| # This should be fine since clang tidy check is non-blocking. |
| BUILD_DIRECTORIES = { |
| 'audioassistant_x64_eng_iwyu': 'out_clang_audio_gn/Debug/', |
| } |
| |
| def GetValidBuildNames(): |
| return [ |
| 'audioassistant_x64_eng_iwyu', |
| ] |
| |
| |
| def CreateRecipe(build_name: str, **kwargs): |
| """Builds a recipe object.""" |
| # Extracts default_properties from build config and adds it to the overall |
| # properties in kwargs. |
| config = BUILD_CONFIGS[build_name] |
| return ClangTidyRecipe( |
| build_name, |
| build_config=config, |
| build_dir=BUILD_DIRECTORIES[build_name], |
| **kwargs) |
| |
| class ClangTidyRecipe(base_recipe.BaseRecipe): |
| """Recipe to clang-tidy a change.""" |
| |
| def __init__(self, build_name, build_config, build_dir, **kwargs): |
| base_recipe.BaseRecipe.__init__( |
| self, enable_build_accelerator=True, **kwargs) |
| self._properties = kwargs.get('properties', {}) |
| self._build_name = build_name |
| self._build_config = build_config |
| self._build_dir = build_dir |
| self._builder_kwargs = kwargs |
| |
| def get_steps(self): |
| allow_list_filter = PROJECT_CONFIGS.get(self._properties['patch_project'], |
| {}).get('allow_list_filter', None) |
| deny_list_filter = PROJECT_CONFIGS.get(self._properties['patch_project'], |
| {}).get('deny_list_filter', None) |
| |
| # Build cast shell and unittests to generate necessary header files |
| build_steps = clang_builder.ClangRecipe( |
| self._build_config, **self._builder_kwargs).get_steps() |
| |
| return build_steps + [ |
| # Generate compilation database from the build directory. |
| compdb_gen_step.CompdbGenStep( |
| build_dir=self._build_dir, **self._step_kwargs), |
| # Then iwyu can use the compilation database to analyze the code |
| include_what_you_use_step.IncludeWhatYouUseStep( |
| allow_list_filter=allow_list_filter, |
| deny_list_filter=deny_list_filter, |
| **self._step_kwargs), |
| ] |