Skip to content

Commit 827f405

Browse files
committed
Add a little filesystem watcher for those of us not building everything with eclipse
1 parent 66f8db2 commit 827f405

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import shutil
3232
import sys
3333
import tempfile
34+
import time
3435
from argparse import ArgumentParser
3536

3637
import mx
@@ -1019,12 +1020,52 @@ def python_coverage(args):
10191020
mx.command_function("jacocoreport")(["--omit-excluded", "--format=html"])
10201021

10211022

1023+
def python_build_watch(args):
1024+
"""
1025+
Watch the suite and on any changes to .class, .jar, .h, or .c files rebuild.
1026+
By default, rebuilds only the archives and non-Java projects.
1027+
"""
1028+
parser = ArgumentParser(prog='mx python-build-watch')
1029+
parser.add_argument('--full', action='store_true', help='Run a full mx build', required=False)
1030+
parser.add_argument('--graalvm', action='store_true', help='Build a graalvm', required=False)
1031+
parser.add_argument('--no-java', action='store_true', help='Build only archives and native projects [default]', required=False)
1032+
args = parser.parse_args(args)
1033+
if sum([args.full, args.graalvm, args.no_java]) > 1:
1034+
mx.abort("Only one of --full, --graalvm, --no-java can be specified")
1035+
while True:
1036+
out = mx.OutputCapture()
1037+
mx.run([
1038+
"inotifywait", "-q", "-e", "close_write,moved_to", "-r", "--format=%f",
1039+
"--exclude", ".*\\.py$",
1040+
"@%s" % os.path.join(SUITE.dir, ".git"),
1041+
SUITE.dir
1042+
], out=out)
1043+
changed_file = out.data.strip()
1044+
mx.logv(changed_file)
1045+
suffixes = [".c", ".h", ".class", ".jar"]
1046+
if args.full:
1047+
suffixes.append(".java")
1048+
elif args.graalvm:
1049+
suffixes.extend([".java", ".py"])
1050+
if any(changed_file.endswith(ext) for ext in [".c", ".h", ".class", ".jar"]):
1051+
mx.log("Build needed ...")
1052+
time.sleep(2)
1053+
if args.full:
1054+
mx.command_function("build")()
1055+
elif args.graalvm:
1056+
mx.log(python_gvm())
1057+
else:
1058+
nativebuild([])
1059+
break
1060+
1061+
10221062
# ----------------------------------------------------------------------------------------------------------------------
10231063
#
10241064
# register the suite commands (if any)
10251065
#
10261066
# ----------------------------------------------------------------------------------------------------------------------
10271067
mx.update_commands(SUITE, {
1068+
'python-build-watch': [python_build_watch, ''],
10281069
'python': [python, '[Python args|@VM options]'],
10291070
'python3': [python, '[Python args|@VM options]'],
10301071
'deploy-binary-if-master': [deploy_binary_if_master, ''],

0 commit comments

Comments
 (0)