return r;
}
-static int find_dependency(char** haystack, const char* needle) {
- if (!needle) {
- errno = EINVAL;
- return -1;
- }
-
- if (!haystack)
- return 0;
-
- for (char** element = haystack; *element; element++) {
- if (strcmp(needle, *element) == 0)
- return 1;
- }
-
- return 0;
-}
-
static int pakfire_build_find_dependencies(struct pakfire_build* build,
struct pakfire_package* pkg, struct pakfire_filelist* filelist, const char* buildroot) {
char* provides = NULL;
goto ERROR;
}
-#warning TODO parse dependencies
-#if 0
// Add all provides to the package
if (provides) {
- for (char** element = provides; *element; element++) {
- DEBUG(build->pakfire, "Adding provides: %s\n", *element);
- pakfire_package_add_provides(pkg, *element);
+ r = pakfire_str2deps(build->pakfire, pkg,
+ pakfire_package_add_provides, provides);
+ if (r) {
+ ERROR(build->pakfire, "Could not add provides: %m\n");
+ goto ERROR;
}
}
// Add all requires to the package
if (requires) {
- for (char** element = requires; *element; element++) {
- // Skip adding this requirement if also provided by this package
- if (find_dependency(provides, *element))
- continue;
-
- DEBUG(build->pakfire, "Adding requires: %s\n", *element);
- pakfire_package_add_requires(pkg, *element);
+ r = pakfire_str2deps(build->pakfire, pkg,
+ pakfire_package_add_requires, requires);
+ if (r) {
+ ERROR(build->pakfire, "Could not add provides: %m\n");
+ goto ERROR;
}
}
-#endif
// Success
r = 0;
goto ERROR;
// Add all pre-requires to the package
-#warning TODO parse dependenices
-#if 0
if (prerequires) {
- for (char** element = prerequires; *element; element++) {
- DEBUG(build->pakfire, "Adding pre-requires: %s\n", *element);
- pakfire_package_add_prerequires(pkg, *element);
+ r = pakfire_str2deps(build->pakfire, pkg,
+ pakfire_package_add_prerequires, prerequires);
+ if (r) {
+ ERROR(build->pakfire, "Could not add pre-requires: %m\n");
+ goto ERROR;
}
}
-#endif
ERROR:
if (r && *path)
const char* pakfire_dep2str(struct pakfire* pakfire, Id id);
Id pakfire_str2dep(struct pakfire* pakfire, const char* s);
-void pakfire_str2deps(struct pakfire* pakfire, struct pakfire_package* pkg,
- void (*func)(struct pakfire_package* pkg, const char* dep), const char* deps);
+int pakfire_str2deps(struct pakfire* pakfire, struct pakfire_package* pkg,
+ void (*callback)(struct pakfire_package* pkg, const char* dep), const char* deps);
#define pakfire_string_format(s, fmt, ...) snprintf(s, sizeof(s) - 1, fmt, __VA_ARGS__)
#define pakfire_string_set(s, value) pakfire_string_format(s, "%s", value)
argv[2] = (const char*)command;
// The output of the command
- char** stdout = NULL;
+ char* output = NULL;
// Execute the command inside the Pakfire environment
- r = pakfire_jail_run(parser->pakfire, argv, 0, &stdout);
+ r = pakfire_jail_run(parser->pakfire, argv, 0, &output);
if (r) {
// Just log this and continue
DEBUG(parser->pakfire, "Command '%s' failed with return code %d\n", command, r);
}
- // Join all output together
- char* output = pakfire_string_join(stdout, "");
-
// Strip newline from output
if (output)
pakfire_remove_trailing_newline(output);
pcre2_substring_free(pattern);
pattern = NULL;
- if (stdout) {
- for (char** line = stdout; *line; line++)
- free(*line);
- free(stdout);
- }
-
if (output)
free(output);
}
return id;
}
-void pakfire_str2deps(struct pakfire* pakfire, struct pakfire_package* pkg,
- void (*func)(struct pakfire_package* pkg, const char* dep), const char* deps) {
- char* p = strdupa(deps);
+int pakfire_str2deps(struct pakfire* pakfire, struct pakfire_package* pkg,
+ void (callback)(struct pakfire_package* pkg, const char* dep), const char* deps) {
+ char* p = NULL;
- while (*p) {
- char* e = strchr(p, '\n');
+ // Check for valid inputs
+ if (!callback || !deps) {
+ errno = EINVAL;
+ return 1;
+ }
- // Terminate the string
- if (e)
- *e = '\0';
+ // Copy deps into a working buffer
+ char* buffer = strdup(deps);
+ if (!buffer)
+ return 1;
- // Add the dependency
- func(pkg, p);
+ char* dep = strtok_r(buffer, "\n", &p);
- // End loop when we reached the end
- if (!e)
- break;
+ // Walk through the buffer line by line
+ while (dep) {
+ DEBUG(pakfire, "Found dep '%s'\n", dep);
- // Or continue at the next line
- p = e + 1;
+ // Add the dependency
+ callback(pkg, dep);
+
+ // Move on to next token
+ dep = strtok_r(NULL, "\n", &p);
}
+
+ free(buffer);
+ return 0;
}
int pakfire_string_startswith(const char* s, const char* prefix) {