|
31 | 31 | import shutil
|
32 | 32 | import sys
|
33 | 33 | import tempfile
|
| 34 | +import time |
34 | 35 | from argparse import ArgumentParser
|
35 | 36 |
|
36 | 37 | import mx
|
@@ -1019,12 +1020,52 @@ def python_coverage(args):
|
1019 | 1020 | mx.command_function("jacocoreport")(["--omit-excluded", "--format=html"])
|
1020 | 1021 |
|
1021 | 1022 |
|
| 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 | + |
1022 | 1062 | # ----------------------------------------------------------------------------------------------------------------------
|
1023 | 1063 | #
|
1024 | 1064 | # register the suite commands (if any)
|
1025 | 1065 | #
|
1026 | 1066 | # ----------------------------------------------------------------------------------------------------------------------
|
1027 | 1067 | mx.update_commands(SUITE, {
|
| 1068 | + 'python-build-watch': [python_build_watch, ''], |
1028 | 1069 | 'python': [python, '[Python args|@VM options]'],
|
1029 | 1070 | 'python3': [python, '[Python args|@VM options]'],
|
1030 | 1071 | 'deploy-binary-if-master': [deploy_binary_if_master, ''],
|
|
0 commit comments