diff options
Diffstat (limited to 'tests/scripts/format.py')
-rw-r--r-- | tests/scripts/format.py | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/tests/scripts/format.py b/tests/scripts/format.py index 50a0d3dc70..9736c033b2 100644 --- a/tests/scripts/format.py +++ b/tests/scripts/format.py @@ -176,30 +176,52 @@ def main(argv): my_env["PATH"] += os.pathsep + jitutilsBin current_dir = os.getcwd() - if os.path.isdir(jitutilsBin): - os.chdir(jitutilsBin) - else: + if not os.path.isdir(jitutilsBin): print("Jitutils not built!") return -1 - jitformat = "" + jitformat = jitutilsBin if platform == 'Linux' or platform == 'OSX': - jitformat = "jit-format" + jitformat = os.path.join(jitformat, "jit-format") elif platform == 'Windows_NT': - jitformat = "jit-format.cmd" + jitformat = os.path.join(jitformat,"jit-format.bat") + errorMessage = "" + + builds = ["Checked", "Debug", "Release"] + projects = ["dll", "standalone", "crossgen"] - for build in ["Checked", "Debug", "Release"]: - for project in ["dll", "standalone", "crossgen"]: + for build in builds: + for project in projects: proc = subprocess.Popen([jitformat, "-a", arch, "-b", build, "-o", platform, "-c", coreclr, "--verbose", "--projects", project], env=my_env) output,error = proc.communicate() errorcode = proc.returncode if errorcode != 0: + errorMessage += "\tjit-format -a " + arch + " -b " + build + " -o " + platform + errorMessage += " -c <absolute-path-to-coreclr> --verbose --fix --projects " + project +"\n" returncode = errorcode + # Fix mode doesn't return an error, so we have to run the build, then run with + # --fix to generate the patch. This means that it is likely only the first run + # of jit-format will return a formatting failure. + if errorcode == -2: + # If errorcode was -2, no need to run clang-tidy again + proc = subprocess.Popen([jitformat, "--fix", "--untidy", "-a", arch, "-b", build, "-o", platform, "-c", coreclr, "--verbose", "--projects", project], env=my_env) + output,error = proc.communicate() + else: + # Otherwise, must run both + proc = subprocess.Popen([jitformat, "--fix", "-a", arch, "-b", build, "-o", platform, "-c", coreclr, "--verbose", "--projects", project], env=my_env) + output,error = proc.communicate() + os.chdir(current_dir) + if returncode != 0: + # Create a patch file + patchFile = open("format.patch", "w") + proc = subprocess.Popen(["git", "diff", "--patch", "-U20"], env=my_env, stdout=patchFile) + output,error = proc.communicate() + if os.path.isdir(jitUtilsPath): print("Deleting " + jitUtilsPath) shutil.rmtree(jitUtilsPath, onerror=del_rw) @@ -212,6 +234,14 @@ def main(argv): print("Deleting " + bootstrapPath) os.remove(bootstrapPath) + if returncode != 0: + buildUrl = my_env["BUILD_URL"] + print("There were errors in formatting. Please run jit-format locally with: \n") + print(errorMessage) + print("\nOr download and apply generated patch:") + print("wget " + buildUrl + "artifact/format.patch") + print("git apply format.patch") + return returncode if __name__ == '__main__': |