diff options
Diffstat (limited to 'mesonbuild')
65 files changed, 196 insertions, 182 deletions
diff --git a/mesonbuild/ast/interpreter.py b/mesonbuild/ast/interpreter.py index b9dfc7b..99c6979 100644 --- a/mesonbuild/ast/interpreter.py +++ b/mesonbuild/ast/interpreter.py @@ -179,7 +179,7 @@ class AstInterpreter(InterpreterBase): if not os.path.isfile(absname): sys.stderr.write(f'Unable to find build file {buildfilename} --> Skipping\n') return - with open(absname, encoding='utf8') as f: + with open(absname, encoding='utf-8') as f: code = f.read() assert(isinstance(code, str)) try: diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index c489dce..21a6c83 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -374,7 +374,7 @@ class Backend: if not os.path.exists(outfileabs_tmp_dir): os.makedirs(outfileabs_tmp_dir) result.append(unity_src) - return open(outfileabs_tmp, 'w') + return open(outfileabs_tmp, 'w', encoding='utf-8') # For each language, generate unity source files and return the list for comp, srcs in compsrcs.items(): @@ -765,7 +765,7 @@ class Backend: content = f'#include "{os.path.basename(pch_header)}"' pch_file_tmp = pch_file + '.tmp' - with open(pch_file_tmp, 'w') as f: + with open(pch_file_tmp, 'w', encoding='utf-8') as f: f.write(content) mesonlib.replace_if_different(pch_file, pch_file_tmp) return pch_rel_to_build @@ -1019,7 +1019,7 @@ class Backend: ifilename = os.path.join(self.environment.get_build_dir(), 'depmf.json') ofilename = os.path.join(self.environment.get_prefix(), self.build.dep_manifest_name) mfobj = {'type': 'dependency manifest', 'version': '1.0', 'projects': self.build.dep_manifest} - with open(ifilename, 'w') as f: + with open(ifilename, 'w', encoding='utf-8') as f: f.write(json.dumps(mfobj)) # Copy file from, to, and with mode unchanged d.data.append(InstallDataBase(ifilename, ofilename, None, '')) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 192cef3..597789b 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -20,6 +20,7 @@ import subprocess from collections import OrderedDict from enum import Enum, unique import itertools +from textwrap import dedent from pathlib import PurePath, Path from functools import lru_cache @@ -462,10 +463,11 @@ class NinjaBackend(backends.Backend): return open(tempfilename, 'a', encoding='utf-8') filename = os.path.join(self.environment.get_scratch_dir(), 'incdetect.c') - with open(filename, 'w') as f: - f.write('''#include<stdio.h> -int dummy; -''') + with open(filename, 'w', encoding='utf-8') as f: + f.write(dedent('''\ + #include<stdio.h> + int dummy; + ''')) # The output of cl dependency information is language # and locale dependent. Any attempt at converting it to @@ -1215,7 +1217,7 @@ int dummy; manifest_path = os.path.join(self.get_target_private_dir(target), 'META-INF', 'MANIFEST.MF') manifest_fullpath = os.path.join(self.environment.get_build_dir(), manifest_path) os.makedirs(os.path.dirname(manifest_fullpath), exist_ok=True) - with open(manifest_fullpath, 'w') as manifest: + with open(manifest_fullpath, 'w', encoding='utf-8') as manifest: if any(target.link_targets): manifest.write('Class-Path: ') cp_paths = [os.path.join(self.get_target_dir(l), l.get_filename()) for l in target.link_targets] diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 5595fd0..7fcc324 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -206,7 +206,7 @@ class Vs2010Backend(backends.Backend): @staticmethod def touch_regen_timestamp(build_dir: str) -> None: - with open(Vs2010Backend.get_regen_stampfile(build_dir), 'w'): + with open(Vs2010Backend.get_regen_stampfile(build_dir), 'w', encoding='utf-8'): pass def get_vcvars_command(self): diff --git a/mesonbuild/cmake/fileapi.py b/mesonbuild/cmake/fileapi.py index 6773e9a..5d4d01a 100644 --- a/mesonbuild/cmake/fileapi.py +++ b/mesonbuild/cmake/fileapi.py @@ -51,7 +51,7 @@ class CMakeFileAPI: } query_file = self.request_dir / 'query.json' - query_file.write_text(json.dumps(query, indent=2)) + query_file.write_text(json.dumps(query, indent=2), encoding='utf-8') def load_reply(self) -> None: if not self.reply_dir.is_dir(): @@ -75,7 +75,7 @@ class CMakeFileAPI: # Debug output debug_json = self.build_dir / '..' / 'fileAPI.json' debug_json = debug_json.resolve() - debug_json.write_text(json.dumps(index, indent=2)) + debug_json.write_text(json.dumps(index, indent=2), encoding='utf-8') mlog.cmd_ci_include(debug_json.as_posix()) # parse the JSON @@ -313,7 +313,7 @@ class CMakeFileAPI: if not real_path.exists(): raise CMakeException(f'File "{real_path}" does not exist') - data = json.loads(real_path.read_text()) + data = json.loads(real_path.read_text(encoding='utf-8')) assert isinstance(data, dict) for i in data.keys(): assert isinstance(i, str) diff --git a/mesonbuild/cmake/toolchain.py b/mesonbuild/cmake/toolchain.py index f3e487d..1a6dcf0 100644 --- a/mesonbuild/cmake/toolchain.py +++ b/mesonbuild/cmake/toolchain.py @@ -66,8 +66,8 @@ class CMakeToolchain: def write(self) -> Path: if not self.toolchain_file.parent.exists(): self.toolchain_file.parent.mkdir(parents=True) - self.toolchain_file.write_text(self.generate()) - self.cmcache_file.write_text(self.generate_cache()) + self.toolchain_file.write_text(self.generate(), encoding='utf-8') + self.cmcache_file.write_text(self.generate_cache(), encoding='utf-8') mlog.cmd_ci_include(self.toolchain_file.as_posix()) return self.toolchain_file @@ -215,11 +215,11 @@ class CMakeToolchain: build_dir = Path(self.env.scratch_dir) / '__CMake_compiler_info__' build_dir.mkdir(parents=True, exist_ok=True) cmake_file = build_dir / 'CMakeLists.txt' - cmake_file.write_text(cmake_content) + cmake_file.write_text(cmake_content, encoding='utf-8') # Generate the temporary toolchain file temp_toolchain_file = build_dir / 'CMakeMesonTempToolchainFile.cmake' - temp_toolchain_file.write_text(CMakeToolchain._print_vars(self.variables)) + temp_toolchain_file.write_text(CMakeToolchain._print_vars(self.variables), encoding='utf-8') # Configure trace = CMakeTraceParser(self.cmakebin.version(), build_dir) diff --git a/mesonbuild/cmake/traceparser.py b/mesonbuild/cmake/traceparser.py index 23a1852..42ceec6 100644 --- a/mesonbuild/cmake/traceparser.py +++ b/mesonbuild/cmake/traceparser.py @@ -158,7 +158,7 @@ class CMakeTraceParser: if not self.requires_stderr(): if not self.trace_file_path.exists and not self.trace_file_path.is_file(): raise CMakeException('CMake: Trace file "{}" not found'.format(str(self.trace_file_path))) - trace = self.trace_file_path.read_text(errors='ignore') + trace = self.trace_file_path.read_text(errors='ignore', encoding='utf-8') if not trace: raise CMakeException('CMake: The CMake trace was not provided or is empty') diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index ff87819..52529f7 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -765,14 +765,14 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): if isinstance(code, str): srcname = os.path.join(tmpdirname, 'testfile.' + self.default_suffix) - with open(srcname, 'w') as ofile: + with open(srcname, 'w', encoding='utf-8') as ofile: ofile.write(code) # ccache would result in a cache miss no_ccache = True contents = code elif isinstance(code, mesonlib.File): srcname = code.fname - with open(code.fname) as f: + with open(code.fname, encoding='utf-8') as f: contents = f.read() # Construct the compiler command-line diff --git a/mesonbuild/compilers/cs.py b/mesonbuild/compilers/cs.py index 218942c..7ebb66d 100644 --- a/mesonbuild/compilers/cs.py +++ b/mesonbuild/compilers/cs.py @@ -87,7 +87,7 @@ class CsCompiler(BasicLinkerIsCompilerMixin, Compiler): src = 'sanity.cs' obj = 'sanity.exe' source_name = os.path.join(work_dir, src) - with open(source_name, 'w') as ofile: + with open(source_name, 'w', encoding='utf-8') as ofile: ofile.write(textwrap.dedent(''' public class Sanity { static public void Main () { diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py index 145b7c8..4c0d0a6 100644 --- a/mesonbuild/compilers/cuda.py +++ b/mesonbuild/compilers/cuda.py @@ -504,7 +504,7 @@ class CudaCompiler(Compiler): binname += '_cross' if self.is_cross else '' source_name = os.path.join(work_dir, sname) binary_name = os.path.join(work_dir, binname + '.exe') - with open(source_name, 'w') as ofile: + with open(source_name, 'w', encoding='utf-8') as ofile: ofile.write(code) # The Sanity Test for CUDA language will serve as both a sanity test diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 78d0f62..b5ec905 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -535,7 +535,7 @@ class DCompiler(Compiler): def sanity_check(self, work_dir: str, environment: 'Environment') -> None: source_name = os.path.join(work_dir, 'sanity.d') output_name = os.path.join(work_dir, 'dtest') - with open(source_name, 'w') as ofile: + with open(source_name, 'w', encoding='utf-8') as ofile: ofile.write('''void main() { }''') pc = subprocess.Popen(self.exelist + self.get_output_args(output_name) + self._get_target_arch_args() + [source_name], cwd=work_dir) pc.wait() diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index 8264638..925eff6 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -71,7 +71,7 @@ class FortranCompiler(CLikeCompiler, Compiler): if binary_name.is_file(): binary_name.unlink() - source_name.write_text('print *, "Fortran compilation is working."; end') + source_name.write_text('print *, "Fortran compilation is working."; end', encoding='utf-8') extra_flags: T.List[str] = [] extra_flags += environment.coredata.get_external_args(self.for_machine, self.language) diff --git a/mesonbuild/compilers/java.py b/mesonbuild/compilers/java.py index 77e1a9b..ab82450 100644 --- a/mesonbuild/compilers/java.py +++ b/mesonbuild/compilers/java.py @@ -70,7 +70,7 @@ class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler): src = 'SanityCheck.java' obj = 'SanityCheck' source_name = os.path.join(work_dir, src) - with open(source_name, 'w') as ofile: + with open(source_name, 'w', encoding='utf-8') as ofile: ofile.write(textwrap.dedent( '''class SanityCheck { public static void main(String[] args) { diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py index 3210dd7..09ad837 100644 --- a/mesonbuild/compilers/mixins/clike.py +++ b/mesonbuild/compilers/mixins/clike.py @@ -306,7 +306,7 @@ class CLikeCompiler(Compiler): binname += '.exe' # Write binary check source binary_name = os.path.join(work_dir, binname) - with open(source_name, 'w') as ofile: + with open(source_name, 'w', encoding='utf-8') as ofile: ofile.write(code) # Compile sanity check # NOTE: extra_flags must be added at the end. On MSVC, it might contain a '/link' argument diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py index 6a7bd04..2b566c8 100644 --- a/mesonbuild/compilers/rust.py +++ b/mesonbuild/compilers/rust.py @@ -65,7 +65,7 @@ class RustCompiler(Compiler): def sanity_check(self, work_dir: str, environment: 'Environment') -> None: source_name = os.path.join(work_dir, 'sanity.rs') output_name = os.path.join(work_dir, 'rusttest') - with open(source_name, 'w') as ofile: + with open(source_name, 'w', encoding='utf-8') as ofile: ofile.write(textwrap.dedent( '''fn main() { } diff --git a/mesonbuild/compilers/swift.py b/mesonbuild/compilers/swift.py index 7b18591..2d52e21 100644 --- a/mesonbuild/compilers/swift.py +++ b/mesonbuild/compilers/swift.py @@ -107,7 +107,7 @@ class SwiftCompiler(Compiler): extra_flags += self.get_compile_only_args() else: extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language) - with open(source_name, 'w') as ofile: + with open(source_name, 'w', encoding='utf-8') as ofile: ofile.write('''print("Swift compilation is working.") ''') pc = subprocess.Popen(self.exelist + extra_flags + ['-emit-executable', '-o', output_name, src], cwd=work_dir) diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index a0ee7df..97edeb2 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -481,8 +481,8 @@ class CoreData: # the contents of that file into the meson private (scratch) # directory so that it can be re-read when wiping/reconfiguring copy = os.path.join(scratch_dir, f'{uuid.uuid4()}.{ftype}.ini') - with open(f) as rf: - with open(copy, 'w') as wf: + with open(f, encoding='utf-8') as rf: + with open(copy, 'w', encoding='utf-8') as wf: wf.write(rf.read()) real.append(copy) @@ -973,7 +973,7 @@ def write_cmd_line_file(build_dir: str, options: argparse.Namespace) -> None: config['options'] = {str(k): str(v) for k, v in options.cmd_line_options.items()} config['properties'] = properties - with open(filename, 'w') as f: + with open(filename, 'w', encoding='utf-8') as f: config.write(f) def update_cmd_line_file(build_dir: str, options: argparse.Namespace): @@ -981,7 +981,7 @@ def update_cmd_line_file(build_dir: str, options: argparse.Namespace): config = CmdLineFileParser() config.read(filename) config['options'].update({str(k): str(v) for k, v in options.cmd_line_options.items()}) - with open(filename, 'w') as f: + with open(filename, 'w', encoding='utf-8') as f: config.write(f) def get_cmd_line_options(build_dir: str, options: argparse.Namespace) -> str: diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py index dc317cd..4e5af90 100644 --- a/mesonbuild/dependencies/boost.py +++ b/mesonbuild/dependencies/boost.py @@ -717,7 +717,7 @@ class BoostDependency(SystemDependency): # also work, however, this is slower (since it the compiler has to be # invoked) and overkill since the layout of the header is always the same. assert hfile.exists() - raw = hfile.read_text() + raw = hfile.read_text(encoding='utf-8') m = re.search(r'#define\s+BOOST_VERSION\s+([0-9]+)', raw) if not m: mlog.debug(f'Failed to extract version information from {hfile}') diff --git a/mesonbuild/dependencies/cmake.py b/mesonbuild/dependencies/cmake.py index 7dee62e..8219cc5 100644 --- a/mesonbuild/dependencies/cmake.py +++ b/mesonbuild/dependencies/cmake.py @@ -620,7 +620,7 @@ class CMakeDependency(ExternalDependency): """).format(' '.join(cmake_language)) + cmake_txt cm_file = build_dir / 'CMakeLists.txt' - cm_file.write_text(cmake_txt) + cm_file.write_text(cmake_txt, encoding='utf-8') mlog.cmd_ci_include(cm_file.absolute().as_posix()) return build_dir diff --git a/mesonbuild/dependencies/cuda.py b/mesonbuild/dependencies/cuda.py index 43bb622..21cc7ab 100644 --- a/mesonbuild/dependencies/cuda.py +++ b/mesonbuild/dependencies/cuda.py @@ -184,7 +184,7 @@ class CudaDependency(SystemDependency): def _read_cuda_runtime_api_version(self, path_str: str) -> T.Optional[str]: path = Path(path_str) for i in path.rglob('cuda_runtime_api.h'): - raw = i.read_text() + raw = i.read_text(encoding='utf-8') m = self.cudart_version_regex.search(raw) if not m: continue @@ -202,7 +202,7 @@ class CudaDependency(SystemDependency): # Read 'version.txt' at the root of the CUDA Toolkit directory to determine the tookit version version_file_path = os.path.join(path, 'version.txt') try: - with open(version_file_path) as version_file: + with open(version_file_path, encoding='utf-8') as version_file: version_str = version_file.readline() # e.g. 'CUDA Version 10.1.168' m = self.toolkit_version_regex.match(version_str) if m: diff --git a/mesonbuild/dependencies/pkgconfig.py b/mesonbuild/dependencies/pkgconfig.py index be5412e..1e8d913 100644 --- a/mesonbuild/dependencies/pkgconfig.py +++ b/mesonbuild/dependencies/pkgconfig.py @@ -423,7 +423,7 @@ class PkgConfigDependency(ExternalDependency): return out.strip() def extract_field(self, la_file: str, fieldname: str) -> T.Optional[str]: - with open(la_file) as f: + with open(la_file, encoding='utf-8') as f: for line in f: arr = line.strip().split('=') if arr[0] == fieldname: diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index e4fb0d4..1a9872d 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -973,7 +973,7 @@ external dependencies (including libraries) must go to "dependencies".''') ast.accept(printer) printer.post_process() meson_filename = os.path.join(self.build.environment.get_build_dir(), subdir, 'meson.build') - with open(meson_filename, "w") as f: + with open(meson_filename, "w", encoding='utf-8') as f: f.write(printer.result) mlog.log('Build file:', meson_filename) @@ -1964,7 +1964,7 @@ This will become a hard error in the future.''' % kwargs['input'], location=self if not os.path.isfile(absname): self.subdir = prev_subdir raise InterpreterException(f"Non-existent build file '{buildfilename!s}'") - with open(absname, encoding='utf8') as f: + with open(absname, encoding='utf-8') as f: code = f.read() assert(isinstance(code, str)) try: @@ -2198,7 +2198,7 @@ This will become a hard error in the future.''' % kwargs['input'], location=self mesonlib.replace_if_different(ofile_abs, dst_tmp) if depfile: mlog.log('Reading depfile:', mlog.bold(depfile)) - with open(depfile) as f: + with open(depfile, encoding='utf-8') as f: df = DepFile(f.readlines()) deps = df.get_all_dependencies(ofile_fname) for dep in deps: diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index 3f5726b..d66fb9c 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -95,7 +95,7 @@ class InterpreterBase: mesonfile = os.path.join(self.source_root, self.subdir, environment.build_filename) if not os.path.isfile(mesonfile): raise InvalidArguments('Missing Meson file in %s' % mesonfile) - with open(mesonfile, encoding='utf8') as mf: + with open(mesonfile, encoding='utf-8') as mf: code = mf.read() if code.isspace(): raise InvalidCode('Builder file is empty.') diff --git a/mesonbuild/mcompile.py b/mesonbuild/mcompile.py index d6f54e3..6e526f6 100644 --- a/mesonbuild/mcompile.py +++ b/mesonbuild/mcompile.py @@ -58,7 +58,7 @@ def parse_introspect_data(builddir: Path) -> T.Dict[str, T.List[dict]]: path_to_intro = builddir / 'meson-info' / 'intro-targets.json' if not path_to_intro.exists(): raise MesonException(f'`{path_to_intro.name}` is missing! Directory is not configured yet?') - with path_to_intro.open() as f: + with path_to_intro.open(encoding='utf-8') as f: schema = json.load(f) parsed_data = defaultdict(list) # type: T.Dict[str, T.List[dict]] diff --git a/mesonbuild/mdist.py b/mesonbuild/mdist.py index 397f8cd..22196d8 100644 --- a/mesonbuild/mdist.py +++ b/mesonbuild/mdist.py @@ -49,7 +49,7 @@ def create_hash(fname): hashname = fname + '.sha256sum' m = hashlib.sha256() m.update(open(fname, 'rb').read()) - with open(hashname, 'w') as f: + with open(hashname, 'w', encoding='utf-8') as f: # A space and an asterisk because that is the format defined by GNU coreutils # and accepted by busybox and the Perl shasum tool. f.write('{} *{}\n'.format(m.hexdigest(), os.path.basename(fname))) @@ -67,7 +67,7 @@ def process_submodules(dirname): if not os.path.exists(module_file): return subprocess.check_call(['git', 'submodule', 'update', '--init', '--recursive'], cwd=dirname) - for line in open(module_file): + for line in open(module_file, encoding='utf-8'): line = line.strip() if '=' not in line: continue @@ -242,7 +242,7 @@ def check_dist(packagename, meson_command, extra_meson_args, bld_root, privdir): unpacked_files = glob(os.path.join(unpackdir, '*')) assert(len(unpacked_files) == 1) unpacked_src_dir = unpacked_files[0] - with open(os.path.join(bld_root, 'meson-info', 'intro-buildoptions.json')) as boptions: + with open(os.path.join(bld_root, 'meson-info', 'intro-buildoptions.json'), encoding='utf-8') as boptions: meson_command += ['-D{name}={value}'.format(**o) for o in json.load(boptions) if o['name'] not in ['backend', 'install_umask', 'buildtype']] meson_command += extra_meson_args diff --git a/mesonbuild/mesondata.py b/mesonbuild/mesondata.py index b9a4c10..43b7bde 100644 --- a/mesonbuild/mesondata.py +++ b/mesonbuild/mesondata.py @@ -361,7 +361,7 @@ class DataFile: def write_once(self, path: Path) -> None: if not path.exists(): - path.write_text(self.data) + path.write_text(self.data, encoding='utf-8') def write_to_private(self, env: 'Environment') -> Path: out_file = Path(env.scratch_dir) / 'data' / self.path.name diff --git a/mesonbuild/mesonlib/posix.py b/mesonbuild/mesonlib/posix.py index 1d8ba8c..67f9a44 100644 --- a/mesonbuild/mesonlib/posix.py +++ b/mesonbuild/mesonlib/posix.py @@ -27,7 +27,7 @@ __all__ = ['BuildDirLock'] class BuildDirLock(BuildDirLockBase): def __enter__(self) -> None: - self.lockfile = open(self.lockfilename, 'w') + self.lockfile = open(self.lockfilename, 'w', encoding='utf-8') try: fcntl.flock(self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) except (BlockingIOError, PermissionError): diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py index 0ed99a5..c500e15 100644 --- a/mesonbuild/mesonlib/universal.py +++ b/mesonbuild/mesonlib/universal.py @@ -1359,7 +1359,7 @@ def expand_arguments(args: T.Iterable[str]) -> T.Optional[T.List[str]]: args_file = arg[1:] try: - with open(args_file) as f: + with open(args_file, encoding='utf-8') as f: extended_args = f.read().split() expended_args += extended_args except Exception as e: @@ -1854,11 +1854,11 @@ def get_wine_shortpath(winecmd: T.List[str], wine_paths: T.Sequence[str]) -> str wine_paths = list(OrderedSet(wine_paths)) getShortPathScript = '%s.bat' % str(uuid.uuid4()).lower()[:5] - with open(getShortPathScript, mode='w') as f: + with open(getShortPathScript, mode='w', encoding='utf-8') as f: f.write("@ECHO OFF\nfor %%x in (%*) do (\n echo|set /p=;%~sx\n)\n") f.flush() try: - with open(os.devnull, 'w') as stderr: + with open(os.devnull, 'w', encoding='utf-8') as stderr: wine_path = subprocess.check_output( winecmd + ['cmd', '/C', getShortPathScript] + wine_paths, diff --git a/mesonbuild/mesonlib/win32.py b/mesonbuild/mesonlib/win32.py index 0919ef7..bc0caec 100644 --- a/mesonbuild/mesonlib/win32.py +++ b/mesonbuild/mesonlib/win32.py @@ -27,7 +27,7 @@ __all__ = ['BuildDirLock'] class BuildDirLock(BuildDirLockBase): def __enter__(self) -> None: - self.lockfile = open(self.lockfilename, 'w') + self.lockfile = open(self.lockfilename, 'w', encoding='utf-8') try: msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_NBLCK, 1) except (BlockingIOError, PermissionError): diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index a3fd27d..86ae973 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -100,7 +100,7 @@ def setup_vsenv() -> None: bat_separator = '---SPLIT---' bat_contents = bat_template.format(bat_path, bat_separator) - bat_file.write_text(bat_contents) + bat_file.write_text(bat_contents, encoding='utf-8') try: bat_output = subprocess.check_output(str(bat_file), universal_newlines=True) finally: diff --git a/mesonbuild/minstall.py b/mesonbuild/minstall.py index 7011c42..b631d4a 100644 --- a/mesonbuild/minstall.py +++ b/mesonbuild/minstall.py @@ -708,7 +708,7 @@ def run(opts: 'ArgumentType') -> int: if not rebuild_all(opts.wd): sys.exit(-1) os.chdir(opts.wd) - with open(os.path.join(log_dir, 'install-log.txt'), 'w') as lf: + with open(os.path.join(log_dir, 'install-log.txt'), 'w', encoding='utf-8') as lf: installer = Installer(opts, lf) append_to_log(lf, '# List of files installed by Meson') append_to_log(lf, '# Does not contain files installed by custom scripts.') diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index 430b2f1..73790a5 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -394,7 +394,7 @@ def get_info_file(infodir: str, kind: T.Optional[str] = None) -> str: 'meson-info.json' if not kind else f'intro-{kind}.json') def load_info_file(infodir: str, kind: T.Optional[str] = None) -> T.Any: - with open(get_info_file(infodir, kind)) as fp: + with open(get_info_file(infodir, kind), encoding='utf-8') as fp: return json.load(fp) def run(options: argparse.Namespace) -> int: @@ -464,7 +464,7 @@ def write_intro_info(intro_info: T.Sequence[T.Tuple[str, T.Union[dict, T.List[T. for i in intro_info: out_file = os.path.join(info_dir, 'intro-{}.json'.format(i[0])) tmp_file = os.path.join(info_dir, 'tmp_dump.json') - with open(tmp_file, 'w') as fp: + with open(tmp_file, 'w', encoding='utf-8') as fp: json.dump(i[1], fp) fp.flush() # Not sure if this is needed os.replace(tmp_file, out_file) @@ -535,7 +535,7 @@ def write_meson_info_file(builddata: build.Build, errors: list, build_files_upda # Write the data to disc tmp_file = os.path.join(info_dir, 'tmp_dump.json') - with open(tmp_file, 'w') as fp: + with open(tmp_file, 'w', encoding='utf-8') as fp: json.dump(info_data, fp) fp.flush() os.replace(tmp_file, info_file) diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index 5c76677..314e1b7 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -100,7 +100,7 @@ def set_verbose() -> None: def initialize(logdir: str, fatal_warnings: bool = False) -> None: global log_dir, log_file, log_fatal_warnings log_dir = logdir - log_file = open(os.path.join(logdir, log_fname), 'w', encoding='utf8') + log_file = open(os.path.join(logdir, log_fname), 'w', encoding='utf-8') log_fatal_warnings = fatal_warnings def set_timestamp_start(start: float) -> None: diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py index cb37edc..c390b01 100644 --- a/mesonbuild/modules/cmake.py +++ b/mesonbuild/modules/cmake.py @@ -298,7 +298,7 @@ class CmakeModule(ExtensionModule): package_init += PACKAGE_INIT_SET_AND_CHECK try: - with open(infile) as fin: + with open(infile, encoding='utf-8') as fin: data = fin.readlines() except Exception as e: raise mesonlib.MesonException('Could not read input file {}: {}'.format(infile, str(e))) diff --git a/mesonbuild/modules/dlang.py b/mesonbuild/modules/dlang.py index e2a55b6..b6efc86 100644 --- a/mesonbuild/modules/dlang.py +++ b/mesonbuild/modules/dlang.py @@ -70,7 +70,7 @@ class DlangModule(ExtensionModule): config_path = os.path.join(args[1], 'dub.json') if os.path.exists(config_path): - with open(config_path, encoding='utf8') as ofile: + with open(config_path, encoding='utf-8') as ofile: try: config = json.load(ofile) except ValueError: @@ -108,7 +108,7 @@ class DlangModule(ExtensionModule): else: config[key] = value - with open(config_path, 'w', encoding='utf8') as ofile: + with open(config_path, 'w', encoding='utf-8') as ofile: ofile.write(json.dumps(config, indent=4, ensure_ascii=False)) def _call_dubbin(self, args, env=None): diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index efd1f00..1b68f6c 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -1713,7 +1713,7 @@ G_END_DECLS''' def _generate_deps(self, state, library, packages, install_dir): outdir = state.environment.scratch_dir fname = os.path.join(outdir, library + '.deps') - with open(fname, 'w') as ofile: + with open(fname, 'w', encoding='utf-8') as ofile: for package in packages: ofile.write(package + '\n') return build.Data([mesonlib.File(True, outdir, fname)], install_dir, None, state.subproject) diff --git a/mesonbuild/modules/hotdoc.py b/mesonbuild/modules/hotdoc.py index 26026fb..4dccd06 100644 --- a/mesonbuild/modules/hotdoc.py +++ b/mesonbuild/modules/hotdoc.py @@ -310,7 +310,7 @@ class HotdocTargetBuilder: hotdoc_config_name = fullname + '.json' hotdoc_config_path = os.path.join( self.builddir, self.subdir, hotdoc_config_name) - with open(hotdoc_config_path, 'w') as f: + with open(hotdoc_config_path, 'w', encoding='utf-8') as f: f.write('{}') self.cmd += ['--conf-file', hotdoc_config_path] diff --git a/mesonbuild/modules/keyval.py b/mesonbuild/modules/keyval.py index d637ac0..b2d54db 100644 --- a/mesonbuild/modules/keyval.py +++ b/mesonbuild/modules/keyval.py @@ -32,7 +32,7 @@ class KeyvalModule(ExtensionModule): def _load_file(self, path_to_config): result = dict() try: - with open(path_to_config) as f: + with open(path_to_config, encoding='utf-8') as f: for line in f: if '#' in line: comment_idx = line.index('#') diff --git a/mesonbuild/modules/rpm.py b/mesonbuild/modules/rpm.py index 704e82b..1fae144 100644 --- a/mesonbuild/modules/rpm.py +++ b/mesonbuild/modules/rpm.py @@ -77,7 +77,7 @@ class RPMModule(ExtensionModule): filename = os.path.join(state.environment.get_build_dir(), '%s.spec' % proj) - with open(filename, 'w+') as fn: + with open(filename, 'w+', encoding='utf-8') as fn: fn.write('Name: %s\n' % proj) fn.write('Version: # FIXME\n') fn.write('Release: 1%{?dist}\n') diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/unstable_external_project.py index e997f6a..4f8ac56 100644 --- a/mesonbuild/modules/unstable_external_project.py +++ b/mesonbuild/modules/unstable_external_project.py @@ -162,7 +162,7 @@ class ExternalProject(ModuleObject): log_filename = Path(mlog.log_dir, f'{self.name}-{step}.log') output = None if not self.verbose: - output = open(log_filename, 'w') + output = open(log_filename, 'w', encoding='utf-8') output.write(m + '\n') output.flush() else: diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py index b348948..9ed2981 100644 --- a/mesonbuild/msetup.py +++ b/mesonbuild/msetup.py @@ -148,9 +148,9 @@ class MesonApp: def add_vcs_ignore_files(self, build_dir: str) -> None: if os.listdir(build_dir): return - with open(os.path.join(build_dir, '.gitignore'), 'w') as ofile: + with open(os.path.join(build_dir, '.gitignore'), 'w', encoding='utf-8') as ofile: ofile.write(git_ignore_file) - with open(os.path.join(build_dir, '.hgignore'), 'w') as ofile: + with open(os.path.join(build_dir, '.hgignore'), 'w', encoding='utf-8') as ofile: ofile.write(hg_ignore_file) def validate_dirs(self, dir1: str, dir2: str, reconfigure: bool, wipe: bool) -> T.Tuple[str, str]: diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index e54740e..826619f 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -467,7 +467,7 @@ class TestLogger: class TestFileLogger(TestLogger): def __init__(self, filename: str, errors: str = 'replace') -> None: self.filename = filename - self.file = open(filename, 'w', encoding='utf8', errors=errors) + self.file = open(filename, 'w', encoding='utf-8', errors=errors) def close(self) -> None: if self.file: diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py index 6043691..72bf865 100644 --- a/mesonbuild/optinterpreter.py +++ b/mesonbuild/optinterpreter.py @@ -142,7 +142,7 @@ class OptionInterpreter: def process(self, option_file: str) -> None: try: - with open(option_file, encoding='utf8') as f: + with open(option_file, encoding='utf-8') as f: ast = mparser.Parser(f.read(), option_file).parse() except mesonlib.MesonException as me: me.file = option_file diff --git a/mesonbuild/programs.py b/mesonbuild/programs.py index bb14f96..ffd177f 100644 --- a/mesonbuild/programs.py +++ b/mesonbuild/programs.py @@ -176,7 +176,7 @@ class ExternalProgram(mesonlib.HoldableObject): or if we're on Windows (which does not understand shebangs). """ try: - with open(script) as f: + with open(script, encoding='utf-8') as f: first_line = f.readline().strip() if first_line.startswith('#!'): # In a shebang, everything before the first space is assumed to diff --git a/mesonbuild/rewriter.py b/mesonbuild/rewriter.py index ddd712f..3f661a4 100644 --- a/mesonbuild/rewriter.py +++ b/mesonbuild/rewriter.py @@ -818,9 +818,9 @@ class Rewriter: fdata = '' # Create an empty file if it does not exist if not os.path.exists(fpath): - with open(fpath, 'w'): + with open(fpath, 'w', encoding='utf-8'): pass - with open(fpath) as fp: + with open(fpath, encoding='utf-8') as fp: fdata = fp.read() # Generate line offsets numbers @@ -871,7 +871,7 @@ class Rewriter: # Write the files back for key, val in files.items(): mlog.log('Rewriting', mlog.yellow(key)) - with open(val['path'], 'w') as fp: + with open(val['path'], 'w', encoding='utf-8') as fp: fp.write(val['raw']) target_operation_map = { @@ -923,7 +923,7 @@ def generate_def_opts(options) -> T.List[dict]: def generate_cmd(options) -> T.List[dict]: if os.path.exists(options.json): - with open(options.json) as fp: + with open(options.json, encoding='utf-8') as fp: return json.load(fp) else: return json.loads(options.json) diff --git a/mesonbuild/scripts/coverage.py b/mesonbuild/scripts/coverage.py index f8a4924..b60d5d1 100644 --- a/mesonbuild/scripts/coverage.py +++ b/mesonbuild/scripts/coverage.py @@ -68,11 +68,11 @@ def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build # Create a shim to allow using llvm-cov as a gcov tool. if mesonlib.is_windows(): llvm_cov_shim_path = os.path.join(log_dir, 'llvm-cov.bat') - with open(llvm_cov_shim_path, 'w') as llvm_cov_bat: + with open(llvm_cov_shim_path, 'w', encoding='utf-8') as llvm_cov_bat: llvm_cov_bat.write(f'@"{llvm_cov_exe}" gcov %*') else: llvm_cov_shim_path = os.path.join(log_dir, 'llvm-cov.sh') - with open(llvm_cov_shim_path, 'w') as llvm_cov_sh: + with open(llvm_cov_shim_path, 'w', encoding='utf-8') as llvm_cov_sh: llvm_cov_sh.write(f'#!/usr/bin/env sh\nexec "{llvm_cov_exe}" gcov $@') os.chmod(llvm_cov_shim_path, os.stat(llvm_cov_shim_path).st_mode | stat.S_IEXEC) gcov_tool_args = ['--gcov-tool', llvm_cov_shim_path] diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py index c215749..52c7ba9 100644 --- a/mesonbuild/scripts/depfixer.py +++ b/mesonbuild/scripts/depfixer.py @@ -468,7 +468,7 @@ def fix_darwin(fname: str, new_rpath: str, final_path: str, install_name_mapping def fix_jar(fname: str) -> None: subprocess.check_call(['jar', 'xfv', fname, 'META-INF/MANIFEST.MF']) - with open('META-INF/MANIFEST.MF', 'r+') as f: + with open('META-INF/MANIFEST.MF', 'r+', encoding='utf-8') as f: lines = f.readlines() f.seek(0) for line in lines: diff --git a/mesonbuild/scripts/depscan.py b/mesonbuild/scripts/depscan.py index 207bbc6..9fc435b 100644 --- a/mesonbuild/scripts/depscan.py +++ b/mesonbuild/scripts/depscan.py @@ -57,7 +57,7 @@ class DependencyScanner: def scan_fortran_file(self, fname: str) -> None: fpath = pathlib.Path(fname) modules_in_this_file = set() - for line in fpath.read_text().split('\n'): + for line in fpath.read_text(encoding='utf-8').split('\n'): import_match = FORTRAN_USE_RE.match(line) export_match = FORTRAN_MODULE_RE.match(line) submodule_export_match = FORTRAN_SUBMOD_RE.match(line) @@ -108,7 +108,7 @@ class DependencyScanner: def scan_cpp_file(self, fname: str) -> None: fpath = pathlib.Path(fname) - for line in fpath.read_text().split('\n'): + for line in fpath.read_text(encoding='utf-8').split('\n'): import_match = CPP_IMPORT_RE.match(line) export_match = CPP_EXPORT_RE.match(line) if import_match: @@ -150,7 +150,7 @@ class DependencyScanner: def scan(self) -> int: for s in self.sources: self.scan_file(s) - with open(self.outfile, 'w') as ofile: + with open(self.outfile, 'w', encoding='utf-8') as ofile: ofile.write('ninja_dyndep_version = 1\n') for src in self.sources: objfilename = self.objname_for(src) diff --git a/mesonbuild/scripts/externalproject.py b/mesonbuild/scripts/externalproject.py index 657ef2f..a8e3bfe 100644 --- a/mesonbuild/scripts/externalproject.py +++ b/mesonbuild/scripts/externalproject.py @@ -34,7 +34,7 @@ class ExternalProject: self.make = options.make def write_depfile(self) -> None: - with open(self.depfile, 'w') as f: + with open(self.depfile, 'w', encoding='utf-8') as f: f.write(f'{self.stampfile}: \\\n') for dirpath, dirnames, filenames in os.walk(self.src_dir): dirnames[:] = [d for d in dirnames if not d.startswith('.')] @@ -45,7 +45,7 @@ class ExternalProject: f.write(' {} \\\n'.format(path.as_posix().replace(' ', '\\ '))) def write_stampfile(self) -> None: - with open(self.stampfile, 'w') as f: + with open(self.stampfile, 'w', encoding='utf-8') as f: pass def gnu_make(self) -> bool: @@ -78,7 +78,7 @@ class ExternalProject: log_filename = Path(self.log_dir, f'{self.name}-{step}.log') output = None if not self.verbose: - output = open(log_filename, 'w') + output = open(log_filename, 'w', encoding='utf-8') output.write(m + '\n') output.flush() else: diff --git a/mesonbuild/scripts/gettext.py b/mesonbuild/scripts/gettext.py index 92b55d3..b1ce6af 100644 --- a/mesonbuild/scripts/gettext.py +++ b/mesonbuild/scripts/gettext.py @@ -34,7 +34,7 @@ def read_linguas(src_sub: str) -> T.List[str]: linguas = os.path.join(src_sub, 'LINGUAS') try: langs = [] - with open(linguas) as f: + with open(linguas, encoding='utf-8') as f: for line in f: line = line.strip() if line and not line.startswith('#'): diff --git a/mesonbuild/scripts/symbolextractor.py b/mesonbuild/scripts/symbolextractor.py index 728d5e2..17501e2 100644 --- a/mesonbuild/scripts/symbolextractor.py +++ b/mesonbuild/scripts/symbolextractor.py @@ -38,18 +38,18 @@ RELINKING_WARNING = 'Relinking will always happen on source changes.' def dummy_syms(outfilename: str) -> None: """Just touch it so relinking happens always.""" - with open(outfilename, 'w'): + with open(outfilename, 'w', encoding='utf-8'): pass def write_if_changed(text: str, outfilename: str) -> None: try: - with open(outfilename) as f: + with open(outfilename, encoding='utf-8') as f: oldtext = f.read() if text == oldtext: return except FileNotFoundError: pass - with open(outfilename, 'w') as f: + with open(outfilename, 'w', encoding='utf-8') as f: f.write(text) def print_tool_warning(tools: T.List[str], msg: str, stderr: T.Optional[str] = None) -> None: @@ -61,7 +61,7 @@ def print_tool_warning(tools: T.List[str], msg: str, stderr: T.Optional[str] = N m += '\n' + stderr mlog.warning(m) # Write it out so we don't warn again - with open(TOOL_WARNING_FILE, 'w'): + with open(TOOL_WARNING_FILE, 'w', encoding='utf-8'): pass def get_tool(name: str) -> T.List[str]: @@ -309,7 +309,7 @@ def gen_symbols(libfilename: str, impfilename: str, outfilename: str, cross_host mlog.warning('Symbol extracting has not been implemented for this ' 'platform. ' + RELINKING_WARNING) # Write it out so we don't warn again - with open(TOOL_WARNING_FILE, 'w'): + with open(TOOL_WARNING_FILE, 'w', encoding='utf-8'): pass dummy_syms(outfilename) diff --git a/mesonbuild/scripts/uninstall.py b/mesonbuild/scripts/uninstall.py index 8db04dd..f08490f 100644 --- a/mesonbuild/scripts/uninstall.py +++ b/mesonbuild/scripts/uninstall.py @@ -20,7 +20,7 @@ logfile = 'meson-logs/install-log.txt' def do_uninstall(log: str) -> None: failures = 0 successes = 0 - for line in open(log): + for line in open(log, encoding='utf-8'): if line.startswith('#'): continue fname = line.strip() diff --git a/mesonbuild/scripts/vcstagger.py b/mesonbuild/scripts/vcstagger.py index 64985f6..18cf5f7 100644 --- a/mesonbuild/scripts/vcstagger.py +++ b/mesonbuild/scripts/vcstagger.py @@ -22,15 +22,15 @@ def config_vcs_tag(infile: str, outfile: str, fallback: str, source_dir: str, re except Exception: new_string = fallback - with open(infile, encoding='utf8') as f: + with open(infile, encoding='utf-8') as f: new_data = f.read().replace(replace_string, new_string) if os.path.exists(outfile): - with open(outfile, encoding='utf8') as f: + with open(outfile, encoding='utf-8') as f: needs_update = (f.read() != new_data) else: needs_update = True if needs_update: - with open(outfile, 'w', encoding='utf8') as f: + with open(outfile, 'w', encoding='utf-8') as f: f.write(new_data) diff --git a/mesonbuild/templates/cpptemplates.py b/mesonbuild/templates/cpptemplates.py index 2d28d3a..61c2737 100644 --- a/mesonbuild/templates/cpptemplates.py +++ b/mesonbuild/templates/cpptemplates.py @@ -149,11 +149,12 @@ class CppProject(SampleImpl): def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.cpp' - open(source_name, 'w').write(hello_cpp_template.format(project_name=self.name)) - open('meson.build', 'w').write(hello_cpp_meson_template.format(project_name=self.name, - exe_name=lowercase_token, - source_name=source_name, - version=self.version)) + open(source_name, 'w', encoding='utf-8').write(hello_cpp_template.format(project_name=self.name)) + open('meson.build', 'w', encoding='utf-8').write( + hello_cpp_meson_template.format(project_name=self.name, + exe_name=lowercase_token, + source_name=source_name, + version=self.version)) def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) @@ -178,7 +179,7 @@ class CppProject(SampleImpl): 'test_name': lowercase_token, 'version': self.version, } - open(lib_hpp_name, 'w').write(lib_hpp_template.format(**kwargs)) - open(lib_cpp_name, 'w').write(lib_cpp_template.format(**kwargs)) - open(test_cpp_name, 'w').write(lib_cpp_test_template.format(**kwargs)) - open('meson.build', 'w').write(lib_cpp_meson_template.format(**kwargs)) + open(lib_hpp_name, 'w', encoding='utf-8').write(lib_hpp_template.format(**kwargs)) + open(lib_cpp_name, 'w', encoding='utf-8').write(lib_cpp_template.format(**kwargs)) + open(test_cpp_name, 'w', encoding='utf-8').write(lib_cpp_test_template.format(**kwargs)) + open('meson.build', 'w', encoding='utf-8').write(lib_cpp_meson_template.format(**kwargs)) diff --git a/mesonbuild/templates/cstemplates.py b/mesonbuild/templates/cstemplates.py index 8524c97..bad7984 100644 --- a/mesonbuild/templates/cstemplates.py +++ b/mesonbuild/templates/cstemplates.py @@ -100,12 +100,14 @@ class CSharpProject(SampleImpl): uppercase_token = lowercase_token.upper() class_name = uppercase_token[0] + lowercase_token[1:] source_name = uppercase_token[0] + lowercase_token[1:] + '.cs' - open(source_name, 'w').write(hello_cs_template.format(project_name=self.name, - class_name=class_name)) - open('meson.build', 'w').write(hello_cs_meson_template.format(project_name=self.name, - exe_name=self.name, - source_name=source_name, - version=self.version)) + open(source_name, 'w', encoding='utf-8').write( + hello_cs_template.format(project_name=self.name, + class_name=class_name)) + open('meson.build', 'w', encoding='utf-8').write( + hello_cs_meson_template.format(project_name=self.name, + exe_name=self.name, + source_name=source_name, + version=self.version)) def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) @@ -127,6 +129,6 @@ class CSharpProject(SampleImpl): 'test_name': lowercase_token, 'version': self.version, } - open(lib_cs_name, 'w').write(lib_cs_template.format(**kwargs)) - open(test_cs_name, 'w').write(lib_cs_test_template.format(**kwargs)) - open('meson.build', 'w').write(lib_cs_meson_template.format(**kwargs)) + open(lib_cs_name, 'w', encoding='utf-8').write(lib_cs_template.format(**kwargs)) + open(test_cs_name, 'w', encoding='utf-8').write(lib_cs_test_template.format(**kwargs)) + open('meson.build', 'w', encoding='utf-8').write(lib_cs_meson_template.format(**kwargs)) diff --git a/mesonbuild/templates/ctemplates.py b/mesonbuild/templates/ctemplates.py index 440731c..9b651bc 100644 --- a/mesonbuild/templates/ctemplates.py +++ b/mesonbuild/templates/ctemplates.py @@ -132,11 +132,12 @@ class CProject(SampleImpl): def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.c' - open(source_name, 'w').write(hello_c_template.format(project_name=self.name)) - open('meson.build', 'w').write(hello_c_meson_template.format(project_name=self.name, - exe_name=lowercase_token, - source_name=source_name, - version=self.version)) + open(source_name, 'w', encoding='utf-8').write(hello_c_template.format(project_name=self.name)) + open('meson.build', 'w', encoding='utf-8').write( + hello_c_meson_template.format(project_name=self.name, + exe_name=lowercase_token, + source_name=source_name, + version=self.version)) def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) @@ -159,7 +160,7 @@ class CProject(SampleImpl): 'test_name': lowercase_token, 'version': self.version, } - open(lib_h_name, 'w').write(lib_h_template.format(**kwargs)) - open(lib_c_name, 'w').write(lib_c_template.format(**kwargs)) - open(test_c_name, 'w').write(lib_c_test_template.format(**kwargs)) - open('meson.build', 'w').write(lib_c_meson_template.format(**kwargs)) + open(lib_h_name, 'w', encoding='utf-8').write(lib_h_template.format(**kwargs)) + open(lib_c_name, 'w', encoding='utf-8').write(lib_c_template.format(**kwargs)) + open(test_c_name, 'w', encoding='utf-8').write(lib_c_test_template.format(**kwargs)) + open('meson.build', 'w', encoding='utf-8').write(lib_c_meson_template.format(**kwargs)) diff --git a/mesonbuild/templates/cudatemplates.py b/mesonbuild/templates/cudatemplates.py index 4fa9a2b..919db21 100644 --- a/mesonbuild/templates/cudatemplates.py +++ b/mesonbuild/templates/cudatemplates.py @@ -149,11 +149,12 @@ class CudaProject(SampleImpl): def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.cu' - open(source_name, 'w').write(hello_cuda_template.format(project_name=self.name)) - open('meson.build', 'w').write(hello_cuda_meson_template.format(project_name=self.name, - exe_name=lowercase_token, - source_name=source_name, - version=self.version)) + open(source_name, 'w', encoding='utf-8').write(hello_cuda_template.format(project_name=self.name)) + open('meson.build', 'w', encoding='utf-8').write( + hello_cuda_meson_template.format(project_name=self.name, + exe_name=lowercase_token, + source_name=source_name, + version=self.version)) def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) @@ -178,7 +179,7 @@ class CudaProject(SampleImpl): 'test_name': lowercase_token, 'version': self.version, } - open(lib_h_name, 'w').write(lib_h_template.format(**kwargs)) - open(lib_cuda_name, 'w').write(lib_cuda_template.format(**kwargs)) - open(test_cuda_name, 'w').write(lib_cuda_test_template.format(**kwargs)) - open('meson.build', 'w').write(lib_cuda_meson_template.format(**kwargs)) + open(lib_h_name, 'w', encoding='utf-8').write(lib_h_template.format(**kwargs)) + open(lib_cuda_name, 'w', encoding='utf-8').write(lib_cuda_template.format(**kwargs)) + open(test_cuda_name, 'w', encoding='utf-8').write(lib_cuda_test_template.format(**kwargs)) + open('meson.build', 'w', encoding='utf-8').write(lib_cuda_meson_template.format(**kwargs)) diff --git a/mesonbuild/templates/dlangtemplates.py b/mesonbuild/templates/dlangtemplates.py index 4aacda8..3d939d8 100644 --- a/mesonbuild/templates/dlangtemplates.py +++ b/mesonbuild/templates/dlangtemplates.py @@ -110,11 +110,12 @@ class DlangProject(SampleImpl): def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.d' - open(source_name, 'w').write(hello_d_template.format(project_name=self.name)) - open('meson.build', 'w').write(hello_d_meson_template.format(project_name=self.name, - exe_name=lowercase_token, - source_name=source_name, - version=self.version)) + open(source_name, 'w', encoding='utf-8').write(hello_d_template.format(project_name=self.name)) + open('meson.build', 'w', encoding='utf-8').write( + hello_d_meson_template.format(project_name=self.name, + exe_name=lowercase_token, + source_name=source_name, + version=self.version)) def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) @@ -137,6 +138,6 @@ class DlangProject(SampleImpl): 'test_name': lowercase_token, 'version': self.version, } - open(lib_d_name, 'w').write(lib_d_template.format(**kwargs)) - open(test_d_name, 'w').write(lib_d_test_template.format(**kwargs)) - open('meson.build', 'w').write(lib_d_meson_template.format(**kwargs)) + open(lib_d_name, 'w', encoding='utf-8').write(lib_d_template.format(**kwargs)) + open(test_d_name, 'w', encoding='utf-8').write(lib_d_test_template.format(**kwargs)) + open('meson.build', 'w', encoding='utf-8').write(lib_d_meson_template.format(**kwargs)) diff --git a/mesonbuild/templates/fortrantemplates.py b/mesonbuild/templates/fortrantemplates.py index f4cae66..8fc1bca 100644 --- a/mesonbuild/templates/fortrantemplates.py +++ b/mesonbuild/templates/fortrantemplates.py @@ -109,11 +109,12 @@ class FortranProject(SampleImpl): def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.f90' - open(source_name, 'w').write(hello_fortran_template.format(project_name=self.name)) - open('meson.build', 'w').write(hello_fortran_meson_template.format(project_name=self.name, - exe_name=lowercase_token, - source_name=source_name, - version=self.version)) + open(source_name, 'w', encoding='utf-8').write(hello_fortran_template.format(project_name=self.name)) + open('meson.build', 'w', encoding='utf-8').write( + hello_fortran_meson_template.format(project_name=self.name, + exe_name=lowercase_token, + source_name=source_name, + version=self.version)) def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) @@ -134,6 +135,6 @@ class FortranProject(SampleImpl): 'test_name': lowercase_token, 'version': self.version, } - open(lib_fortran_name, 'w').write(lib_fortran_template.format(**kwargs)) - open(test_fortran_name, 'w').write(lib_fortran_test_template.format(**kwargs)) - open('meson.build', 'w').write(lib_fortran_meson_template.format(**kwargs)) + open(lib_fortran_name, 'w', encoding='utf-8').write(lib_fortran_template.format(**kwargs)) + open(test_fortran_name, 'w', encoding='utf-8').write(lib_fortran_test_template.format(**kwargs)) + open('meson.build', 'w', encoding='utf-8').write(lib_fortran_meson_template.format(**kwargs)) diff --git a/mesonbuild/templates/javatemplates.py b/mesonbuild/templates/javatemplates.py index 9c64743..e432961 100644 --- a/mesonbuild/templates/javatemplates.py +++ b/mesonbuild/templates/javatemplates.py @@ -104,12 +104,14 @@ class JavaProject(SampleImpl): uppercase_token = lowercase_token.upper() class_name = uppercase_token[0] + lowercase_token[1:] source_name = uppercase_token[0] + lowercase_token[1:] + '.java' - open(source_name, 'w').write(hello_java_template.format(project_name=self.name, - class_name=class_name)) - open('meson.build', 'w').write(hello_java_meson_template.format(project_name=self.name, - exe_name=class_name, - source_name=source_name, - version=self.version)) + open(source_name, 'w', encoding='utf-8').write( + hello_java_template.format(project_name=self.name, + class_name=class_name)) + open('meson.build', 'w', encoding='utf-8').write( + hello_java_meson_template.format(project_name=self.name, + exe_name=class_name, + source_name=source_name, + version=self.version)) def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) @@ -129,6 +131,6 @@ class JavaProject(SampleImpl): 'test_name': lowercase_token, 'version': self.version, } - open(lib_java_name, 'w').write(lib_java_template.format(**kwargs)) - open(test_java_name, 'w').write(lib_java_test_template.format(**kwargs)) - open('meson.build', 'w').write(lib_java_meson_template.format(**kwargs)) + open(lib_java_name, 'w', encoding='utf-8').write(lib_java_template.format(**kwargs)) + open(test_java_name, 'w', encoding='utf-8').write(lib_java_test_template.format(**kwargs)) + open('meson.build', 'w', encoding='utf-8').write(lib_java_meson_template.format(**kwargs)) diff --git a/mesonbuild/templates/mesontemplates.py b/mesonbuild/templates/mesontemplates.py index 4c4d66f..a29ac6f 100644 --- a/mesonbuild/templates/mesontemplates.py +++ b/mesonbuild/templates/mesontemplates.py @@ -71,5 +71,5 @@ def create_meson_build(options: argparse.Namespace) -> None: sourcespec=sourcespec, depspec=depspec, default_options=formatted_default_options) - open('meson.build', 'w').write(content) + open('meson.build', 'w', encoding='utf-8').write(content) print('Generated meson.build file:\n\n' + content) diff --git a/mesonbuild/templates/objcpptemplates.py b/mesonbuild/templates/objcpptemplates.py index f4f4b51..4f61d6c 100644 --- a/mesonbuild/templates/objcpptemplates.py +++ b/mesonbuild/templates/objcpptemplates.py @@ -132,11 +132,12 @@ class ObjCppProject(SampleImpl): def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.mm' - open(source_name, 'w').write(hello_objcpp_template.format(project_name=self.name)) - open('meson.build', 'w').write(hello_objcpp_meson_template.format(project_name=self.name, - exe_name=lowercase_token, - source_name=source_name, - version=self.version)) + open(source_name, 'w', encoding='utf-8').write(hello_objcpp_template.format(project_name=self.name)) + open('meson.build', 'w', encoding='utf-8').write( + hello_objcpp_meson_template.format(project_name=self.name, + exe_name=lowercase_token, + source_name=source_name, + version=self.version)) def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) @@ -159,8 +160,8 @@ class ObjCppProject(SampleImpl): 'test_name': lowercase_token, 'version': self.version, } - open(lib_h_name, 'w').write(lib_h_template.format(**kwargs)) - open(lib_objcpp_name, 'w').write(lib_objcpp_template.format(**kwargs)) - open(test_objcpp_name, 'w').write(lib_objcpp_test_template.format(**kwargs)) - open('meson.build', 'w').write(lib_objcpp_meson_template.format(**kwargs)) + open(lib_h_name, 'w', encoding='utf-8').write(lib_h_template.format(**kwargs)) + open(lib_objcpp_name, 'w', encoding='utf-8').write(lib_objcpp_template.format(**kwargs)) + open(test_objcpp_name, 'w', encoding='utf-8').write(lib_objcpp_test_template.format(**kwargs)) + open('meson.build', 'w', encoding='utf-8').write(lib_objcpp_meson_template.format(**kwargs)) diff --git a/mesonbuild/templates/objctemplates.py b/mesonbuild/templates/objctemplates.py index 4243024..dac638d 100644 --- a/mesonbuild/templates/objctemplates.py +++ b/mesonbuild/templates/objctemplates.py @@ -132,11 +132,12 @@ class ObjCProject(SampleImpl): def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.m' - open(source_name, 'w').write(hello_objc_template.format(project_name=self.name)) - open('meson.build', 'w').write(hello_objc_meson_template.format(project_name=self.name, - exe_name=lowercase_token, - source_name=source_name, - version=self.version)) + open(source_name, 'w', encoding='utf-8').write(hello_objc_template.format(project_name=self.name)) + open('meson.build', 'w', encoding='utf-8').write( + hello_objc_meson_template.format(project_name=self.name, + exe_name=lowercase_token, + source_name=source_name, + version=self.version)) def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) @@ -159,7 +160,7 @@ class ObjCProject(SampleImpl): 'test_name': lowercase_token, 'version': self.version, } - open(lib_h_name, 'w').write(lib_h_template.format(**kwargs)) - open(lib_objc_name, 'w').write(lib_objc_template.format(**kwargs)) - open(test_objc_name, 'w').write(lib_objc_test_template.format(**kwargs)) - open('meson.build', 'w').write(lib_objc_meson_template.format(**kwargs)) + open(lib_h_name, 'w', encoding='utf-8').write(lib_h_template.format(**kwargs)) + open(lib_objc_name, 'w', encoding='utf-8').write(lib_objc_template.format(**kwargs)) + open(test_objc_name, 'w', encoding='utf-8').write(lib_objc_test_template.format(**kwargs)) + open('meson.build', 'w', encoding='utf-8').write(lib_objc_meson_template.format(**kwargs)) diff --git a/mesonbuild/templates/rusttemplates.py b/mesonbuild/templates/rusttemplates.py index 6e99586..95a937c 100644 --- a/mesonbuild/templates/rusttemplates.py +++ b/mesonbuild/templates/rusttemplates.py @@ -80,11 +80,12 @@ class RustProject(SampleImpl): def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.rs' - open(source_name, 'w').write(hello_rust_template.format(project_name=self.name)) - open('meson.build', 'w').write(hello_rust_meson_template.format(project_name=self.name, - exe_name=lowercase_token, - source_name=source_name, - version=self.version)) + open(source_name, 'w', encoding='utf-8').write(hello_rust_template.format(project_name=self.name)) + open('meson.build', 'w', encoding='utf-8').write( + hello_rust_meson_template.format(project_name=self.name, + exe_name=lowercase_token, + source_name=source_name, + version=self.version)) def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) @@ -107,6 +108,6 @@ class RustProject(SampleImpl): 'test_name': lowercase_token, 'version': self.version, } - open(lib_rs_name, 'w').write(lib_rust_template.format(**kwargs)) - open(test_rs_name, 'w').write(lib_rust_test_template.format(**kwargs)) - open('meson.build', 'w').write(lib_rust_meson_template.format(**kwargs)) + open(lib_rs_name, 'w', encoding='utf-8').write(lib_rust_template.format(**kwargs)) + open(test_rs_name, 'w', encoding='utf-8').write(lib_rust_test_template.format(**kwargs)) + open('meson.build', 'w', encoding='utf-8').write(lib_rust_meson_template.format(**kwargs)) diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index e88d658..4a6583f 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -291,7 +291,7 @@ class Resolver: mlog.log('Using', mlog.bold(rel)) # Write a dummy wrap file in main project that redirect to the # wrap we picked. - with open(main_fname, 'w') as f: + with open(main_fname, 'w', encoding='utf-8') as f: f.write(textwrap.dedent('''\ [wrap-redirect] filename = {} |