def _VerifyManifest(actual_manifest, expected_file, normalized_manifest, expected_manifest_base_expectation, unexpected_manifest_failure_file, fail_on_mismatch): with build_utils.AtomicOutput(normalized_manifest) as normalized_output: normalized_output.write(manifest_utils.NormalizeManifest(actual_manifest)) if expected_manifest_base_expectation: with tempfile.NamedTemporaryFile() as generated_diff: actual_diff_content = diff_utils.GenerateDiffWithOnlyAdditons( expected_manifest_base_expectation, normalized_manifest) generated_diff.write(actual_diff_content) generated_diff.flush() msg = diff_utils.DiffFileContents(expected_file, generated_diff.name) else: msg = diff_utils.DiffFileContents(expected_file, normalized_manifest) if not msg: return msg_header = """\ AndroidManifest.xml expectations file needs updating. For details see: https://chromium.googlesource.com/chromium/src/+/HEAD/chrome/android/java/README.md """ sys.stderr.write(msg_header) sys.stderr.write(msg) if unexpected_manifest_failure_file: build_utils.MakeDirectory(os.path.dirname(unexpected_manifest_failure_file)) with open(unexpected_manifest_failure_file, 'w') as f: f.write(msg_header) f.write(msg) if fail_on_mismatch: sys.exit(1)
def _VerifyExpectedConfigs(expected_path, actual_path, fail_on_exit): diff = diff_utils.DiffFileContents(expected_path, actual_path, 'Proguard Flags') if not diff: return print diff if fail_on_exit: sys.exit(1)
def _VerifyExpectedConfigs(expected_path, actual_path, fail_on_exit): msg = diff_utils.DiffFileContents(expected_path, actual_path) if not msg: return sys.stderr.write("""\ Proguard flag expectations file needs updating. For details see: https://chromium.googlesource.com/chromium/src/+/HEAD/chrome/android/java/README.md """) sys.stderr.write(msg) if fail_on_exit: sys.exit(1)
def _VerifyManifest(actual_manifest, expected_manifest, normalized_manifest, fail_if_unexpected_manifest): with build_utils.AtomicOutput(normalized_manifest) as normalized_output: normalized_output.write(manifest_utils.NormalizeManifest(actual_manifest)) msg = diff_utils.DiffFileContents(expected_manifest, normalized_manifest) if msg: sys.stderr.write("""\ AndroidManifest.xml expectations file needs updating. For details see: https://chromium.googlesource.com/chromium/src/+/HEAD/chrome/android/java/README.md """) sys.stderr.write(msg) if fail_if_unexpected_manifest: sys.exit(1)
def _VerifyExpectedConfigs(expected_path, actual_path, failure_file_path): msg = diff_utils.DiffFileContents(expected_path, actual_path) if not msg: return msg_header = """\ ProGuard flag expectations file needs updating. For details see: https://chromium.googlesource.com/chromium/src/+/HEAD/chrome/android/java/README.md """ sys.stderr.write(msg_header) sys.stderr.write(msg) if failure_file_path: build_utils.MakeDirectory(os.path.dirname(failure_file_path)) with open(failure_file_path, 'w') as f: f.write(msg_header) f.write(msg)
def _VerifyExpectedConfigs(expected_path, actual_path, fail_on_exit): diff = diff_utils.DiffFileContents(expected_path, actual_path) if not diff: return print """ {} Detected Proguard flags change. Please update by running: cp {} {} See https://chromium.googlesource.com/chromium/src/+/HEAD/chrome/android/java/README.md for more info. """.format(diff, os.path.abspath(actual_path), os.path.abspath(expected_path)) if fail_on_exit: sys.exit(1)
def _VerifyManifest(actual_manifest, expected_manifest, normalized_manifest, unexpected_manifest_failure_file): with build_utils.AtomicOutput(normalized_manifest) as normalized_output: normalized_output.write(manifest_utils.NormalizeManifest(actual_manifest)) msg = diff_utils.DiffFileContents(expected_manifest, normalized_manifest) if not msg: return msg_header = """\ AndroidManifest.xml expectations file needs updating. For details see: https://chromium.googlesource.com/chromium/src/+/HEAD/chrome/android/java/README.md """ sys.stderr.write(msg_header) sys.stderr.write(msg) if unexpected_manifest_failure_file: build_utils.MakeDirectory(os.path.dirname(unexpected_manifest_failure_file)) with open(unexpected_manifest_failure_file, 'w') as f: f.write(msg_header) f.write(msg)
def _VerifyNativeLibsAndAssets( native_libs, assets, expectation_file_path, unexpected_native_libs_and_assets_failure_file_path, fail_on_mismatch): """Verifies the native libraries and assets are as expected. Check that the native libraries and assets being added are consistent with the expectation file. """ native_libs = sorted(native_libs) assets = sorted(assets) with tempfile.NamedTemporaryFile() as generated_output: for apk_path, _, compress, alignment in native_libs + assets: generated_output.write('apk_path=%s, compress=%s, alignment=%s\n' % (apk_path, compress, alignment)) generated_output.flush() msg = diff_utils.DiffFileContents(expectation_file_path, generated_output.name, show_files_compared=False) if not msg: return msg_header = """\ Native Libraries and Assets expectations file needs updating. For details see: https://chromium.googlesource.com/chromium/src/+/HEAD/chrome/android/java/README.md """ sys.stderr.write(msg_header) sys.stderr.write(msg) if unexpected_native_libs_and_assets_failure_file_path: build_utils.MakeDirectory( os.path.dirname( unexpected_native_libs_and_assets_failure_file_path)) with open(unexpected_native_libs_and_assets_failure_file_path, 'w') as f: f.write(msg_header) f.write(msg) if fail_on_mismatch: sys.exit(1)
def main(argv): argv = build_utils.ExpandFileArgs(argv) parser = argparse.ArgumentParser(description=__doc__) build_utils.AddDepfileOption(parser) parser.add_argument('--build-vars', help='Path to GN build vars file', required=True) parser.add_argument('--root-manifest', help='Root manifest which to merge into', required=True) parser.add_argument('--expected-manifest', help='Expected contents for the merged manifest.') parser.add_argument('--normalized-output', help='Normalized merged manifest.') parser.add_argument( '--verify-expected-manifest', action='store_true', help='Fail if expected contents do not match merged manifest contents.' ) parser.add_argument('--output', help='Output manifest path', required=True) parser.add_argument('--extras', help='GN list of additional manifest to merge') args = parser.parse_args(argv) classpath = _BuildManifestMergerClasspath( build_utils.ReadBuildVars(args.build_vars)) with build_utils.AtomicOutput(args.output) as output: cmd = [ 'java', '-cp', classpath, _MANIFEST_MERGER_MAIN_CLASS, '--out', output.name, ] extras = build_utils.ParseGnList(args.extras) if extras: cmd += ['--libs', ':'.join(extras)] with _ProcessManifest(args.root_manifest) as tup: root_manifest, package = tup cmd += [ '--main', root_manifest, '--property', 'PACKAGE=' + package ] build_utils.CheckOutput( cmd, # https://issuetracker.google.com/issues/63514300: # The merger doesn't set a nonzero exit code for failures. fail_func=lambda returncode, stderr: returncode != 0 or build_utils.IsTimeStale(output.name, [root_manifest] + extras)) if args.expected_manifest: with build_utils.AtomicOutput( args.normalized_output) as normalized_output: normalized_output.write(_NormalizeManifest(args.output)) msg = diff_utils.DiffFileContents(args.expected_manifest, args.normalized_output) if msg: sys.stderr.write("""\ AndroidManifest.xml expectations file needs updating. For details see: https://chromium.googlesource.com/chromium/src/+/HEAD/chrome/android/java/README.md """) sys.stderr.write(msg) if args.verify_expected_manifest: sys.exit(1) if args.depfile: inputs = extras + classpath.split(':') build_utils.WriteDepfile(args.depfile, args.output, inputs=inputs, add_pydeps=False)