mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1241398 - Add a dry-run mode to mach build-backend
. r=gps
When doing build system changes affecting backend-generated files, I often use `mach build-backend --diff`. But most of the time I end up wanting to look at the full diff again when doing further changes, which leads me to stash my changes away, run `mach build-backend` to get the initial state again, unstash and rerun `mach build-backend --diff`. This has been a time drain for long enough :)
This commit is contained in:
parent
176579f61a
commit
2c359cbe55
@ -83,6 +83,8 @@ class BuildBackend(LoggingMixin):
|
||||
# Mapping of changed file paths to diffs of the changes.
|
||||
self.file_diffs = {}
|
||||
|
||||
self.dry_run = False
|
||||
|
||||
self._init()
|
||||
|
||||
def summary(self):
|
||||
@ -149,7 +151,8 @@ class BuildBackend(LoggingMixin):
|
||||
except IOError:
|
||||
pass
|
||||
try:
|
||||
os.unlink(full_path)
|
||||
if not self.dry_run:
|
||||
os.unlink(full_path)
|
||||
self._deleted_count += 1
|
||||
except OSError:
|
||||
pass
|
||||
@ -196,7 +199,7 @@ class BuildBackend(LoggingMixin):
|
||||
|
||||
if path is not None:
|
||||
assert fh is None
|
||||
fh = FileAvoidWrite(path, capture_diff=True)
|
||||
fh = FileAvoidWrite(path, capture_diff=True, dry_run=self.dry_run)
|
||||
else:
|
||||
assert fh is not None
|
||||
|
||||
|
@ -116,6 +116,8 @@ def config_status(topobjdir='.', topsrcdir='.',
|
||||
default=default_backends,
|
||||
help='what backend to build (default: %s).' %
|
||||
' '.join(default_backends))
|
||||
parser.add_argument('--dry-run', action='store_true',
|
||||
help='do everything except writing files out.')
|
||||
options = parser.parse_args()
|
||||
|
||||
# Without -n, the current directory is meant to be the top object directory
|
||||
@ -137,6 +139,10 @@ def config_status(topobjdir='.', topsrcdir='.',
|
||||
# or what is in BUILD_BACKENDS.
|
||||
selected_backends = [get_backend_class(b)(env) for b in options.backend]
|
||||
|
||||
if options.dry_run:
|
||||
for b in selected_backends:
|
||||
b.dry_run = True
|
||||
|
||||
reader = BuildReader(env)
|
||||
emitter = TreeMetadataEmitter(env)
|
||||
# This won't actually do anything because of the magic of generators.
|
||||
|
@ -607,7 +607,9 @@ class Build(MachCommandBase):
|
||||
help='Which backend to build.')
|
||||
@CommandArgument('-v', '--verbose', action='store_true',
|
||||
help='Verbose output.')
|
||||
def build_backend(self, backend, diff=False, verbose=False):
|
||||
@CommandArgument('-n', '--dry-run', action='store_true',
|
||||
help='Do everything except writing files out.')
|
||||
def build_backend(self, backend, diff=False, verbose=False, dry_run=False):
|
||||
python = self.virtualenv_manager.python_path
|
||||
config_status = os.path.join(self.topobjdir, 'config.status')
|
||||
|
||||
@ -625,6 +627,8 @@ class Build(MachCommandBase):
|
||||
args.append('--diff')
|
||||
if verbose:
|
||||
args.append('--verbose')
|
||||
if dry_run:
|
||||
args.append('--dry-run')
|
||||
|
||||
return self._run_command_in_objdir(args=args, pass_thru=True,
|
||||
ensure_exit_code=False)
|
||||
|
@ -139,11 +139,16 @@ class FileAvoidWrite(BytesIO):
|
||||
Instances can optionally capture diffs of file changes. This feature is not
|
||||
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, mode='rU'):
|
||||
def __init__(self, filename, capture_diff=False, dry_run=False, mode='rU'):
|
||||
BytesIO.__init__(self)
|
||||
self.name = filename
|
||||
self._capture_diff = capture_diff
|
||||
self._dry_run = dry_run
|
||||
self.diff = None
|
||||
self.mode = mode
|
||||
|
||||
@ -183,14 +188,15 @@ class FileAvoidWrite(BytesIO):
|
||||
finally:
|
||||
existing.close()
|
||||
|
||||
ensureParentDir(self.name)
|
||||
# Maintain 'b' if specified. 'U' only applies to modes starting with
|
||||
# 'r', so it is dropped.
|
||||
writemode = 'w'
|
||||
if 'b' in self.mode:
|
||||
writemode += 'b'
|
||||
with open(self.name, writemode) as file:
|
||||
file.write(buf)
|
||||
if not self._dry_run:
|
||||
ensureParentDir(self.name)
|
||||
# Maintain 'b' if specified. 'U' only applies to modes starting with
|
||||
# 'r', so it is dropped.
|
||||
writemode = 'w'
|
||||
if 'b' in self.mode:
|
||||
writemode += 'b'
|
||||
with open(self.name, writemode) as file:
|
||||
file.write(buf)
|
||||
|
||||
if self._capture_diff:
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user