]> granicus.if.org Git - icu/commitdiff
ICU-21248 Adds line ending check to Travis CI check. The eol check fits
authorgnrunge <nrunge@google.com>
Wed, 23 Sep 2020 23:22:31 +0000 (16:22 -0700)
committerMarkus Scherer <markus.icu@gmail.com>
Thu, 24 Sep 2020 16:56:55 +0000 (09:56 -0700)
quite well into what the script is doing already.
Note that one file, 'testrunner.cmd', contains \r, which seems to
be acceptable since it is a Windows file.

tools/scripts/icu-file-utf8-check.py

index 9e30e3b48664bad13512e05f605bdc962d9a49d2..42b069326ebaf63826a5b1f13e3a956bcde20bf0 100755 (executable)
@@ -38,14 +38,18 @@ import getopt
 # all of icu/. Modify as needed.
 icu_directories_to_be_scanned = ["."]
 
+# Files that are allowed to contain \r line endings. If this list
+# grows too long consider a file instead.
+ignore_cr_in_files = [
+    "vendor/double-conversion/upstream/msvc/testrunner.cmd"
+    ]
+
 def runCommand(cmd):
     output_file = os.popen(cmd);
     output_text = output_file.read();
     exit_status = output_file.close();
-    if exit_status:
-        print('"', cmd, '" failed.  Exiting.', file=sys.stderr)
-        sys.exit(exit_status)
-    return output_text
+
+    return output_text, exit_status
 
 
 def usage():
@@ -80,6 +84,7 @@ def check_file(file_name, is_source):
 
 def main(argv):
     exit_status = 0
+    rc = 0
 
     try:
         opts, args = getopt.getopt(argv, "h", ("help"))
@@ -101,7 +106,10 @@ def main(argv):
 
     for dir in icu_directories_to_be_scanned:
         print('Scanning ' + dir)
-        output = runCommand(git_cmd.replace("DIR", dir))
+        cmd = git_cmd.replace("DIR", dir)
+        output, rc = runCommand(cmd)
+        if rc:
+            print('"', cmd, '" failed. Exiting.', file=sys.stderr)
         file_list = output.splitlines()
 
         for f in file_list:
@@ -116,6 +124,15 @@ def main(argv):
             if check_file(f, source_file) != 0:
                 exit_status = 1
 
+            # Lastly, check the line endings of the file.
+            # Note that 'grep' returns null if it reports a file,
+            # a non-null value otherwise.
+            output, rc = runCommand("grep -rPIl \"\\r\" " + f)
+            if (rc is None):
+                if f not in ignore_cr_in_files:
+                    print("File ", f, " has \\r line ending")
+                    exit_status = 1
+
     print(exit_status)
     sys.exit(exit_status)