From 47120e853bcad76901aa6036c9443103bab46520 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 8 Jul 2024 09:47:25 -0400 Subject: [PATCH] Use a meson "generator" to deduplicate `.gen.hh` creation --- build-utils-meson/generate-header/meson.build | 9 +++++++++ meson.build | 3 ++- src/libexpr/meson.build | 9 +++------ src/libexpr/primops/meson.build | 11 +++-------- src/libstore/meson.build | 10 +++------- 5 files changed, 20 insertions(+), 22 deletions(-) create mode 100644 build-utils-meson/generate-header/meson.build diff --git a/build-utils-meson/generate-header/meson.build b/build-utils-meson/generate-header/meson.build new file mode 100644 index 000000000000..14baa90e096c --- /dev/null +++ b/build-utils-meson/generate-header/meson.build @@ -0,0 +1,9 @@ +bash = find_program('bash', native: true) + +gen_header = generator( + bash, + arguments : [ '-c', '{ echo \'R"__NIX_STR(\' && cat @INPUT@ && echo \')__NIX_STR"\'; } > "$1"', '_ignored_argv0', '@OUTPUT@' ], + output : '@PLAINNAME@.gen.hh', + #install : true, + #install_dir : get_option('includedir') / 'nix', +) diff --git a/meson.build b/meson.build index 356d978dc8e7..f09998ab6d6e 100644 --- a/meson.build +++ b/meson.build @@ -6,6 +6,7 @@ project('nix-dev-shell', 'cpp', subproject_dir : 'src', ) +# Internal Libraries subproject('libutil') subproject('libstore') subproject('libfetchers') @@ -18,7 +19,7 @@ subproject('libcmd') subproject('internal-api-docs') subproject('external-api-docs') -# C wrappers +# External C wrapper libraries subproject('libutil-c') subproject('libstore-c') subproject('libexpr-c') diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index 3025b6da1825..e65cf545f2d8 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -117,20 +117,17 @@ lexer_tab = custom_target( install_dir : get_option('includedir') / 'nix', ) +subdir('build-utils-meson/generate-header') + generated_headers = [] foreach header : [ 'imported-drv-to-derivation.nix', 'fetchurl.nix', 'call-flake.nix', ] - generated_headers += custom_target( - command : [ 'bash', '-c', '{ echo \'R"__NIX_STR(\' && cat @INPUT@ && echo \')__NIX_STR"\'; } > "$1"', '_ignored_argv0', '@OUTPUT@' ], - input : header, - output : '@PLAINNAME@.gen.hh', - ) + generated_headers += gen_header.process(header) endforeach - sources = files( 'attr-path.cc', 'attr-set.cc', diff --git a/src/libexpr/primops/meson.build b/src/libexpr/primops/meson.build index 96a1dd07ecf1..f910fe237681 100644 --- a/src/libexpr/primops/meson.build +++ b/src/libexpr/primops/meson.build @@ -1,12 +1,7 @@ -foreach header : [ +generated_headers += gen_header.process( 'derivation.nix', -] - generated_headers += custom_target( - command : [ 'bash', '-c', '{ echo \'R"__NIX_STR(\' && cat @INPUT@ && echo \')__NIX_STR"\'; } > "$1"', '_ignored_argv0', '@OUTPUT@' ], - input : header, - output : '@PLAINNAME@.gen.hh', - ) -endforeach + preserve_path_from: meson.project_source_root(), +) sources += files( 'context.cc', diff --git a/src/libstore/meson.build b/src/libstore/meson.build index 7444cba20b59..5324b2a1fd75 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -99,18 +99,14 @@ deps_public += nlohmann_json sqlite = dependency('sqlite3', 'sqlite', version : '>=3.6.19') deps_private += sqlite +subdir('build-utils-meson/generate-header') + generated_headers = [] foreach header : [ 'schema.sql', 'ca-specific-schema.sql', ] - generated_headers += custom_target( - command : [ 'bash', '-c', '{ echo \'R"__NIX_STR(\' && cat @INPUT@ && echo \')__NIX_STR"\'; } > "$1"', '_ignored_argv0', '@OUTPUT@' ], - input : header, - output : '@PLAINNAME@.gen.hh', - install : true, - install_dir : get_option('includedir') / 'nix', - ) + generated_headers += gen_header.process(header) endforeach busybox = find_program(get_option('sandbox-shell'), required : false)