osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-dev/+/37343?usp=email )
Change subject: gen_makefile: write content into a buffer first ......................................................................
gen_makefile: write content into a buffer first
Instead of directly writing the new Makefile, write the new content into a buffer variable first. This ensures that we don't abort half-way while writing the Makefile, and it allows replacing spaces -> tabs in the next patch.
Change-Id: I9a0ee9aa5047b7d9af9673465441039cd55c221b --- M gen_makefile.py 1 file changed, 44 insertions(+), 27 deletions(-)
Approvals: osmith: Looks good to me, approved; Verified
diff --git a/gen_makefile.py b/gen_makefile.py index ca9003a..76c81f8 100755 --- a/gen_makefile.py +++ b/gen_makefile.py @@ -465,19 +465,15 @@ if not build_dir: build_dir = make_dir
-output = os.path.join(make_dir, args.output) -print('Writing to %r' % output) +content = '# This Makefile was generated by %s\n' % os.path.basename(sys.argv[0])
-with open(output, 'w') as out: - out.write('# This Makefile was generated by %s\n' % os.path.basename(sys.argv[0])) +configure_opts_args = "" +for f in configure_opts_files: + if not f.endswith(".deps"): + configure_opts_args += f' \\n\t\t{os.path.relpath(f, make_dir)}'
- configure_opts_args = "" - for f in configure_opts_files: - if not f.endswith(".deps"): - configure_opts_args += f' \\n\t\t{os.path.relpath(f, make_dir)}' - - # convenience: add a regen target that updates the generated makefile itself - out.write(r''' +# convenience: add a regen target that updates the generated makefile itself +content += r''' default: usrp
# @@ -567,26 +563,33 @@ docker_cmd=f' \\n\t\t--docker-cmd "{args.docker_cmd}"' if args.docker_cmd else '', build_debug=f' \\n\t\t--build-debug' if args.build_debug else '', auto_distclean=' \\n\t\t--auto-distclean' if args.auto_distclean else '', - )) +)
- # convenience target: clone all repositories first - out.write('clone: \\n\t' + ' \\n\t'.join([ '.make.%s.clone' % p for p, d in projects_deps ]) + '\n\n') +# convenience target: clone all repositories first +content += 'clone: \\n\t' + ' \\n\t'.join([ '.make.%s.clone' % p for p, d in projects_deps ]) + '\n\n'
- # convenience target: clean all - out.write('clean: \\n\t' + ' \\n\t'.join([ '%s-clean' % p for p, d in projects_deps ]) + '\n\n') +# convenience target: clean all +content += 'clean: \\n\t' + ' \\n\t'.join([ '%s-clean' % p for p, d in projects_deps ]) + '\n\n'
- # now the actual useful build rules - out.write('all: clone all-install\n\n') +# now the actual useful build rules +content += 'all: clone all-install\n\n'
- out.write('all-install: \\n\t' + ' \\n\t'.join([ '.make.%s.install' % p for p, d in projects_deps ]) + '\n\n') +content += 'all-install: \\n\t' + ' \\n\t'.join([ '.make.%s.install' % p for p, d in projects_deps ]) + '\n\n'
- for proj, deps in projects_deps: - all_config_opts = [] - all_config_opts.extend(configure_opts.get('ALL') or []) - all_config_opts.extend(configure_opts.get(proj) or []) - out.write(gen_make(proj, deps, all_config_opts, args.jobs, - make_dir, args.src_dir, build_dir, args.url, args.push_url, - args.sudo_make_install, args.no_ldconfig, - args.ldconfig_without_sudo, args.make_check)) +for proj, deps in projects_deps: + all_config_opts = [] + all_config_opts.extend(configure_opts.get('ALL') or []) + all_config_opts.extend(configure_opts.get(proj) or []) + content += gen_make(proj, deps, all_config_opts, args.jobs, + make_dir, args.src_dir, build_dir, args.url, args.push_url, + args.sudo_make_install, args.no_ldconfig, + args.ldconfig_without_sudo, args.make_check) + + +output = os.path.join(make_dir, args.output) +print('Writing to %r' % output) + +with open(output, 'w') as out: + out.write(content)
# vim: expandtab tabstop=2 shiftwidth=2