Bug 1916786 - Modernize python/mozbuild/mozbuild to use exist_ok=True parameter from os.makedirs r=ahochheiden

Differential Revision: https://phabricator.services.mozilla.com/D221070
This commit is contained in:
serge-sans-paille 2024-09-05 05:52:56 +00:00
Родитель 5bc16ac9c3
Коммит 384a41d933
10 изменённых файлов: 16 добавлений и 73 удалений

Просмотреть файл

@ -3,7 +3,6 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import codecs
import errno
import io
import itertools
import logging
@ -154,12 +153,7 @@ def main(argv):
js_config = config.copy()
pwd = os.getcwd()
try:
try:
os.makedirs("js/src")
except OSError as e:
if e.errno != errno.EEXIST:
raise
os.makedirs("js/src", exist_ok=True)
os.chdir("js/src")
js_config["OLD_CONFIGURE_SUBSTS"] = old_js_configure_substs
js_config["OLD_CONFIGURE_DEFINES"] = old_js_configure_defines

Просмотреть файл

@ -2,7 +2,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import errno
import io
import itertools
import os
@ -284,11 +283,7 @@ class BuildBackend(LoggingMixin):
assert fh is not None
dirname = mozpath.dirname(fh.name)
try:
os.makedirs(dirname)
except OSError as error:
if error.errno != errno.EEXIST:
raise
os.makedirs(dirname, exist_ok=True)
yield fh

Просмотреть файл

@ -118,11 +118,7 @@ class CppEclipseBackend(CommonBackend):
workspace_settings_dir,
self._workspace_lang_dir,
]:
try:
os.makedirs(dir_name)
except OSError as e:
if e.errno != errno.EEXIST:
raise
os.makedirs(dir_name, exist_ok=True)
project_path = os.path.join(self._project_dir, ".project")
with open(project_path, "w") as fh:

Просмотреть файл

@ -4,7 +4,6 @@
# This modules provides functionality for dealing with compiler warnings.
import errno
import io
import json
import os
@ -282,12 +281,8 @@ class WarningsDatabase(object):
def save_to_file(self, filename):
"""Save the database to a file."""
try:
# Ensure the directory exists
os.makedirs(os.path.dirname(filename))
except OSError as e:
if e.errno != errno.EEXIST:
raise
# Ensure the directory exists
os.makedirs(os.path.dirname(filename), exist_ok=True)
with io.open(filename, "w", encoding="utf-8", newline="\n") as fh:
self.serialize(fh)

Просмотреть файл

@ -5,7 +5,6 @@
# This file contains miscellaneous utility functions that don't belong anywhere
# in particular.
import errno
import os
import sys
@ -20,11 +19,7 @@ def ensureParentDir(path):
"""Ensures the directory parent to the given file exists."""
d = os.path.dirname(path)
if d and not os.path.exists(path):
try:
os.makedirs(d)
except OSError as error:
if error.errno != errno.EEXIST:
raise
os.makedirs(d, exist_ok=True)
def mkdir(path, not_indexed=False):
@ -33,11 +28,7 @@ def mkdir(path, not_indexed=False):
If ``not_indexed`` is True, an attribute is set that disables content
indexing on the directory.
"""
try:
os.makedirs(path)
except OSError as e:
if e.errno != errno.EEXIST:
raise
os.makedirs(path, exist_ok=True)
if not_indexed:
if sys.platform == "win32":

Просмотреть файл

@ -402,11 +402,7 @@ class JarMaker(object):
if self.outputFormat == "jar":
# jar
jarfilepath = jarfile + ".jar"
try:
os.makedirs(os.path.dirname(jarfilepath))
except OSError as error:
if error.errno != errno.EEXIST:
raise
os.makedirs(os.path.dirname(jarfilepath), exist_ok=True)
jf = ZipFile(jarfilepath, "a", lock=True)
outHelper = self.OutputHelper_jar(jf)
else:
@ -578,11 +574,8 @@ class JarMaker(object):
out = os.path.join(self.basepath, name)
outdir = os.path.dirname(out)
if not os.path.isdir(outdir):
try:
os.makedirs(outdir)
except OSError as error:
if error.errno != errno.EEXIST:
raise
os.makedirs(outdir, exist_ok=True)
return out
class OutputHelper_symlink(OutputHelper_flat):

Просмотреть файл

@ -22,7 +22,6 @@ value :
| \w+ # string identifier or value;
"""
import errno
import io
import os
import re
@ -504,11 +503,8 @@ class Preprocessor:
encoding = "utf-8"
dir = os.path.dirname(path)
if dir:
try:
os.makedirs(dir)
except OSError as error:
if error.errno != errno.EEXIST:
raise
os.makedirs(dir, exist_ok=True)
return io.open(path, "w", encoding=encoding, newline="\n")
p = self.getCommandLineParser()

Просмотреть файл

@ -2,7 +2,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import errno
import os
import shutil
@ -26,11 +25,7 @@ def prepare_tmp_topsrcdir(path):
"build/moz.configure/util.configure",
):
file_path = os.path.join(path, p)
try:
os.makedirs(os.path.dirname(file_path))
except OSError as e:
if e.errno != errno.EEXIST:
raise
os.makedirs(os.path.dirname(file_path), exist_ok=True)
shutil.copy(os.path.join(topsrcdir, p), file_path)

Просмотреть файл

@ -304,11 +304,7 @@ class FileCopier(FileRegistry):
# symlinks and permissions and parent directories of the destination
# directory may have their own weird schema. The contract is we only
# manage children of destination, not its parents.
try:
os.makedirs(destination)
except OSError as e:
if e.errno != errno.EEXIST:
raise
os.makedirs(destination, exist_ok=True)
# Because we could be handling thousands of files, code in this
# function is optimized to minimize system calls. We prefer CPU time
@ -336,11 +332,7 @@ class FileCopier(FileRegistry):
# to directory X and we attempt to install a symlink in this directory
# to a file in directory X, we may create a recursive symlink!
for d in sorted(required_dirs, key=len):
try:
os.mkdir(d)
except OSError as error:
if error.errno != errno.EEXIST:
raise
os.makedirs(d, exist_ok=True)
# We allow the destination to be a symlink because the caller
# is responsible for managing the destination and we assume

Просмотреть файл

@ -193,11 +193,7 @@ class BaseFile(object):
if getattr(self, "path", None) and getattr(dest, "path", None):
# The destination directory must exist, or CopyFile will fail.
destdir = os.path.dirname(dest.path)
try:
os.makedirs(destdir)
except OSError as e:
if e.errno != errno.EEXIST:
raise
os.makedirs(destdir, exist_ok=True)
_copyfile(self.path, dest.path)
shutil.copystat(self.path, dest.path)
else: