Make .standalone programs same as normal and avoid double compilation (#40148)

This commit is contained in:
Daan De Meyer
2025-12-19 14:58:34 +01:00
committed by GitHub
8 changed files with 59 additions and 101 deletions

View File

@@ -2517,6 +2517,7 @@ foreach dict : executables
is_test = name.startswith('test-')
is_fuzz = name.startswith('fuzz-')
is_standalone = name.endswith('.standalone')
build = true
foreach cond : dict.get('conditions', [])
@@ -2529,17 +2530,13 @@ foreach dict : executables
continue
endif
if name.endswith('.standalone') and not have_standalone_binaries
continue
endif
exe_sources = dict.get('sources', []) + dict.get('extract', [])
kwargs = {}
foreach key, val : dict
if key in ['name', 'dbus', 'public', 'conditions', 'type', 'suite',
'timeout', 'parallel', 'objects', 'sources', 'extract',
'include_directories']
'include_directories', 'build_by_default']
continue
endif
@@ -2551,7 +2548,7 @@ foreach dict : executables
endforeach
include_directories = dict['include_directories']
if not is_test
if not is_test and exe_sources.length() > 0
include_directories += fs.parent(exe_sources[0])
endif
@@ -2579,17 +2576,21 @@ foreach dict : executables
endforeach
endif
build_by_default = dict.get('build_by_default',
have_standalone_binaries or not is_standalone)
exe = executable(
name,
sources : exe_sources,
kwargs : kwargs,
implicit_include_directories : false,
include_directories : include_directories,
build_by_default: build_by_default,
)
executables_by_name += { name : exe }
if not name.endswith('.standalone')
if not is_standalone
sources += exe_sources
endif
@@ -2602,7 +2603,7 @@ foreach dict : executables
}
endif
if dict.get('build_by_default', true)
if build_by_default
if dict.get('dbus', false)
dbus_programs += exe
endif

View File

@@ -4,40 +4,6 @@ if conf.get('ENABLE_IMPORTD') != 1
subdir_done()
endif
systemd_importd_sources = files(
'importd.c',
)
systemd_importd_extract_sources = files(
'import-common.c',
'import-compress.c',
'qcow2-util.c',
)
systemd_pull_sources = files(
'pull.c',
'pull-raw.c',
'pull-tar.c',
'pull-job.c',
'pull-common.c',
'curl-util.c',
)
systemd_import_sources = files(
'import.c',
'import-raw.c',
'import-tar.c',
)
systemd_import_fs_sources = files(
'import-fs.c',
)
systemd_export_sources = files(
'export.c',
'export-tar.c',
'export-raw.c',
)
common_deps = [
libbzip2,
libcurl,
@@ -50,14 +16,27 @@ executables += [
libexec_template + {
'name' : 'systemd-importd',
'dbus' : true,
'sources' : systemd_importd_sources,
'extract' : systemd_importd_extract_sources,
'sources' : files(
'importd.c',
),
'extract' : files(
'import-common.c',
'import-compress.c',
'qcow2-util.c',
),
'dependencies' : [common_deps, threads],
},
libexec_template + {
'name' : 'systemd-pull',
'public' : true,
'sources' : systemd_pull_sources,
'sources' : files(
'pull.c',
'pull-raw.c',
'pull-tar.c',
'pull-job.c',
'pull-common.c',
'curl-util.c',
),
'objects' : ['systemd-importd'],
'dependencies' : common_deps + [
libopenssl,
@@ -66,21 +45,31 @@ executables += [
libexec_template + {
'name' : 'systemd-import',
'public' : true,
'sources' : systemd_import_sources,
'sources' : files(
'import.c',
'import-raw.c',
'import-tar.c',
),
'objects' : ['systemd-importd'],
'dependencies' : common_deps,
},
libexec_template + {
'name' : 'systemd-import-fs',
'public' : true,
'sources' : systemd_import_fs_sources,
'sources' : files(
'import-fs.c',
),
'objects' : ['systemd-importd'],
'dependencies' : common_deps,
},
libexec_template + {
'name' : 'systemd-export',
'public' : true,
'sources' : systemd_export_sources,
'sources' : files(
'export.c',
'export-tar.c',
'export-raw.c',
),
'objects' : ['systemd-importd'],
'dependencies' : common_deps,
},

View File

@@ -8,7 +8,7 @@ executables += [
executable_template + {
'name' : 'systemd-repart',
'public' : true,
'sources' : files('repart.c'),
'extract' : files('repart.c'),
'link_with' : [
libshared,
libshared_fdisk,
@@ -24,8 +24,7 @@ executables += [
executable_template + {
'name' : 'systemd-repart.standalone',
'public' : true,
'sources' : files('repart.c'),
'c_args' : '-DSTANDALONE',
'objects' : ['systemd-repart'],
'link_with' : [
libc_wrapper_static,
libbasic_static,

View File

@@ -4,13 +4,7 @@ if conf.get('HAVE_LIBMOUNT') != 1
subdir_done()
endif
systemd_shutdown_sources = files(
'detach-dm.c',
'detach-loopback.c',
'detach-md.c',
'shutdown.c',
)
systemd_shutdown_extract_sources = files(
shutdown_detach_sources = files(
'detach-swap.c',
'umount.c',
)
@@ -18,14 +12,17 @@ systemd_shutdown_extract_sources = files(
executables += [
libexec_template + {
'name' : 'systemd-shutdown',
'sources' : systemd_shutdown_sources,
'extract' : systemd_shutdown_extract_sources,
'extract' : files(
'detach-dm.c',
'detach-loopback.c',
'detach-md.c',
'shutdown.c',
) + shutdown_detach_sources,
'dependencies' : libmount_cflags,
},
libexec_template + {
'name' : 'systemd-shutdown.standalone',
'sources' : systemd_shutdown_sources + systemd_shutdown_extract_sources,
'c_args' : '-DSTANDALONE',
'objects' : ['systemd-shutdown'],
'link_with' : [
libc_wrapper_static,
libbasic_static,
@@ -35,8 +32,8 @@ executables += [
'dependencies' : libmount_cflags,
},
test_template + {
'sources' : files('test-umount.c'),
'objects' : ['systemd-shutdown'],
'sources' : files('test-umount.c') +
shutdown_detach_sources,
'dependencies' : libmount_cflags,
},
]

View File

@@ -8,14 +8,13 @@ executables += [
executable_template + {
'name' : 'systemd-sysusers',
'public' : true,
'sources' : files('sysusers.c'),
'extract' : files('sysusers.c'),
'dependencies' : libaudit_cflags,
},
executable_template + {
'name' : 'systemd-sysusers.standalone',
'public' : true,
'sources' : files('sysusers.c'),
'c_args' : '-DSTANDALONE',
'objects' : ['systemd-sysusers'],
'link_with' : [
libc_wrapper_static,
libbasic_static,

View File

@@ -2151,15 +2151,10 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_IMAGE:
#ifdef STANDALONE
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"This systemd-sysusers version is compiled without support for --image=.");
#else
r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_image);
if (r < 0)
return r;
break;
#endif
case ARG_IMAGE_POLICY:
r = parse_image_policy_argument(optarg, &arg_image_policy);
@@ -2283,10 +2278,8 @@ static int read_credential_lines(Context *c) {
}
static int run(int argc, char *argv[]) {
#ifndef STANDALONE
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
_cleanup_(umount_and_freep) char *mounted_dir = NULL;
#endif
_cleanup_close_ int lock = -EBADF;
_cleanup_(context_done) Context c = {
.audit_fd = -EBADF,
@@ -2314,7 +2307,6 @@ static int run(int argc, char *argv[]) {
if (r < 0)
return r;
#ifndef STANDALONE
if (arg_image) {
assert(!arg_root);
@@ -2338,9 +2330,6 @@ static int run(int argc, char *argv[]) {
if (!arg_root)
return log_oom();
}
#else
assert(!arg_image);
#endif
/* Prepare to emit audit events, but only if we're operating on the host system. */
if (!arg_root)

View File

@@ -4,26 +4,20 @@ if conf.get('ENABLE_TMPFILES') != 1
subdir_done()
endif
systemd_tmpfiles_sources = files(
'tmpfiles.c',
)
systemd_tmpfiles_extract_sources = files(
'offline-passwd.c',
)
offline_passwd_c = files('offline-passwd.c')
executables += [
executable_template + {
'name' : 'systemd-tmpfiles',
'public' : true,
'sources' : systemd_tmpfiles_sources,
'extract' : systemd_tmpfiles_extract_sources,
'extract' : files('tmpfiles.c') +
offline_passwd_c,
'dependencies' : libacl_cflags,
},
executable_template + {
'name' : 'systemd-tmpfiles.standalone',
'public' : true,
'sources' : systemd_tmpfiles_sources + systemd_tmpfiles_extract_sources,
'c_args' : '-DSTANDALONE',
'objects' : ['systemd-tmpfiles'],
'link_with' : [
libc_wrapper_static,
libbasic_static,
@@ -33,7 +27,7 @@ executables += [
'dependencies' : libacl_cflags,
},
test_template + {
'sources' : files('test-offline-passwd.c'),
'objects' : ['systemd-tmpfiles'],
'sources' : files('test-offline-passwd.c') +
offline_passwd_c,
},
]

View File

@@ -4316,14 +4316,10 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_IMAGE:
#ifdef STANDALONE
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"This systemd-tmpfiles version is compiled without support for --image=.");
#else
r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_image);
if (r < 0)
return r;
#endif
/* Imply -E here since it makes little sense to create files persistently in the /run mountpoint of a disk image */
_fallthrough_;
@@ -4560,10 +4556,8 @@ DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(item_array_hash_ops, char, string_
ItemArray, item_array_free);
static int run(int argc, char *argv[]) {
#ifndef STANDALONE
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
_cleanup_(umount_and_freep) char *mounted_dir = NULL;
#endif
_cleanup_strv_free_ char **config_dirs = NULL;
_cleanup_(context_done) Context c = {};
bool invalid_config = false;
@@ -4642,7 +4636,6 @@ static int run(int argc, char *argv[]) {
if (r < 0)
return r;
#ifndef STANDALONE
if (arg_image) {
assert(!arg_root);
@@ -4666,9 +4659,6 @@ static int run(int argc, char *argv[]) {
if (!arg_root)
return log_oom();
}
#else
assert(!arg_image);
#endif
c.items = ordered_hashmap_new(&item_array_hash_ops);
c.globs = ordered_hashmap_new(&item_array_hash_ops);