def CallAndWriteDepfileIfStale(function, options, record_path=None, input_paths=None, input_strings=None, output_paths=None, force=False, pass_changes=False, depfile_deps=None, add_pydeps=True): """Wraps md5_check.CallAndRecordIfStale() and also writes dep & stamp files. Depfiles and stamp files are automatically added to output_paths when present in the |options| argument. They are then created after |function| is called. By default, only python dependencies are added to the depfile. If there are other input paths that are not captured by GN deps, then they should be listed in depfile_deps. It's important to write paths to the depfile that are already captured by GN deps since GN args can cause GN deps to change, and such changes are not immediately reflected in depfiles (http://crbug.com/589311). """ if not output_paths: raise Exception('At least one output_path must be specified.') input_paths = list(input_paths or []) input_strings = list(input_strings or []) output_paths = list(output_paths or []) python_deps = None if hasattr(options, 'depfile') and options.depfile: python_deps = _ComputePythonDependencies() input_paths += python_deps output_paths += [options.depfile] stamp_file = hasattr(options, 'stamp') and options.stamp if stamp_file: output_paths += [stamp_file] def on_stale_md5(changes): args = (changes, ) if pass_changes else () function(*args) if python_deps is not None: all_depfile_deps = list(python_deps) if add_pydeps else [] if depfile_deps: all_depfile_deps.extend(depfile_deps) WriteDepfile(options.depfile, output_paths[0], all_depfile_deps, add_pydeps=False) if stamp_file: Touch(stamp_file) md5_check.CallAndRecordIfStale(on_stale_md5, record_path=record_path, input_paths=input_paths, input_strings=input_strings, output_paths=output_paths, force=force, pass_changes=True)
def CheckCallAndRecord(should_call, message, force=False): self.called = False def MarkCalled(): self.called = True md5_check.CallAndRecordIfStale( MarkCalled, record_path=record_path.name, input_paths=input_files, input_strings=input_strings, force=force) self.failUnlessEqual(should_call, self.called, message)
def CallAndWriteDepfileIfStale(function, options, record_path=None, input_paths=None, input_strings=None, output_paths=None, force=False, pass_changes=False): """Wraps md5_check.CallAndRecordIfStale() and also writes dep & stamp files. Depfiles and stamp files are automatically added to output_paths when present in the |options| argument. They are then created after |function| is called. """ if not output_paths: raise Exception('At least one output_path must be specified.') input_paths = list(input_paths or []) input_strings = list(input_strings or []) output_paths = list(output_paths or []) python_deps = None if hasattr(options, 'depfile') and options.depfile: python_deps = GetPythonDependencies() # List python deps in input_strings rather than input_paths since the # contents of them does not change what gets written to the depfile. input_strings += python_deps output_paths += [options.depfile] stamp_file = hasattr(options, 'stamp') and options.stamp if stamp_file: output_paths += [stamp_file] def on_stale_md5(changes): args = (changes, ) if pass_changes else () function(*args) if python_deps is not None: WriteDepfile(options.depfile, python_deps + input_paths) if stamp_file: Touch(stamp_file) md5_check.CallAndRecordIfStale(on_stale_md5, record_path=record_path, input_paths=input_paths, input_strings=input_strings, output_paths=output_paths, force=force, pass_changes=True)
def CheckCallAndRecord(should_call, message, force=False, outputs_specified=False, outputs_missing=False, expected_changes=None, added_or_modified_only=None): output_paths = None if outputs_specified: output_file1 = tempfile.NamedTemporaryFile() if outputs_missing: output_file1.close() # Gets deleted on close(). output_paths = [output_file1.name] self.called = False self.changes = None if expected_changes or added_or_modified_only is not None: def MarkCalled(changes): self.called = True self.changes = changes else: def MarkCalled(): self.called = True md5_check.CallAndRecordIfStale( MarkCalled, record_path=record_path.name, input_paths=input_files, input_strings=input_strings, output_paths=output_paths, force=force, pass_changes=(expected_changes or added_or_modified_only) is not None) self.assertEqual(should_call, self.called, message) if expected_changes: description = self.changes.DescribeDifference() self.assertTrue( fnmatch.fnmatch(description, expected_changes), 'Expected %s to match %s' % (repr(description), repr(expected_changes))) if should_call and added_or_modified_only is not None: self.assertEqual(added_or_modified_only, self.changes.AddedOrModifiedOnly())