Bug 1260299 - Allow _write_file to pass mode argument to FileAvoidWrite; r?chmanchester draft
authorGregory Szorc <gps@mozilla.com>
Thu, 19 May 2016 21:03:07 -0700
changeset 369053 95779ee5d5babde81e3185747b7b7e2050e94775
parent 369052 c7323d81b54c02a06fe966f9c5215fb1ccf8e6fa
child 369054 11e6fa78f7418de9ac77da2f3fe15e0633991562
push id18715
push userbmo:gps@mozilla.com
push dateFri, 20 May 2016 04:59:11 +0000
reviewerschmanchester
bugs1260299
milestone49.0a1
Bug 1260299 - Allow _write_file to pass mode argument to FileAvoidWrite; r?chmanchester Currently, self._write_file() instantiates FileAvoidWrite instances with the default mode of 'rU' which uses universal newlines (\n). Visual Studio project files use CRLF newlines. We want to use self._write_file() in the Visual Studio backend (which predates self._write_file). Prepare for this by passing the mode argument through. MozReview-Commit-ID: LHCUf3IrpJ8
python/mozbuild/mozbuild/backend/base.py
--- a/python/mozbuild/mozbuild/backend/base.py
+++ b/python/mozbuild/mozbuild/backend/base.py
@@ -190,31 +190,32 @@ class BuildBackend(LoggingMixin):
         This is the main method used by child classes to react to build
         metadata.
         """
 
     def consume_finished(self):
         """Called when consume() has completed handling all objects."""
 
     @contextmanager
-    def _write_file(self, path=None, fh=None):
+    def _write_file(self, path=None, fh=None, mode='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)
+            fh = FileAvoidWrite(path, capture_diff=True, dry_run=self.dry_run,
+                                mode=mode)
         else:
             assert fh is not None
 
         dirname = mozpath.dirname(fh.name)
         try:
             os.makedirs(dirname)
         except OSError as error:
             if error.errno != errno.EEXIST: