]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
build: Simplify reading the parser environment
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Dec 2024 15:10:07 +0000 (15:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Dec 2024 15:10:07 +0000 (15:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c
src/libpakfire/include/pakfire/parser.h
src/libpakfire/parser.c

index aec2064de705e39d619e4513ae2bf44777d5df3b..ad49d66c71664af9160eefc161f148232b0a3027 100644 (file)
@@ -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);
index f6b2143eaf71f96941eec14e2c8c5d1ec3462f1d..d8f56f16fe05602da2d502d607a71ccb217a4679 100644 (file)
@@ -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 */
 
index 0bb42efc32d6e08976f8e15cb7481adfd0b291bb..1b101b7fb1d3ba76da703021ead7a7ec4fedceb0 100644 (file)
@@ -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,