From f150b3f7f8d0f06e7d06cf5a413f75275f67f629 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Fri, 15 Mar 2024 18:55:59 -0600 Subject: [PATCH] meson: migrate generated headers to a generator() object Change-Id: Ie7b9cab4189825e8f02dfb39d298302bc36fcb61 --- meson.build | 12 ++++++++++++ src/libstore/meson.build | 25 +++---------------------- src/meson.build | 39 ++++++++++++--------------------------- src/nix/meson.build | 22 ++-------------------- 4 files changed, 29 insertions(+), 69 deletions(-) diff --git a/meson.build b/meson.build index 7b37c002e..5a09c0aee 100644 --- a/meson.build +++ b/meson.build @@ -116,6 +116,18 @@ deps += lowdown bash = find_program('bash') lsof = find_program('lsof') +# This is how Nix does generated headers... +# FIXME(Qyriad): do we really need to use the shell for this? +gen_header = generator( + bash, + arguments : [ + '-c', + 'echo \'R"foo(\' | cat - @INPUT@ && echo \')foo"\'', + ], + capture : true, + output : '@PLAINNAME@.gen.hh', +) + # # Configuration # diff --git a/src/libstore/meson.build b/src/libstore/meson.build index bbfa978d0..fc53a1bab 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -1,24 +1,5 @@ -schema_sql_gen = custom_target( - input : 'schema.sql', - output : 'schema.sql.gen.hh', - command : [ - bash, - '-c', - 'echo \'R"foo(\' | cat - @INPUT@ && echo \')foo"\'', - ], - capture : true, -) - -ca_specific_schema = custom_target( - input : 'ca-specific-schema.sql', - output : 'ca-specific-schema.sql.gen.hh', - command : [ - bash, - '-c', - 'echo \'R"foo(\' | cat - @INPUT@ && echo \')foo"\'', - ], - capture : true, -) +schema_sql_gen = gen_header.process('schema.sql') +ca_specific_schema_gen = gen_header.process('ca-specific-schema.sql') libstore_sources = files( 'binary-cache-store.cc', @@ -117,7 +98,7 @@ endforeach libstore = library( 'nixstore', schema_sql_gen, - ca_specific_schema, + ca_specific_schema_gen, libstore_sources, dependencies : [ libarchive, diff --git a/src/meson.build b/src/meson.build index 82302dcd3..f97b66252 100644 --- a/src/meson.build +++ b/src/meson.build @@ -25,43 +25,27 @@ nix_build_sources = files( nix_channel_sources = files( 'nix-channel/nix-channel.cc', ) -unpack_channel_gen = custom_target( - input : 'nix-channel/unpack-channel.nix', - output : 'unpack-channel.nix.gen.hh', - command : [ - bash, - '-c', - 'echo \'R"foo(\' | cat - @INPUT@ && echo \')foo"\'', - ], - capture : true, -) +unpack_channel_gen = gen_header.process('nix-channel/unpack-channel.nix') nix_collect_garbage_sources = files( 'nix-collect-garbage/nix-collect-garbage.cc', ) nix_copy_closure_sources = files( 'nix-copy-closure/nix-copy-closure.cc', ) +nix_env_buildenv_gen = gen_header.process('nix-env/buildenv.nix') +nix_env_sources = files( + 'nix-env/nix-env.cc', + 'nix-env/user-env.cc', +) +nix_instantiate_sources = files( + 'nix-instantiate/nix-instantiate.cc', +) nix_store_sources = files( 'nix-store/dotgraph.cc', 'nix-store/graphml.cc', 'nix-store/nix-store.cc', ) -nix_env_buildenv = custom_target( - input : 'nix-env/buildenv.nix', - output : 'buildenv.nix.gen.hh', - command : [ - bash, - '-c', - 'echo \'R"foo(\' | cat - @INPUT@ && echo \')foo"\'', - ], - capture : true, -) -nix_env_sources = files( - 'nix-env/nix-env.cc', - 'nix-env/user-env.cc', -) - # Hurray for Meson list flattening! nix2_commands_sources = [ build_remote_sources, @@ -70,9 +54,10 @@ nix2_commands_sources = [ unpack_channel_gen, nix_collect_garbage_sources, nix_copy_closure_sources, - nix_store_sources, - nix_env_buildenv, + nix_env_buildenv_gen, nix_env_sources, + nix_instantiate_sources, + nix_store_sources, ] # Finally, the nix command itself, which all of the other commands are implmented in terms of diff --git a/src/nix/meson.build b/src/nix/meson.build index af99364e4..f1ddeb3db 100644 --- a/src/nix/meson.build +++ b/src/nix/meson.build @@ -1,24 +1,6 @@ -generate_manpage_gen = custom_target( - input : meson.project_source_root() / 'doc/manual/generate-manpage.nix', - output : 'generate-manpage.nix.gen.hh', - command : [ - bash, - '-c', - 'echo \'R"foo(\' | cat - @INPUT@ && echo \')foo"\'', - ], - capture : true, -) +generate_manpage_gen = gen_header.process(meson.project_source_root() / 'doc/manual/generate-manpage.nix') -utils_gen = custom_target( - input : meson.project_source_root() / 'doc/manual/utils.nix', - output : 'utils.nix.gen.hh', - command : [ - bash, - '-c', - 'echo \'R"foo(\' | cat - @INPUT@ && echo \')foo"\'', - ], - capture : true, -) +utils_gen = gen_header.process(meson.project_source_root() / 'doc/manual/utils.nix') nix_sources = files( 'add-to-store.cc',