diff options
| author | Marco Antognini <marco.antognini@arm.com> | 2019-09-25 14:15:34 +0000 |
|---|---|---|
| committer | Marco Antognini <marco.antognini@arm.com> | 2019-09-25 14:15:34 +0000 |
| commit | aefdc1e37a840f6448989cbce7b76831b818cc67 (patch) | |
| tree | 281e62236e009d1e7ec006159884e409f1526a9c | |
| parent | 194117f04ba09f5770be9770a0c2b2324265cd4b (diff) | |
| download | bcm5719-llvm-aefdc1e37a840f6448989cbce7b76831b818cc67.tar.gz bcm5719-llvm-aefdc1e37a840f6448989cbce7b76831b818cc67.zip | |
[gn build] Fix Python DeprecationWarning
Summary:
This fixes two issues:
- DeprecationWarning: invalid escape sequence \`
- ResourceWarning: unclosed file
Subscribers: mgorny, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67753
llvm-svn: 372876
| -rwxr-xr-x | llvm/utils/gn/build/write_cmake_config.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/utils/gn/build/write_cmake_config.py b/llvm/utils/gn/build/write_cmake_config.py index d57435285d1..d76d14b6510 100755 --- a/llvm/utils/gn/build/write_cmake_config.py +++ b/llvm/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 @@ def main(): # 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 @@ def main(): 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) |

