Commit 53d98e32 authored by Ondrej Skopek's avatar Ondrej Skopek Committed by Commit Bot

Build file changes for adding Voice Search on the Local NTP.

Change integrity calculation to be able to add another
JavaScript file to the Local NTP. To be used when
porting Voice Search (go/local-ntp-voice-search).

Bug: 583291
Change-Id: I9c0c1c1ede827b7f77b14e744b24a495eca70387
Reviewed-on: https://chromium-review.googlesource.com/600429Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarChris Pickel <sfiera@chromium.org>
Commit-Queue: Ondrej Škopek <oskopek@google.com>
Cr-Commit-Position: refs/heads/master@{#491991}
parent 6233533c
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
input_path = "//chrome/browser/resources/local_ntp/local_ntp.js" local_ntp_resources = "//chrome/browser/resources/local_ntp"
header_path = "$target_gen_dir/local_ntp_js_integrity.h"
action("local_ntp_code_generate") { action("local_ntp_code_generate") {
script = "tools/generate_integrity_header.py" script = "tools/generate_integrity_header.py"
header_path = "$target_gen_dir/local_ntp_js_integrity.h"
local_ntp_js = local_ntp_resources + "/local_ntp.js"
inputs = [ inputs = [
input_path, local_ntp_js,
] ]
outputs = [ outputs = [
...@@ -17,8 +18,8 @@ action("local_ntp_code_generate") { ...@@ -17,8 +18,8 @@ action("local_ntp_code_generate") {
] ]
args = [ args = [
rebase_path(input_path, root_build_dir), "--output_path=" + rebase_path(header_path, root_build_dir),
rebase_path(header_path, root_build_dir), rebase_path(local_ntp_js, root_build_dir),
] ]
} }
......
...@@ -18,36 +18,39 @@ def ComputeIntegrity(input_path): ...@@ -18,36 +18,39 @@ def ComputeIntegrity(input_path):
return base64.b64encode(hasher.digest()) return base64.b64encode(hasher.digest())
def WriteHeader(input_path, integrity, output_path): def WriteHeader(input_paths_and_integrity, output_path):
with open(output_path, 'w') as f: with open(output_path, 'w') as f:
input_filename = os.path.basename(input_path)
f.write('// DO NOT MODIFY THIS FILE DIRECTLY!\n') f.write('// DO NOT MODIFY THIS FILE DIRECTLY!\n')
f.write('// IT IS GENERATED BY generate_integrity_header.py\n') f.write('// IT IS GENERATED BY generate_integrity_header.py\n')
f.write('// FROM ' + input_filename + '\n') f.write('// FROM:\n')
for (input_filename, _) in input_paths_and_integrity:
f.write('// * ' + input_filename + '\n')
f.write('\n') f.write('\n')
define_name = re.sub('\W', '_', input_filename.upper()) for (input_filename, integrity) in input_paths_and_integrity:
define_name = define_name + '_INTEGRITY' define_name = re.sub('\W', '_', input_filename.upper())
define_name = define_name + '_INTEGRITY'
f.write('#define ' + define_name + ' "' + integrity + '"\n') f.write('#define ' + define_name + ' "' + integrity + '"\n')
f.write('\n') f.write('\n')
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Generate a C++ header containing a sha256 checksum of the ' description='Generate a C++ header containing a sha256 checksum of the '
'input file.') 'input files.')
parser.add_argument('input_path', help='Path to input file') parser.add_argument('input_path', help='Path to an input file.', nargs='+')
parser.add_argument('output_path', help='Path to output header file') parser.add_argument('--output_path', help='Path to an output header file.')
args = parser.parse_args() args = parser.parse_args()
input_path = args.input_path input_paths = args.input_path
output_path = args.output_path output_path = args.output_path
integrity = ComputeIntegrity(input_path) input_paths_and_integrity = [(os.path.basename(path), ComputeIntegrity(path))
WriteHeader(input_path, integrity, output_path) for path in input_paths]
WriteHeader(input_paths_and_integrity, output_path)
return 0 return 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment