Bug 1569075 - Rename FileAvoidWrite mode argument. r=chmanchester
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 30 Jul 2019 21:03:12 +0000
changeset 549170 04d91a1c7fbf8cfa4b5dc63490dbe62206f9b95c
parent 549169 6d1d7fc0e34c54666297c4c0e6edea091415125d
child 549171 6da770bf3a21987d6295cec40bdd279dda7c804b
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1569075
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1569075 - Rename FileAvoidWrite mode argument. r=chmanchester It causes confusion because it's the mode used to _read_ the overwritten file. Make that more obvious by renaming to `readmode`. Differential Revision: https://phabricator.services.mozilla.com/D39445
python/mozbuild/mozbuild/action/file_generate.py
python/mozbuild/mozbuild/artifacts.py
python/mozbuild/mozbuild/backend/base.py
python/mozbuild/mozbuild/backend/test_manifest.py
python/mozbuild/mozbuild/backend/visualstudio.py
python/mozbuild/mozbuild/util.py
--- a/python/mozbuild/mozbuild/action/file_generate.py
+++ b/python/mozbuild/mozbuild/action/file_generate.py
@@ -61,17 +61,17 @@ def main(argv):
     method = args.method_name
     if not hasattr(module, method):
         print('Error: script "{0}" is missing a {1} method'.format(script, method),
               file=sys.stderr)
         return 1
 
     ret = 1
     try:
-        with FileAvoidWrite(args.output_file, mode='rb') as output:
+        with FileAvoidWrite(args.output_file, readmode='rb') as output:
             try:
                 ret = module.__dict__[method](output, *args.additional_arguments, **kwargs)
             except Exception:
                 # Ensure that we don't overwrite the file if the script failed.
                 output.avoid_writing_to_file()
                 raise
 
             # The following values indicate a statement of success:
--- a/python/mozbuild/mozbuild/artifacts.py
+++ b/python/mozbuild/mozbuild/artifacts.py
@@ -1068,17 +1068,17 @@ see https://developer.mozilla.org/en-US/
         if self._no_process:
             orig_basename = os.path.basename(filename)
             # Turn 'HASH-target...' into 'target...' if possible.  It might not
             # be possible if the file is given directly on the command line.
             before, _sep, after = orig_basename.rpartition('-')
             if re.match(r'[0-9a-fA-F]{16}$', before):
                 orig_basename = after
             path = mozpath.join(distdir, orig_basename)
-            with FileAvoidWrite(path, mode='rb') as fh:
+            with FileAvoidWrite(path, readmode='rb') as fh:
                 shutil.copyfileobj(open(filename, mode='rb'), fh)
             self.log(logging.INFO, 'artifact',
                      {'path': path},
                      'Copied unprocessed artifact: to {path}')
             return
 
         # Do we need to post-process?
         processed_filename = filename + PROCESSED_SUFFIX
@@ -1104,17 +1104,17 @@ see https://developer.mozilla.org/en-US/
                  {'processed_filename': processed_filename},
                  'Installing from processed {processed_filename}')
 
         with zipfile.ZipFile(processed_filename) as zf:
             for info in zf.infolist():
                 if info.filename.endswith('.ini'):
                     continue
                 n = mozpath.join(distdir, info.filename)
-                fh = FileAvoidWrite(n, mode='rb')
+                fh = FileAvoidWrite(n, readmode='rb')
                 shutil.copyfileobj(zf.open(info), fh)
                 file_existed, file_updated = fh.close()
                 self.log(logging.INFO, 'artifact',
                          {'updating': 'Updating' if file_updated else 'Not updating',
                           'filename': n},
                          '{updating} {filename}')
                 if not file_existed or file_updated:
                     # Libraries and binaries may need to be marked executable,
--- a/python/mozbuild/mozbuild/backend/base.py
+++ b/python/mozbuild/mozbuild/backend/base.py
@@ -258,32 +258,32 @@ class BuildBackend(LoggingMixin):
         If an exception is raised, |mach build| will fail with a
         non-zero exit code.
         """
         self._write_purgecaches(config)
 
         return status
 
     @contextmanager
-    def _write_file(self, path=None, fh=None, mode='rU'):
+    def _write_file(self, path=None, fh=None, readmode='rU'):
         """Context manager to write a file.
 
         This is a glorified wrapper around FileAvoidWrite with integration to
         update the summary data on this instance.
 
         Example usage:
 
             with self._write_file('foo.txt') as fh:
                 fh.write('hello world')
         """
 
         if path is not None:
             assert fh is None
             fh = FileAvoidWrite(path, capture_diff=True, dry_run=self.dry_run,
-                                mode=mode)
+                                readmode=readmode)
         else:
             assert fh is not None
 
         dirname = mozpath.dirname(fh.name)
         try:
             os.makedirs(dirname)
         except OSError as error:
             if error.errno != errno.EEXIST:
--- a/python/mozbuild/mozbuild/backend/test_manifest.py
+++ b/python/mozbuild/mozbuild/backend/test_manifest.py
@@ -50,24 +50,24 @@ class TestManifestBackend(PartialBackend
         for test in obj.tests:
             self.add(test, obj.flavor, obj.topsrcdir)
         self.add_defaults(obj.manifest)
         self.add_installs(obj, obj.topsrcdir)
 
     def consume_finished(self):
         topobjdir = self.environment.topobjdir
 
-        with self._write_file(mozpath.join(topobjdir, 'all-tests.pkl'), mode='rb') as fh:
+        with self._write_file(mozpath.join(topobjdir, 'all-tests.pkl'), readmode='rb') as fh:
             pickle.dump(dict(self.tests_by_path), fh, protocol=2)
 
-        with self._write_file(mozpath.join(topobjdir, 'test-defaults.pkl'), mode='rb') as fh:
+        with self._write_file(mozpath.join(topobjdir, 'test-defaults.pkl'), readmode='rb') as fh:
             pickle.dump(self.manifest_defaults, fh, protocol=2)
 
         path = mozpath.join(topobjdir, 'test-installs.pkl')
-        with self._write_file(path, mode='rb') as fh:
+        with self._write_file(path, readmode='rb') as fh:
             pickle.dump({k: v for k, v in self.installs_by_path.items()
                          if k in self.deferred_installs},
                         fh,
                         protocol=2)
 
     def add(self, t, flavor, topsrcdir):
         t = dict(t)
         t['flavor'] = flavor
--- a/python/mozbuild/mozbuild/backend/visualstudio.py
+++ b/python/mozbuild/mozbuild/backend/visualstudio.py
@@ -157,34 +157,34 @@ class VisualStudioBackend(CommonBackend)
         basename = 'target_vs'
         project_id = self._write_vs_project(
             out_proj_dir, basename, 'visual-studio',
             build_command='$(SolutionDir)\\mach.bat build-backend -b VisualStudio')
         projects[basename] = (project_id, basename, 'visual-studio')
 
         # Write out a shared property file with common variables.
         props_path = os.path.join(out_proj_dir, 'mozilla.props')
-        with self._write_file(props_path, mode='rb') as fh:
+        with self._write_file(props_path, readmode='rb') as fh:
             self._write_props(fh)
 
         # Generate some wrapper scripts that allow us to invoke mach inside
         # a MozillaBuild-like environment. We currently only use the batch
         # script. We'd like to use the PowerShell script. However, it seems
         # to buffer output from within Visual Studio (surely this is
         # configurable) and the default execution policy of PowerShell doesn't
         # allow custom scripts to be executed.
-        with self._write_file(os.path.join(out_dir, 'mach.bat'), mode='rb') as fh:
+        with self._write_file(os.path.join(out_dir, 'mach.bat'), readmode='rb') as fh:
             self._write_mach_batch(fh)
 
-        with self._write_file(os.path.join(out_dir, 'mach.ps1'), mode='rb') as fh:
+        with self._write_file(os.path.join(out_dir, 'mach.ps1'), readmode='rb') as fh:
             self._write_mach_powershell(fh)
 
         # Write out a solution file to tie it all together.
         solution_path = os.path.join(out_dir, 'mozilla.sln')
-        with self._write_file(solution_path, mode='rb') as fh:
+        with self._write_file(solution_path, readmode='rb') as fh:
             self._write_solution(fh, projects)
 
     def _write_projects_for_sources(self, sources, prefix, out_dir):
         projects = {}
         for item, path in sorted(sources.items()):
             config = self._paths_to_configs.get(path, None)
             sources = self._paths_to_sources.get(path, set())
             sources = set(os.path.join('$(TopSrcDir)', path, s) for s in sources)
@@ -456,21 +456,21 @@ class VisualStudioBackend(CommonBackend)
         # appropriate build tool.
         fh.write(b'"%%MOZILLABUILD%%\\msys\\bin\\bash" '
                  b'-c "%s/mach --log-no-times %%1 %%2 %%3 %%4 %%5 %%6 %%7"' % relpath)
 
     def _write_vs_project(self, out_dir, basename, name, **kwargs):
         root = '%s.vcxproj' % basename
         project_id = get_id(basename.encode('utf-8'))
 
-        with self._write_file(os.path.join(out_dir, root), mode='rb') as fh:
+        with self._write_file(os.path.join(out_dir, root), readmode='rb') as fh:
             project_id, name = VisualStudioBackend.write_vs_project(
                 fh, self._version, project_id, name, **kwargs)
 
-        with self._write_file(os.path.join(out_dir, '%s.user' % root), mode='rb') as fh:
+        with self._write_file(os.path.join(out_dir, '%s.user' % root), readmode='rb') as fh:
             fh.write('<?xml version="1.0" encoding="utf-8"?>\r\n')
             fh.write('<Project ToolsVersion="4.0" xmlns="%s">\r\n' %
                      MSBUILD_NAMESPACE)
             fh.write('</Project>\r\n')
 
         return project_id
 
     @staticmethod
--- a/python/mozbuild/mozbuild/util.py
+++ b/python/mozbuild/mozbuild/util.py
@@ -209,26 +209,26 @@ class FileAvoidWrite(BytesIO):
     enabled by default because it a) doesn't make sense for binary files b)
     could add unwanted overhead to calls.
 
     Additionally, there is dry run mode where the file is not actually written
     out, but reports whether the file was existing and would have been updated
     still occur, as well as diff capture if requested.
     """
 
-    def __init__(self, filename, capture_diff=False, dry_run=False, mode='rU'):
+    def __init__(self, filename, capture_diff=False, dry_run=False, readmode='rU'):
         BytesIO.__init__(self)
         self.name = filename
         assert type(capture_diff) == bool
         assert type(dry_run) == bool
-        assert 'r' in mode
+        assert 'r' in readmode
         self._capture_diff = capture_diff
         self._write_to_file = not dry_run
         self.diff = None
-        self.mode = mode
+        self.mode = readmode
 
     def write(self, buf):
         if isinstance(buf, six.text_type):
             buf = buf.encode('utf-8')
         BytesIO.write(self, buf)
 
     def avoid_writing_to_file(self):
         self._write_to_file = False