Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: native_client_sdk/src/build_tools/generate_notice.py

Issue 11074004: [NaCl SDK] Generate NOTICE file automatically. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « native_client_sdk/src/build_tools/build_sdk.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/build_tools/generate_notice.py
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 0000000000000000000000000000000000000000..ffc376bcc8093495eede49c5225b9f5cd98c2d68
--- /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:]))
« no previous file with comments | « native_client_sdk/src/build_tools/build_sdk.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698