diff options
author | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-08 21:43:26 +0000 |
---|---|---|
committer | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-08 21:43:26 +0000 |
commit | e20703d54a4a4667ca064ae773a05598601c35f3 (patch) | |
tree | ae808d48b756ef57f69b34c16583acfec9645b6a /native_client_sdk/src/build_tools | |
parent | 9dbe136c929f89d65bb303656972bff2eda860bd (diff) | |
download | chromium_src-e20703d54a4a4667ca064ae773a05598601c35f3.zip chromium_src-e20703d54a4a4667ca064ae773a05598601c35f3.tar.gz chromium_src-e20703d54a4a4667ca064ae773a05598601c35f3.tar.bz2 |
[NaCl SDK] Generate NOTICE file automatically.
BUG=149754
TBR=noelallen@chromium.org
R=sbc@chromium.org
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/11074004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160711 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk/src/build_tools')
-rwxr-xr-x | native_client_sdk/src/build_tools/build_sdk.py | 23 | ||||
-rwxr-xr-x | native_client_sdk/src/build_tools/generate_notice.py | 90 |
2 files changed, 111 insertions, 2 deletions
diff --git a/native_client_sdk/src/build_tools/build_sdk.py b/native_client_sdk/src/build_tools/build_sdk.py index c20f0a5..31658097 100755 --- a/native_client_sdk/src/build_tools/build_sdk.py +++ b/native_client_sdk/src/build_tools/build_sdk.py @@ -20,9 +20,9 @@ and whether it should upload an SDK to file storage (GSTORE) # std python includes import copy import datetime -import generate_make import optparse import os +import re import subprocess import sys @@ -30,6 +30,8 @@ import sys import buildbot_common import build_updater import build_utils +import generate_make +import generate_notice import manifest_util from tests import test_server @@ -168,7 +170,7 @@ def BuildStepMakePepperDirs(pepperdir, subdirs): def BuildStepCopyTextFiles(pepperdir, pepper_ver, revision): buildbot_common.BuildStep('Add Text Files') - files = ['AUTHORS', 'COPYING', 'LICENSE', 'NOTICE'] + files = ['AUTHORS', 'COPYING', 'LICENSE'] files = [os.path.join(SDK_SRC_DIR, filename) for filename in files] oshelpers.Copy(['-v'] + files + [pepperdir]) @@ -712,6 +714,22 @@ def BuildStepBuildLibraries(pepperdir, platform, directory, clean=True): clean=clean) +def BuildStepGenerateNotice(pepperdir): + # Look for LICENSE files + license_filenames_re = re.compile('LICENSE|COPYING') + + license_files = [] + for root, _, files in os.walk(pepperdir): + for filename in files: + if license_filenames_re.match(filename): + path = os.path.join(root, filename) + license_files.append(path) + print '\n'.join(license_files) + + notice_filename = os.path.join(pepperdir, 'NOTICE') + generate_notice.Generate(notice_filename, pepperdir, license_files) + + def BuildStepTarBundle(pepper_ver, tarfile): buildbot_common.BuildStep('Tar Pepper Bundle') buildbot_common.MakeDir(os.path.dirname(tarfile)) @@ -963,6 +981,7 @@ def main(args): # Ship with libraries prebuilt, so run that first. BuildStepBuildLibraries(pepperdir, platform, 'src') + BuildStepGenerateNotice(pepperdir) if not options.skip_tar: BuildStepTarBundle(pepper_ver, tarfile) diff --git a/native_client_sdk/src/build_tools/generate_notice.py b/native_client_sdk/src/build_tools/generate_notice.py new file mode 100755 index 0000000..ffc376b --- /dev/null +++ b/native_client_sdk/src/build_tools/generate_notice.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Build the NOTICE file distributed with the NaCl SDK from a set of given +license files.""" + +import optparse +import os +import sys + + +def Trace(msg): + if Trace.verbose: + print msg + +Trace.verbose = False + + +def FindFiles(files): + found = [f for f in files if os.path.exists(f)] + + if Trace.verbose: + for f in sorted(set(files) - set(found)): + Trace('Skipping %s. File doesn\'t exist.\n' % (f,)) + + return found + + +def CreateLicenseDict(files): + # Many of the license files are duplicates. Create a map of license text to + # filename. + license_dict = {} + for filename in files: + license_text = open(filename).read() + license_dict.setdefault(license_text, []).append(filename) + + # Flip the dictionary (map tuple of filenames -> license text). + return dict((tuple(value), key) for key, value in license_dict.iteritems()) + + +def WriteLicense(output_file, root, license_text, license_filenames): + Trace('Writing license for files:\n' + '\n'.join(license_filenames)) + output_file.write('=' * 70 + '\n') + for filename in sorted(license_filenames): + filename = os.path.relpath(filename, root) + license_dir = os.path.dirname(filename) + if not license_dir: + license_dir = 'native_client_sdk' + + output_file.write('%s is licensed as follows\n' % (license_dir,)) + output_file.write(' (Cf. %s):\n' % (filename,)) + output_file.write('=' * 70 + '\n') + output_file.write(license_text) + output_file.write('\n\n\n') + + +def Generate(output_filename, root, files): + found_files = FindFiles(files) + license_dict = CreateLicenseDict(found_files) + with open(output_filename, 'w') as output_file: + for license_filenames in sorted(license_dict.iterkeys()): + license_text = license_dict[license_filenames] + WriteLicense(output_file, root, license_text, license_filenames) + + +def main(args): + parser = optparse.OptionParser() + parser.add_option('-v', '--verbose', help='Verbose output.', + action='store_true') + parser.add_option('-o', '--output', help='Output file') + parser.add_option('--root', help='Root for all paths') + + options, args = parser.parse_args(args) + Trace.verbose = options.verbose + + if not options.output: + parser.error('No output file given. See -o.') + if not options.root: + parser.error('No root directory given. See --root.') + + Generate(options.output, options.root, args) + Trace('Done.') + + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) |