Skip to content

Commit 21efa92

Browse files
authored
Merge pull request #87 from xelatihy/amalgamate
Single include script
2 parents 8159e8b + bd76291 commit 21efa92

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Amalgamate Ubuntu 20.04 CI (GCC 9, 8)
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
ubuntu-build:
7+
runs-on: ubuntu-20.04
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
include:
12+
# Legacy/x86 compilers cause CI failures.
13+
#- {cxx: -DCMAKE_CXX_COMPILER=g++-8, arch: }
14+
- {cxx: , arch: } # default=gcc9
15+
#- {cxx: , arch: -DCMAKE_CXX_FLAGS="-m32"} # default=gcc9
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Compile with amalgamation
19+
run: |
20+
mkdir build &&
21+
mkdir build/fast_float &&
22+
python3 ./script/amalgamate.py > build/fast_float/fast_float.h &&
23+
cp tests/string_test.cpp build/ &&
24+
cd build &&
25+
g++ string_test.cpp

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Maksim Kita
33
Marcin Wojdyr
44
Neal Richardson
55
Tim Paine
6+
Fabio Pellacini

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ target_link_libraries(myprogram PUBLIC fast_float)
141141
142142
```
143143

144+
## Using as single header
145+
146+
The script `script/amalgamate.py` may be used to generate a single header
147+
version of the library if so desired.
148+
Just run the script from the root directory of this repository.
149+
You can customize the license type and output file if desired as described in
150+
the command line help.
144151

145152
## Credit
146153

script/amalgamate.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# text parts
2+
processed_files = { }
3+
4+
# authors
5+
for filename in ['AUTHORS', 'CONTRIBUTORS']:
6+
with open(filename) as f:
7+
text = ''
8+
for line in f:
9+
if filename == 'AUTHORS':
10+
text += '// fast_float by ' + line
11+
if filename == 'CONTRIBUTORS':
12+
text += '// with contributions from ' + line
13+
processed_files[filename] = text
14+
15+
# licenses
16+
for filename in ['LICENSE-MIT', 'LICENSE-APACHE']:
17+
with open(filename) as f:
18+
text = ''
19+
for line in f:
20+
text += '// ' + line
21+
processed_files[filename] = text
22+
23+
# code
24+
for filename in [ 'fast_float.h', 'float_common.h', 'ascii_number.h',
25+
'fast_table.h', 'decimal_to_binary.h', 'ascii_number.h',
26+
'simple_decimal_conversion.h', 'parse_number.h']:
27+
with open('include/fast_float/' + filename) as f:
28+
text = ''
29+
for line in f:
30+
if line.startswith('#include "'): continue
31+
text += line
32+
processed_files[filename] = text
33+
34+
# command line
35+
import argparse
36+
37+
parser = argparse.ArgumentParser(description='Amalgamate fast_float.')
38+
parser.add_argument('--license', default='MIT', help='choose license')
39+
parser.add_argument('--output', default='', help='output file (stdout if none')
40+
41+
args = parser.parse_args()
42+
43+
text = '\n\n'.join([
44+
processed_files['AUTHORS'], processed_files['CONTRIBUTORS'],
45+
processed_files['LICENSE-' + args.license],
46+
processed_files['fast_float.h'], processed_files['float_common.h'],
47+
processed_files['ascii_number.h'], processed_files['fast_table.h'],
48+
processed_files['decimal_to_binary.h'], processed_files['ascii_number.h'],
49+
processed_files['simple_decimal_conversion.h'],
50+
processed_files['parse_number.h']])
51+
52+
if args.output:
53+
with open(args.output, 'wt') as f:
54+
f.write(text)
55+
else:
56+
print(text)

0 commit comments

Comments
 (0)