|
10 | 10 | text += '// fast_float by ' + line |
11 | 11 | if filename == 'CONTRIBUTORS': |
12 | 12 | text += '// with contributions from ' + line |
13 | | - processed_files[filename] = text |
| 13 | + processed_files[filename] = text + '//\n' |
14 | 14 |
|
15 | 15 | # licenses |
16 | 16 | for filename in ['LICENSE-MIT', 'LICENSE-APACHE']: |
| 17 | + lines = [] |
17 | 18 | with open(filename) as f: |
18 | | - text = '' |
19 | | - for line in f: |
20 | | - text += '// ' + line |
21 | | - processed_files[filename] = text |
| 19 | + lines = f.readlines() |
| 20 | + |
| 21 | + # Retrieve subset required for inclusion in source |
| 22 | + if filename == 'LICENSE-APACHE': |
| 23 | + lines = [ |
| 24 | + ' Copyright 2021 The fast_float authors\n', |
| 25 | + *lines[189:-1] |
| 26 | + ] |
| 27 | + |
| 28 | + text = '' |
| 29 | + for line in lines: |
| 30 | + text += '// ' + line.strip() + '\n' |
| 31 | + processed_files[filename] = text |
22 | 32 |
|
23 | 33 | # code |
24 | 34 | for filename in [ 'fast_float.h', 'float_common.h', 'ascii_number.h', |
|
29 | 39 | for line in f: |
30 | 40 | if line.startswith('#include "'): continue |
31 | 41 | text += line |
32 | | - processed_files[filename] = text |
| 42 | + processed_files[filename] = '\n' + text |
33 | 43 |
|
34 | 44 | # command line |
35 | 45 | import argparse |
36 | 46 |
|
37 | 47 | parser = argparse.ArgumentParser(description='Amalgamate fast_float.') |
38 | | -parser.add_argument('--license', default='MIT', help='choose license') |
| 48 | +parser.add_argument('--license', default='DUAL', choices=['DUAL', 'MIT', 'APACHE'], help='choose license') |
39 | 49 | parser.add_argument('--output', default='', help='output file (stdout if none') |
40 | 50 |
|
41 | 51 | args = parser.parse_args() |
42 | 52 |
|
43 | | -text = '\n\n'.join([ |
| 53 | +def license_content(license_arg): |
| 54 | + result = [] |
| 55 | + |
| 56 | + if license_arg == 'DUAL': |
| 57 | + result += [ |
| 58 | + '// Licensed under the Apache License, Version 2.0, or the\n', |
| 59 | + '// MIT License at your option. This file may not be copied,\n', |
| 60 | + '// modified, or distributed except according to those terms.\n', |
| 61 | + '//\n' |
| 62 | + ] |
| 63 | + |
| 64 | + if license_arg in ('DUAL', 'MIT'): |
| 65 | + result.append('// MIT License Notice\n//\n') |
| 66 | + result.append(processed_files['LICENSE-MIT']) |
| 67 | + result.append('//\n') |
| 68 | + if license_arg in ('DUAL', 'APACHE'): |
| 69 | + result.append('// Apache License (Version 2.0) Notice\n//\n') |
| 70 | + result.append(processed_files['LICENSE-APACHE']) |
| 71 | + result.append('//\n') |
| 72 | + |
| 73 | + return result |
| 74 | + |
| 75 | +text = ''.join([ |
44 | 76 | processed_files['AUTHORS'], processed_files['CONTRIBUTORS'], |
45 | | - processed_files['LICENSE-' + args.license], |
| 77 | + *license_content(args.license), |
46 | 78 | processed_files['fast_float.h'], processed_files['float_common.h'], |
47 | 79 | processed_files['ascii_number.h'], processed_files['fast_table.h'], |
48 | 80 | processed_files['decimal_to_binary.h'], processed_files['bigint.h'], |
|
0 commit comments