1
0
mirror of synced 2025-04-19 00:24:02 +03:00

Split the header only if needed (#1060)

* Update split.py

* Update split.py

* Update split.py

* Update split.py
This commit is contained in:
David Pfahler 2021-09-29 00:11:50 +02:00 committed by GitHub
parent 3da42fd1e8
commit d87d0672a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,7 +19,26 @@ args_parser.add_argument(
args = args_parser.parse_args() args = args_parser.parse_args()
cur_dir = os.path.dirname(sys.argv[0]) cur_dir = os.path.dirname(sys.argv[0])
with open(cur_dir + '/httplib.h') as f: lib_name = 'httplib'
header_name = '/' + lib_name + '.h'
source_name = '/' + lib_name + '.' + args.extension
# get the input file
in_file = cur_dir + header_name
# get the output file
h_out = args.out + header_name
cc_out = args.out + source_name
# if the modification time of the out file is after the in file,
# don't split (as it is already finished)
do_split = True
if os.path.exists(h_out):
in_time = os.path.getmtime(in_file)
out_time = os.path.getmtime(h_out)
do_split = in_time > out_time
if do_split:
with open(in_file) as f:
lines = f.readlines() lines = f.readlines()
python_version = sys.version_info[0] python_version = sys.version_info[0]
@ -29,8 +48,7 @@ else:
os.makedirs(args.out, exist_ok=True) os.makedirs(args.out, exist_ok=True)
in_implementation = False in_implementation = False
h_out = args.out + '/httplib.h' cc_out = args.out + source_name
cc_out = args.out + '/httplib.' + args.extension
with open(h_out, 'w') as fh, open(cc_out, 'w') as fc: with open(h_out, 'w') as fh, open(cc_out, 'w') as fc:
fc.write('#include "httplib.h"\n') fc.write('#include "httplib.h"\n')
fc.write('namespace httplib {\n') fc.write('namespace httplib {\n')
@ -45,3 +63,5 @@ with open(h_out, 'w') as fh, open(cc_out, 'w') as fc:
fc.write('} // namespace httplib\n') fc.write('} // namespace httplib\n')
print("Wrote {} and {}".format(h_out, cc_out)) print("Wrote {} and {}".format(h_out, cc_out))
else:
print("{} and {} are up to date".format(h_out, cc_out))