Skip to content

Commit

Permalink
[GR-32358] Add mx command to run commands on all repos.
Browse files Browse the repository at this point in the history
PullRequest: mx/1339
  • Loading branch information
zapster committed Sep 11, 2023
2 parents 5d5267c + a8e895b commit dc93f35
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 9 deletions.
14 changes: 7 additions & 7 deletions common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Jsonnet files should not include this file directly but use ci/common.jsonnet instead."
],

"mx_version": "6.45.0",
"mx_version": "6.46.1",

"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
"jdks": {
Expand Down Expand Up @@ -35,12 +35,12 @@
"labsjdk-ee-20-llvm": {"name": "labsjdk", "version": "ee-20.0.2+2-jvmci-23.1-b02-sulong", "platformspecific": true },

"oraclejdk21": {"name": "jpg-jdk", "version": "21", "build_id": "33", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]},
"labsjdk-ce-21": {"name": "labsjdk", "version": "ce-21+35-jvmci-23.1-b14", "platformspecific": true },
"labsjdk-ce-21Debug": {"name": "labsjdk", "version": "ce-21+35-jvmci-23.1-b14-debug", "platformspecific": true },
"labsjdk-ce-21-llvm": {"name": "labsjdk", "version": "ce-21+35-jvmci-23.1-b14-sulong", "platformspecific": true },
"labsjdk-ee-21": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b14", "platformspecific": true },
"labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b14-debug", "platformspecific": true },
"labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b14-sulong", "platformspecific": true },
"labsjdk-ce-21": {"name": "labsjdk", "version": "ce-21+35-jvmci-23.1-b15", "platformspecific": true },
"labsjdk-ce-21Debug": {"name": "labsjdk", "version": "ce-21+35-jvmci-23.1-b15-debug", "platformspecific": true },
"labsjdk-ce-21-llvm": {"name": "labsjdk", "version": "ce-21+35-jvmci-23.1-b15-sulong", "platformspecific": true },
"labsjdk-ee-21": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b15", "platformspecific": true },
"labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b15-debug", "platformspecific": true },
"labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b15-sulong", "platformspecific": true },

"oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "11", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]}
},
Expand Down
3 changes: 2 additions & 1 deletion mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18495,6 +18495,7 @@ def list_commands(l):
import mx_bisect # pylint: disable=unused-import
import mx_gc # pylint: disable=unused-import
import mx_multiplatform # pylint: disable=unused-import
import mx_foreach # pylint: disable=unused-import

from mx_unittest import unittest
from mx_jackpot import jackpot
Expand Down Expand Up @@ -18787,7 +18788,7 @@ def alarm_handler(signum, frame):
abort(1, killsig=signal.SIGINT)

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("6.46.1") # GR-48450: Read the value of the right argument.
version = VersionSpec("6.47.0") # for each repo

_mx_start_datetime = datetime.utcnow()
_last_timestamp = _mx_start_datetime
Expand Down
88 changes: 88 additions & 0 deletions mx_foreach.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# ----------------------------------------------------------------------------------------------------
#
# Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# ----------------------------------------------------------------------------------------------------
#
import argparse
import textwrap

import mx


@mx.command('mx', 'foreach-repo')
def foreach_repo(args):

parser = argparse.ArgumentParser(prog='mx foreach-repo',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''
Run a command in the root of all repos of imported suites.
Example:
$ mx foreach-repo pwd
Entering directory
Running: pwd
.../path/to/graalpython
Leaving directory
Entering directory
Running: pwd
.../path/to/graal
Leaving directory
'''.rstrip()),
usage='%(prog)s [options] [--] command...')
parser.add_argument('-n', '--dry-run', action='store_true', help='show what would be removed without actually doing anything')

try:
sep_idx = args.index('--')
parsed_args = parser.parse_args(args[:sep_idx])
remaining_args = args[(sep_idx + 1):]
except ValueError:
parsed_args, remaining_args = parser.parse_known_args(args)

p = mx.primary_suite()
suites = [p] + [mx.suite(i.name) for i in p.suite_imports]
vc_dirs = []
# ensure that we preserve the order
for x in suites:
if x.vc_dir not in vc_dirs:
vc_dirs.append(x.vc_dir)

def _log_cwd(msg):
mx.log(mx.colorize(msg, color='cyan'))

def _log_exec(msg):
mx.log(mx.colorize(msg, color='green'))

cmd = remaining_args
if len(cmd) == 0:
mx.abort(f'{parser.prog} requires a command...\n\n{parser.format_usage()}')
for vc_dir in vc_dirs:
_log_cwd('Entering directory `{}`'.format(vc_dir))
try:
if parsed_args.dry_run:
_log_exec('Would run: {}'.format(' '.join(cmd)))
else:
_log_exec('Running: {}'.format(' '.join(cmd)))
mx.run(cmd, cwd=vc_dir)
finally:
_log_cwd('Leaving directory `{}`'.format(vc_dir))
2 changes: 1 addition & 1 deletion mx_spotbugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def spotbugs(args, fbArgs=None, suite=None, projects=None, jarFileName='spotbugs
def _spotbugs(all_args, fbArgs, suite, projectsToTest, spotbugsVersion):
"""run FindBugs against non-test Java projects"""
parser = ArgumentParser(prog='mx spotbugs')
parser.add_argument('--strict-mode', action='store_true', help='abort if a spotbugs cannot be executed due some reason (e.g., unsupported JDK version)')
parser.add_argument('--strict-mode', action='store_true', help='abort if SpotBugs cannot be executed for some reason (e.g., unsupported JDK version)')
parsed_args, args = parser.parse_known_args(all_args)

findBugsHome = mx.get_env('SPOTBUGS_HOME', mx.get_env('FINDBUGS_HOME', None))
Expand Down

0 comments on commit dc93f35

Please sign in to comment.