[PATCH] D67753: [gn build] Fix Python DeprecationWarning

Marco Antognini via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 07:14:44 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL372876: [gn build] Fix Python DeprecationWarning (authored by mantognini, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D67753?vs=220828&id=221761#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67753/new/

https://reviews.llvm.org/D67753

Files:
  llvm/trunk/utils/gn/build/write_cmake_config.py


Index: llvm/trunk/utils/gn/build/write_cmake_config.py
===================================================================
--- llvm/trunk/utils/gn/build/write_cmake_config.py
+++ llvm/trunk/utils/gn/build/write_cmake_config.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-"""Emulates the bits of CMake's configure_file() function needed in LLVM.
+r"""Emulates the bits of CMake's configure_file() function needed in LLVM.
 
 The CMake build uses configure_file() for several things.  This emulates that
 function for the GN build.  In the GN build, this runs at build time instead
@@ -62,7 +62,8 @@
     # Matches e.g. '${FOO}' or '@FOO@' and captures FOO in group 1 or 2.
     var_re = re.compile(r'\$\{([^}]*)\}|@([^@]*)@')
 
-    in_lines = open(args.input).readlines()
+    with open(args.input) as f:
+        in_lines = f.readlines()
     out_lines = []
     for in_line in in_lines:
         def repl(m):
@@ -102,8 +103,13 @@
             file=sys.stderr)
         return 1
 
-    if not os.path.exists(args.output) or open(args.output).read() != output:
-        open(args.output, 'w').write(output)
+    def read(filename):
+        with open(args.output) as f:
+            return f.read()
+
+    if not os.path.exists(args.output) or read(args.output) != output:
+        with open(args.output, 'w') as f:
+            f.write(output)
         os.chmod(args.output, os.stat(args.input).st_mode & 0o777)
 
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67753.221761.patch
Type: text/x-patch
Size: 1413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190925/07e044e5/attachment.bin>


More information about the llvm-commits mailing list