Create patches in formatting job
authorMichelle McDaniel <adiaaida@gmail.com>
Tue, 8 Nov 2016 21:37:20 +0000 (13:37 -0800)
committerMichelle McDaniel <adiaaida@gmail.com>
Thu, 10 Nov 2016 22:25:41 +0000 (14:25 -0800)
In the formatting job, if there are formatting errors, we will run the
formatter in --fix mode and generate a patch which will be uploaded to
azure storage.

Commit migrated from https://github.com/dotnet/coreclr/commit/503de5e8dde3d996b06db41c0b46617cebbdee11

src/coreclr/netci.groovy
src/coreclr/tests/scripts/format.py

index 3bba51d..81d3ee7 100755 (executable)
@@ -1761,6 +1761,7 @@ combinedScenarios.each { scenario ->
                                     }
                                     else if (scenario == 'formatting') {
                                         buildCommands += "python -u tests\\scripts\\format.py -c %WORKSPACE% -o Windows_NT -a ${arch}"
+                                        Utilities.addArchival(newJob, "format.patch", "", true, false)
                                         break
                                     }
                                     else {
@@ -1972,6 +1973,7 @@ combinedScenarios.each { scenario ->
 
                                     if (scenario == 'formatting') {
                                         buildCommands += "python tests/scripts/format.py -c \${WORKSPACE} -o Linux -a ${arch}"
+                                        Utilities.addArchival(newJob, "format.patch", "", true, false)
                                         break
                                     }
                                 
index ae8348a..1cda283 100644 (file)
@@ -202,8 +202,26 @@ def main(argv):
                 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)
@@ -217,8 +235,12 @@ def main(argv):
         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 + "artifacts/format.patch")
+        print("git apply format.patch")
 
     return returncode