Bug 1816443 - Use auto-bootstrap code to bootstrap clang-tidy in both bootstrap and code-analysis. r=andi,firefox-build-system-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D168962
This commit is contained in:
Mike Hommey 2023-02-16 22:06:01 +00:00
Родитель 383759bb16
Коммит 0ea0ba74cc
12 изменённых файлов: 13 добавлений и 109 удалений

Просмотреть файл

@ -142,6 +142,11 @@ def bootstrap_path(path, **kwargs):
if not path: if not path:
return return
path_parts = path.split("/") path_parts = path.split("/")
path_prefix = ""
# Small hack until clang-tidy stops being a separate toolchain in a
# weird location.
if path_parts[0] == "clang-tools":
path_prefix = path_parts.pop(0)
def try_bootstrap(exists): def try_bootstrap(exists):
if not tasks: if not tasks:
@ -228,9 +233,9 @@ def bootstrap_path(path, **kwargs):
log.info( log.info(
"%s bootstrapped toolchain in %s", "%s bootstrapped toolchain in %s",
"Updating" if exists else "Installing", "Updating" if exists else "Installing",
os.path.join(toolchains_base_dir, path_parts[0]), os.path.join(toolchains_base_dir, path_prefix, path_parts[0]),
) )
os.makedirs(toolchains_base_dir, exist_ok=True) os.makedirs(os.path.join(toolchains_base_dir, path_prefix), exist_ok=True)
subprocess.run( subprocess.run(
[ [
sys.executable, sys.executable,
@ -238,7 +243,7 @@ def bootstrap_path(path, **kwargs):
"--log-no-times", "--log-no-times",
] ]
+ command, + command,
cwd=toolchains_base_dir, cwd=os.path.join(toolchains_base_dir, path_prefix),
check=True, check=True,
) )
ensureParentDir(index_file) ensureParentDir(index_file)
@ -246,7 +251,7 @@ def bootstrap_path(path, **kwargs):
fh.write(task_index) fh.write(task_index)
return True return True
path = os.path.join(toolchains_base_dir, *path_parts) path = os.path.join(toolchains_base_dir, path_prefix, *path_parts)
if bootstrap: if bootstrap:
try: try:
if not try_bootstrap(os.path.exists(path)): if not try_bootstrap(os.path.exists(path)):

Просмотреть файл

@ -333,27 +333,12 @@ class BaseBootstrapper(object):
% __name__ % __name__
) )
def ensure_clang_static_analysis_package(self):
"""
Install the clang static analysis package
"""
raise NotImplementedError(
"%s does not yet implement ensure_clang_static_analysis_package()"
% __name__
)
def ensure_sccache_packages(self): def ensure_sccache_packages(self):
""" """
Install sccache. Install sccache.
""" """
pass pass
def install_toolchain_static_analysis(self, toolchain_job):
clang_tools_path = self.state_dir / "clang-tools"
if not clang_tools_path.exists():
clang_tools_path.mkdir()
self.install_toolchain_artifact_impl(clang_tools_path, toolchain_job)
def install_toolchain_artifact(self, toolchain_job, no_unpack=False): def install_toolchain_artifact(self, toolchain_job, no_unpack=False):
if no_unpack: if no_unpack:
return self.install_toolchain_artifact_impl( return self.install_toolchain_artifact_impl(

Просмотреть файл

@ -261,7 +261,7 @@ class Bootstrapper(object):
self.instance.install_toolchain_artifact("fix-stacks") self.instance.install_toolchain_artifact("fix-stacks")
self.instance.install_toolchain_artifact("minidump-stackwalk") self.instance.install_toolchain_artifact("minidump-stackwalk")
if not self.instance.artifact_mode: if not self.instance.artifact_mode:
self.instance.ensure_clang_static_analysis_package() self.instance.install_toolchain_artifact("clang-tools/clang-tidy")
self.instance.ensure_sccache_packages() self.instance.ensure_sccache_packages()
# Like 'ensure_browser_packages' or 'ensure_mobile_android_packages' # Like 'ensure_browser_packages' or 'ensure_mobile_android_packages'
getattr(self.instance, "ensure_%s_packages" % application)() getattr(self.instance, "ensure_%s_packages" % application)()

Просмотреть файл

@ -66,9 +66,5 @@ class FreeBSDBootstrapper(BaseBootstrapper):
def install_browser_artifact_mode_packages(self, mozconfig_builder): def install_browser_artifact_mode_packages(self, mozconfig_builder):
self.install_browser_packages(mozconfig_builder, artifact_mode=True) self.install_browser_packages(mozconfig_builder, artifact_mode=True)
def ensure_clang_static_analysis_package(self):
# TODO: we don't ship clang base static analysis for this platform
pass
def upgrade_mercurial(self, current): def upgrade_mercurial(self, current):
self.pkg_install("mercurial") self.pkg_install("mercurial")

Просмотреть файл

@ -13,23 +13,6 @@ def is_non_x86_64():
return platform.machine() != "x86_64" return platform.machine() != "x86_64"
class ClangStaticAnalysisInstall(object):
def __init__(self, **kwargs):
pass
def ensure_clang_static_analysis_package(self):
if is_non_x86_64():
print(
"Cannot install static analysis tools from taskcluster.\n"
"Please install these tools manually."
)
return
from mozboot import static_analysis
self.install_toolchain_static_analysis(static_analysis.LINUX_CLANG_TIDY)
class MobileAndroidBootstrapper(object): class MobileAndroidBootstrapper(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
pass pass
@ -80,10 +63,7 @@ class MobileAndroidBootstrapper(object):
return self.generate_mobile_android_mozconfig(artifact_mode=True) return self.generate_mobile_android_mozconfig(artifact_mode=True)
class LinuxBootstrapper( class LinuxBootstrapper(MobileAndroidBootstrapper):
ClangStaticAnalysisInstall,
MobileAndroidBootstrapper,
):
def __init__(self, **kwargs): def __init__(self, **kwargs):
pass pass

Просмотреть файл

@ -222,11 +222,6 @@ class MozillaBuildBootstrapper(BaseBootstrapper):
def generate_mobile_android_artifact_mode_mozconfig(self): def generate_mobile_android_artifact_mode_mozconfig(self):
return self.generate_mobile_android_mozconfig(artifact_mode=True) return self.generate_mobile_android_mozconfig(artifact_mode=True)
def ensure_clang_static_analysis_package(self):
from mozboot import static_analysis
self.install_toolchain_static_analysis(static_analysis.WINDOWS_CLANG_TIDY)
def ensure_sccache_packages(self): def ensure_sccache_packages(self):
from mozboot import sccache from mozboot import sccache

Просмотреть файл

@ -32,7 +32,3 @@ class OpenBSDBootstrapper(BaseBootstrapper):
def install_browser_artifact_mode_packages(self, mozconfig_builder): def install_browser_artifact_mode_packages(self, mozconfig_builder):
self.install_browser_packages(mozconfig_builder, artifact_mode=True) self.install_browser_packages(mozconfig_builder, artifact_mode=True)
def ensure_clang_static_analysis_package(self):
# TODO: we don't ship clang base static analysis for this platform
pass

Просмотреть файл

@ -164,9 +164,6 @@ class OSXBootstrapperLight(OSXAndroidBootstrapper, BaseBootstrapper):
def install_browser_artifact_mode_packages(self, mozconfig_builder): def install_browser_artifact_mode_packages(self, mozconfig_builder):
pass pass
def ensure_clang_static_analysis_package(self):
pass
class OSXBootstrapper(OSXAndroidBootstrapper, BaseBootstrapper): class OSXBootstrapper(OSXAndroidBootstrapper, BaseBootstrapper):
def __init__(self, version, **kwargs): def __init__(self, version, **kwargs):
@ -272,16 +269,6 @@ class OSXBootstrapper(OSXAndroidBootstrapper, BaseBootstrapper):
if not homebrew_found: if not homebrew_found:
self.install_homebrew() self.install_homebrew()
def ensure_clang_static_analysis_package(self):
from mozboot import static_analysis
if platform.machine() == "arm64":
self.install_toolchain_static_analysis(
static_analysis.MACOS_AARCH64_CLANG_TIDY
)
else:
self.install_toolchain_static_analysis(static_analysis.MACOS_CLANG_TIDY)
def ensure_sccache_packages(self): def ensure_sccache_packages(self):
from mozboot import sccache from mozboot import sccache

Просмотреть файл

@ -1,8 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
WINDOWS_CLANG_TIDY = "win64-clang-tidy"
LINUX_CLANG_TIDY = "linux64-clang-tidy"
MACOS_CLANG_TIDY = "macosx64-clang-tidy"
MACOS_AARCH64_CLANG_TIDY = "macosx64-aarch64-clang-tidy"

Просмотреть файл

@ -99,11 +99,6 @@ class WindowsBootstrapper(BaseBootstrapper):
"We do not support building Android on Windows. Sorry!" "We do not support building Android on Windows. Sorry!"
) )
def ensure_clang_static_analysis_package(self):
from mozboot import static_analysis
self.install_toolchain_static_analysis(static_analysis.WINDOWS_CLANG_TIDY)
def _update_package_manager(self): def _update_package_manager(self):
self.pacman_update() self.pacman_update()

Просмотреть файл

@ -1592,38 +1592,12 @@ def get_clang_tools(
if source: if source:
return _get_clang_tools_from_source(command_context, clang_paths, source) return _get_clang_tools_from_source(command_context, clang_paths, source)
from mozbuild.artifact_commands import artifact_toolchain
if not download_if_needed: if not download_if_needed:
return 0, clang_paths return 0, clang_paths
job, _ = command_context.platform from mozbuild.bootstrap import bootstrap_toolchain
if job is None: bootstrap_toolchain("clang-tools/clang-tidy")
raise Exception(
"The current platform isn't supported. "
"Currently only the following platforms are "
"supported: win32/win64, linux64 and macosx64."
)
job += "-clang-tidy"
# We want to unpack data in the clang-tidy mozbuild folder
currentWorkingDir = os.getcwd()
os.chdir(clang_paths._clang_tools_path)
rc = artifact_toolchain(
command_context,
verbose=verbose,
skip_cache=skip_cache,
from_build=[job],
no_unpack=False,
retry=0,
)
# Change back the cwd
os.chdir(currentWorkingDir)
if rc:
return rc, clang_paths
return 0 if _is_version_eligible(command_context, clang_paths) else 1, clang_paths return 0 if _is_version_eligible(command_context, clang_paths) else 1, clang_paths

Просмотреть файл

@ -123,7 +123,6 @@ def bootstrap_tasks(config, tasks):
"python/mozboot/mozboot/mozconfig.py", "python/mozboot/mozboot/mozconfig.py",
"python/mozboot/mozboot/rust.py", "python/mozboot/mozboot/rust.py",
"python/mozboot/mozboot/sccache.py", "python/mozboot/mozboot/sccache.py",
"python/mozboot/mozboot/static_analysis.py",
"python/mozboot/mozboot/util.py", "python/mozboot/mozboot/util.py",
] ]
+ [f"python/mozboot/mozboot/{f}" for f in os_specific] + [f"python/mozboot/mozboot/{f}" for f in os_specific]