diff --git a/builder/builder-manifest.c b/builder/builder-manifest.c index 3d9a3211..f2521db1 100644 --- a/builder/builder-manifest.c +++ b/builder/builder-manifest.c @@ -1815,6 +1815,30 @@ appstream_compose (GFile *app_dir, return TRUE; } +static char ** +strcatv (char **strv1, + char **strv2) +{ + if (strv1 == NULL && strv2 == NULL) + return NULL; + if (strv1 == NULL) + return g_strdupv (strv2); + if (strv2 == NULL) + return g_strdupv (strv1); + + unsigned len1 = g_strv_length (strv1); + unsigned len2 = g_strv_length (strv2); + char **retval = g_new (char *, len1 + len2 + 1); + unsigned ix; + + for (ix = 0; ix < len1; ix++) + retval[ix] = g_strdup (strv1[ix]); + for (ix = 0; ix < len2; ix++) + retval[len1 + ix] = g_strdup (strv2[ix]); + retval[len1 + len2] = NULL; + + return retval; +} gboolean builder_manifest_cleanup (BuilderManifest *self, @@ -1849,10 +1873,13 @@ builder_manifest_cleanup (BuilderManifest *self, if (self->cleanup_commands) { + g_auto(GStrv) build_args = builder_options_get_build_args (self->build_options, context, error); + if (!build_args) + return FALSE; env = builder_options_get_env (self->build_options, context); for (i = 0; self->cleanup_commands[i] != NULL; i++) { - if (!command (app_dir, env, NULL, self->cleanup_commands[i], error)) + if (!command (app_dir, env, build_args, self->cleanup_commands[i], error)) return FALSE; } } @@ -2662,7 +2689,11 @@ builder_manifest_create_platform (BuilderManifest *self, if (self->cleanup_platform_commands) { g_auto(GStrv) env = builder_options_get_env (self->build_options, context); - char *extra_args[] = { "--sdk-dir=platform", "--metadata=metadata.platform", NULL}; + g_auto(GStrv) build_args = builder_options_get_build_args (self->build_options, context, error); + if (!build_args) + return FALSE; + char *platform_args[] = { "--sdk-dir=platform", "--metadata=metadata.platform", NULL }; + g_auto(GStrv) extra_args = strcatv (build_args, platform_args); for (i = 0; self->cleanup_platform_commands[i] != NULL; i++) { diff --git a/tests/Makefile.am.inc b/tests/Makefile.am.inc index d0ea77f8..284eb07f 100644 --- a/tests/Makefile.am.inc +++ b/tests/Makefile.am.inc @@ -89,6 +89,7 @@ dist_installed_test_data = \ tests/org.test.Hello.png \ tests/package_version.txt \ tests/test.json \ + tests/test-runtime.json \ tests/module1.json \ tests/data1 \ tests/data1.patch \ diff --git a/tests/test-builder.sh b/tests/test-builder.sh index f7cd9116..61f22e75 100755 --- a/tests/test-builder.sh +++ b/tests/test-builder.sh @@ -24,7 +24,7 @@ set -euo pipefail skip_without_bwrap skip_without_user_xattrs -echo "1..3" +echo "1..4" setup_repo install_repo @@ -38,6 +38,7 @@ cd $TEST_DATA_DIR/ cp -a $(dirname $0)/test-configure . echo "version1" > app-data cp $(dirname $0)/test.json . +cp $(dirname $0)/test-runtime.json . cp $(dirname $0)/0001-Add-test-logo.patch . mkdir include1 cp $(dirname $0)/module1.json include1/ @@ -88,3 +89,10 @@ run --command=cat org.test.Hello2 /app/share/app-data > app_data_2 assert_file_has_content app_data_2 version2 echo "ok update" + +# The build-args of --help should prevent the faulty cleanup and +# platform-cleanup commands from executing +${FLATPAK_BUILDER} $FL_GPGARGS --repo=$REPO --force-clean runtimedir \ + test-runtime.json + +echo "ok runtime build cleanup with build-args" diff --git a/tests/test-runtime.json b/tests/test-runtime.json new file mode 100644 index 00000000..31f4a98a --- /dev/null +++ b/tests/test-runtime.json @@ -0,0 +1,19 @@ +{ + "build-runtime": true, + "id": "org.test.Hello.Sdk", + "id-platform": "org.test.Hello.Platform", + "runtime": "org.test.Platform", + "sdk": "org.test.Sdk", + "tags": ["test"], + "cleanup-commands": [ "fdghksdfjhsdfkg" ], + "cleanup-platform-commands": [ "sdjfgkafyewgdbvhsail" ], + "build-options": { + "build-args": ["--help"] + }, + + "modules": [ + { + "name": "empty" + } + ] +}