From: Michael Tremer Date: Sun, 29 Dec 2024 15:10:07 +0000 (+0000) Subject: build: Simplify reading the parser environment X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a79b52ebc1275b278ba56d72a309085845c712c5;p=people%2Fric9%2Fpakfire.git build: Simplify reading the parser environment Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index aec2064de..ad49d66c7 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -1038,11 +1038,21 @@ static int pakfire_build_stage(struct pakfire_build* build, // Prepare template for this stage r = pakfire_string_format(template, TEMPLATE, stage); if (r < 0) - return r; + goto ERROR; + + // Create a new environment + r = pakfire_env_create(&env, build->ctx); + if (r < 0) + goto ERROR; + + // Import the build environment + r = pakfire_env_merge(env, build->env); + if (r < 0) + goto ERROR; // Fetch the environment - env = pakfire_parser_make_environ(makefile); - if (!env) + r = pakfire_parser_set_env(makefile, env); + if (r < 0) goto ERROR; // Create the build script @@ -1054,8 +1064,6 @@ static int pakfire_build_stage(struct pakfire_build* build, INFO(build->ctx, "Running build stage '%s'\n", stage); - // XXX merge the basic environment - // Run the script r = pakfire_jail_exec_script(build->jail, script, strlen(script), NULL, env, NULL, NULL, pakfire_build_output_callback, build); diff --git a/src/libpakfire/include/pakfire/parser.h b/src/libpakfire/include/pakfire/parser.h index f6b2143ea..d8f56f16f 100644 --- a/src/libpakfire/include/pakfire/parser.h +++ b/src/libpakfire/include/pakfire/parser.h @@ -114,7 +114,7 @@ int pakfire_parser_apply_declaration( int pakfire_parser_parse_data(struct pakfire_parser* parent, const char* data, size_t len, struct pakfire_parser_error** error); -struct pakfire_env* pakfire_parser_make_environ(struct pakfire_parser* parser); +int pakfire_parser_set_env(struct pakfire_parser* parser, struct pakfire_env* env); #endif /* PAKFIRE_PRIVATE */ diff --git a/src/libpakfire/parser.c b/src/libpakfire/parser.c index 0bb42efc3..1b101b7fb 100644 --- a/src/libpakfire/parser.c +++ b/src/libpakfire/parser.c @@ -955,17 +955,11 @@ int pakfire_parser_set_namespace(struct pakfire_parser* parser, const char* name return 0; } -struct pakfire_env* pakfire_parser_make_environ(struct pakfire_parser* parser) { +int pakfire_parser_set_env(struct pakfire_parser* parser, struct pakfire_env* env) { struct pakfire_parser_declaration* d = NULL; - struct pakfire_env* env = NULL; char* value = NULL; int r; - // Create a new empty environment - r = pakfire_env_create(&env, parser->ctx); - if (r < 0) - goto ERROR; - for (unsigned int i = 0; i < parser->num_declarations; i++) { d = parser->declarations[i]; if (!d) @@ -975,22 +969,17 @@ struct pakfire_env* pakfire_parser_make_environ(struct pakfire_parser* parser) { if (d->flags & PAKFIRE_PARSER_DECLARATION_EXPORT) { value = pakfire_parser_expand(parser, d->namespace, d->value); if (!value) - goto ERROR; + continue; // Store the value r = pakfire_env_set(env, d->name, value); + free(value); if (r < 0) - goto ERROR; + return r; } } - return env; - -ERROR: - if (env) - pakfire_env_unref(env); - - return NULL; + return 0; } int pakfire_parser_create_package(struct pakfire_parser* parser,