From 502ea8a095e6ac493d85feb147ed28656f65f750 Mon Sep 17 00:00:00 2001 From: Bastien Abadie Date: Tue, 2 Apr 2019 14:00:30 +0000 Subject: [PATCH] Bug 1538770 - Replace TRY_MODIFIED_FILES by mozversioncontrol usage, r=ahal Differential Revision: https://phabricator.services.mozilla.com/D24876 --HG-- extra : moz-landing-system : lando --- python/mozbuild/mozbuild/mach_commands.py | 19 +++++++++++++++++-- taskcluster/ci/source-test/clang.yml | 4 ++-- .../scripts/misc/source-test-clang-setup.sh | 4 ---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py index a08cfa8f2c5f..354ba54611d6 100644 --- a/python/mozbuild/mozbuild/mach_commands.py +++ b/python/mozbuild/mozbuild/mach_commands.py @@ -48,6 +48,7 @@ from mozbuild.backend import ( backends, ) +from mozversioncontrol import get_repository_object BUILD_WHAT_HELP = ''' What to build. Can be a top-level make target or a relative directory. If @@ -1701,8 +1702,10 @@ class StaticAnalysis(MachCommandBase): help='Write clang-tidy output in a file') @CommandArgument('--format', default='text', choices=('text', 'json'), help='Output format to write in a file') + @CommandArgument('--outgoing', default=False, action='store_true', + help='Run static analysis checks on outgoing files from mercurial repository') def check(self, source=None, jobs=2, strip=1, verbose=False, - checks='-*', fix=False, header_filter='', output=None, format='text'): + checks='-*', fix=False, header_filter='', output=None, format='text', outgoing=False): from mozbuild.controller.building import ( StaticAnalysisFooter, StaticAnalysisOutputManager, @@ -1717,6 +1720,12 @@ class StaticAnalysis(MachCommandBase): if rc != 0: return rc + # Use outgoing files instead of source files + if outgoing: + repo = get_repository_object(self.topsrcdir) + files = repo.get_outgoing_files() + source = self._conv_to_abspath(files) + # Split in several chunks to avoid hitting Python's limit of 100 groups in re compile_db = json.loads(open(self._compile_db, 'r').read()) total = 0 @@ -2406,11 +2415,17 @@ class StaticAnalysis(MachCommandBase): @CommandArgument('--format', '-f', choices=('diff', 'json'), default='diff', dest='output_format', help='Specify the output format used: diff is the raw patch provided by ' 'clang-format, json is a list of atomic changes to process.') - def clang_format(self, assume_filename, path, commit, output_path=None, output_format='diff', verbose=False): + @CommandArgument('--outgoing', default=False, action='store_true', + help='Run clang-format on outgoing files from mercurial repository') + def clang_format(self, assume_filename, path, commit, output_path=None, output_format='diff', verbose=False, outgoing=False): # Run clang-format or clang-format-diff on the local changes # or files/directories if path is not None: path = self._conv_to_abspath(path) + elif outgoing: + repo = get_repository_object(self.topsrcdir) + files = repo.get_outgoing_files() + path = self._conv_to_abspath(files) os.chdir(self.topsrcdir) diff --git a/taskcluster/ci/source-test/clang.yml b/taskcluster/ci/source-test/clang.yml index 84517ed5bf9d..b948954adc85 100644 --- a/taskcluster/ci/source-test/clang.yml +++ b/taskcluster/ci/source-test/clang.yml @@ -48,7 +48,7 @@ tidy: command: >- source $HOME/checkouts/gecko/taskcluster/scripts/misc/source-test-clang-setup.sh && cd $HOME/checkouts/gecko && - ./mach --log-no-times static-analysis check $TRY_MODIFIED_FILES --output $HOME/clang-tidy.json --format json + ./mach --log-no-times static-analysis check --outgoing --output $HOME/clang-tidy.json --format json worker: artifacts: @@ -64,7 +64,7 @@ format: command: >- source $HOME/checkouts/gecko/taskcluster/scripts/misc/source-test-clang-setup.sh && cd $HOME/checkouts/gecko && - ./mach --log-no-times clang-format --path $TRY_MODIFIED_FILES --output $HOME/clang-format.json --format json + ./mach --log-no-times clang-format --outgoing --output $HOME/clang-format.json --format json worker: artifacts: - type: file diff --git a/taskcluster/scripts/misc/source-test-clang-setup.sh b/taskcluster/scripts/misc/source-test-clang-setup.sh index bc98ceebd885..44880ab1fd4c 100755 --- a/taskcluster/scripts/misc/source-test-clang-setup.sh +++ b/taskcluster/scripts/misc/source-test-clang-setup.sh @@ -22,7 +22,3 @@ export LD_LIBRARY_PATH=$MOZBUILD_STATE_PATH/clang/lib # Mach lookup clang-tidy in clang-tools mkdir -p $MOZBUILD_STATE_PATH/clang-tools ln -s $MOZBUILD_STATE_PATH/clang-tidy $MOZBUILD_STATE_PATH/clang-tools/clang-tidy - -# List modified files since last public revision -cd $HOME/checkouts/gecko -export TRY_MODIFIED_FILES=$(hg status --rev 'max(ancestors(tip) and public())' -q --no-status)