// 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
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);
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 */
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)
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,