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
--- 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: