Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # Push the {vers}/{plaform}/download_file_types.pb files to GCS so | 6 # Build and push the {vers}/{platform}/download_file_types.pb files to GCS so |
| 7 # that the component update system will pick them up and push them | 7 # that the component update system will pick them up and push them |
| 8 # to users. See README.md before running this. | 8 # to users. See README.md before running this. |
| 9 # | |
| 10 # Requires ninja and gsutil to be in the user's path. | |
| 9 | 11 |
| 10 import optparse | 12 import optparse |
| 11 import os | 13 import os |
| 14 import shutil | |
| 12 import subprocess | 15 import subprocess |
| 13 import sys | 16 import sys |
| 14 | 17 |
| 15 | 18 |
| 16 DEST_BUCKET = 'gs://chrome-component-file-type-policies' | 19 DEST_BUCKET = 'gs://chrome-component-file-type-policies' |
| 20 RESOURCE_SUBDIR = 'chrome/browser/resources/safe_browsing' | |
| 17 | 21 |
| 18 | 22 |
| 19 def main(): | 23 def main(): |
| 20 parser = optparse.OptionParser() | 24 parser = optparse.OptionParser() |
| 21 parser.add_option('-d', '--dir', | 25 parser.add_option('-d', '--dir', |
| 22 help='The directory containing ' | 26 help='An up-to-date GN/Ninja build directory, ' |
| 23 '{vers}/{platform}/download_file_types.pb files.') | 27 'such as ./out/Debug') |
|
vakh (use Gerrit instead)
2016/06/07 23:36:31
`out-gn` to be consistent?
| |
| 24 | 28 |
| 25 (opts, args) = parser.parse_args() | 29 (opts, args) = parser.parse_args() |
| 26 if opts.dir is None: | 30 if opts.dir is None: |
| 27 parser.print_help() | 31 parser.print_help() |
| 28 return 1 | 32 return 1 |
| 29 | 33 |
| 30 os.chdir(opts.dir) | 34 # Clear out the target dir before we build so we can be sure we've got |
| 35 # the freshest version. | |
| 36 all_dir = os.path.join(opts.dir, "gen", RESOURCE_SUBDIR, 'all') | |
| 37 if os.path.isdir(all_dir): | |
| 38 shutil.rmtree(all_dir) | |
| 39 | |
| 40 gn_command = ['ninja', | |
| 41 '-C', opts.dir, | |
| 42 RESOURCE_SUBDIR + ':make_all_file_types_protobuf'] | |
| 43 print "Running the following" | |
| 44 print " " + (' '.join(gn_command)) | |
| 45 if subprocess.call(gn_command): | |
| 46 print "Ninja failed." | |
| 47 return 1 | |
| 48 | |
| 49 os.chdir(all_dir) | |
| 31 | 50 |
| 32 # Sanity check that we're in the right place | 51 # Sanity check that we're in the right place |
| 33 assert opts.dir.endswith('/all'), '--dir should end with /all' | |
| 34 dirs = os.listdir('.') | 52 dirs = os.listdir('.') |
| 35 assert (len(dirs) == 1 and dirs[0].isdigit()), ( | 53 assert len(dirs) == 1 and dirs[0].isdigit(), ( |
| 36 'Should be exactly one version directory. Please delete the contents ' | 54 "Confused by lack of single versioned dir under " + all_dir) |
| 37 'of the target dir and regenerate the protos.') | |
| 38 | 55 |
| 39 # Push the files with their directories, in the form | 56 # Push the files with their directories, in the form |
| 40 # {vers}/{platform}/download_file_types.pb | 57 # {vers}/{platform}/download_file_types.pb |
| 41 # Don't overwrite existing files, incase we forgot to increment the | 58 # Don't overwrite existing files, in case we forgot to increment the |
| 42 # version. | 59 # version. |
| 43 vers_dir = dirs[0] | 60 vers_dir = dirs[0] |
| 44 command = ['gsutil', 'cp', '-Rn', vers_dir, DEST_BUCKET] | 61 command = ['gsutil', 'cp', '-Rn', vers_dir, DEST_BUCKET] |
| 45 | 62 |
| 46 print 'Going to run the following command' | 63 print '\nGoing to run the following command' |
| 47 print ' ', ' '.join(command) | 64 print ' ', ' '.join(command) |
| 48 print '\nIn directory' | 65 print '\nIn directory' |
| 49 print ' ', opts.dir | 66 print ' ', all_dir |
| 50 print '\nWhich should push the following files' | 67 print '\nWhich should push the following files' |
| 51 expected_files = [os.path.join(dp, f) for dp, dn, fn in | 68 expected_files = [os.path.join(dp, f) for dp, dn, fn in |
| 52 os.walk(vers_dir) for f in fn] | 69 os.walk(vers_dir) for f in fn] |
| 53 for f in expected_files: | 70 for f in expected_files: |
| 54 print ' ', f | 71 print ' ', f |
| 55 | 72 |
| 56 shall = raw_input('\nAre you sure (y/N) ').lower() == 'y' | 73 shall = raw_input('\nAre you sure (y/N) ').lower() == 'y' |
| 57 if not shall: | 74 if not shall: |
| 58 print 'aborting' | 75 print 'aborting' |
| 59 return 1 | 76 return 1 |
| 60 return subprocess.call(command) | 77 return subprocess.call(command) |
| 61 | 78 |
| 62 | 79 |
| 63 if __name__ == '__main__': | 80 if __name__ == '__main__': |
| 64 sys.exit(main()) | 81 sys.exit(main()) |
| 65 | 82 |
| OLD | NEW |