static int pakfire_build_find_pkgconfig_provides(
struct pakfire_ctx* ctx, struct pakfire_file* file, struct pakfire_find_deps_ctx* deps) {
- const char* buildroot = NULL;
int r;
// Fetch the absolute path
if (!path)
return -EINVAL;
- // Fetch the path to the buildroot
- buildroot = pakfire_relpath(deps->build->pakfire, deps->build->buildroot);
- if (!buildroot)
- return -EINVAL;
-
const char* argv[] = {
"pkg-config",
"--print-provides",
- pakfire_relpath(deps->build->pakfire, path),
+ path,
NULL,
};
static int pakfire_build_find_pkgconfig_requires(
struct pakfire_ctx* ctx, struct pakfire_file* file, struct pakfire_find_deps_ctx* deps) {
+ const char* buildroot = deps->build->buildroot;
struct pakfire_env* env = NULL;
- const char* buildroot = NULL;
int r;
// Fetch the absolute path
if (!path)
return -EINVAL;
- // Fetch the path to the buildroot
- buildroot = pakfire_relpath(deps->build->pakfire, deps->build->buildroot);
- if (!buildroot)
- return -EINVAL;
-
// This package now requires pkgconfig
r = pakfire_package_add_dep(deps->pkg, PAKFIRE_PKG_REQUIRES, "pkgconfig");
if (r < 0)
"pkg-config",
"--print-requires",
"--print-requires-private",
- pakfire_relpath(deps->build->pakfire, path),
+ path,
NULL,
};
// Pass the buildroot as first argument
const char* args[] = {
- pakfire_relpath(build->pakfire, build->buildroot),
+ build->buildroot,
NULL,
};
INFO(build->ctx, "Creating packages...");
int r = 1;
- const char* buildroot = pakfire_relpath(build->pakfire, build->buildroot);
-
// Fetch a list all all packages
char** packages = pakfire_parser_list_namespaces(makefile, "packages.package:*");
if (!packages) {
// Build packages in reverse order
for (int i = num_packages - 1; i >= 0; i--) {
- r = pakfire_build_package(build, makefile, buildroot, packages[i]);
+ r = pakfire_build_package(build, makefile, build->buildroot, packages[i]);
if (r)
goto ERROR;
}
};
static int pakfire_build_run_post_build_scripts(struct pakfire_build* build) {
- // Fetch buildroot
- const char* buildroot = pakfire_relpath(build->pakfire, build->buildroot);
-
// Set default arguments for build scripts
const char* args[] = {
- buildroot, NULL
+ build->buildroot,
+ NULL,
};
// Run them one by one
pakfire_cgroup_unref(build->cgroup);
}
+ // Remove buildroot
+ if (*build->buildroot)
+ pakfire_rmtree(build->buildroot, 0);
+
if (build->pakfire)
pakfire_unref(build->pakfire);
if (build->ctx)
return 0;
}
+/*
+ This creates a new temporary directory that we will bind-mount into the
+ build environment. That will save us lots of path conversions because the
+ path will always be the same, both inside and outside of the jail.
+*/
+static int pakfire_build_setup_buildroot(struct pakfire_build* build) {
+ char path[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-buildroot.XXXXXX";
+ const char* buildroot = NULL;
+ int r;
+
+ // Create BUILDROOT
+ buildroot = pakfire_mkdtemp(path);
+ if (!buildroot) {
+ ERROR(build->ctx, "Could not create BUILDROOT: %m\n");
+ return -errno;
+ }
+
+ // Store the path
+ r = pakfire_string_set(build->buildroot, buildroot);
+ if (r < 0)
+ return r;
+
+ // Bind-mount into the jail
+ r = pakfire_jail_bind(build->jail, buildroot, buildroot, MS_NOSUID|MS_NOEXEC|MS_NODEV);
+ if (r < 0) {
+ ERROR(build->ctx, "Could not mount %s into the jail: %s\n", buildroot, strerror(-r));
+ return r;
+ }
+
+ return 0;
+}
+
int pakfire_build_create(struct pakfire_build** build, struct pakfire_ctx* ctx,
struct pakfire_config* config, const char* arch, const char* id, int flags) {
int r;
// Copy flags
b->flags = flags;
- // Setup Pakfire
- r = pakfire_build_setup_pakfire(b, config, arch);
- if (r < 0)
- goto ERROR;
-
- // Create an environment
- r = pakfire_env_create(&b->env, b->ctx);
- if (r < 0)
- goto ERROR;
-
// Store start time
r = pakfire_build_set_time_start(b);
if (r)
if (r)
goto ERROR;
+ // Setup Pakfire
+ r = pakfire_build_setup_pakfire(b, config, arch);
+ if (r < 0)
+ goto ERROR;
+
+ // Create an environment
+ r = pakfire_env_create(&b->env, b->ctx);
+ if (r < 0)
+ goto ERROR;
+
// Setup repo
r = pakfire_build_setup_repo(b);
if (r)
if (r)
goto ERROR;
+ // Create the buildroot
+ r = pakfire_build_setup_buildroot(b);
+ if (r < 0)
+ goto ERROR;
+
// Setup ccache
r = pakfire_build_setup_ccache(b);
if (r)
}
// Set BUILDROOT
- const char* buildroot = pakfire_relpath(build->pakfire, build->buildroot);
- if (buildroot)
- pakfire_parser_set(*parser, NULL, "BUILDROOT", buildroot, 0);
+ r = pakfire_parser_set(*parser, NULL, "BUILDROOT", build->buildroot, 0);
+ if (r < 0)
+ goto ERROR;
ERROR:
if (error)
int pakfire_build_exec(struct pakfire_build* build, const char* path) {
struct pakfire_package* package = NULL;
struct pakfire_parser* makefile = NULL;
- char* buildroot = NULL;
char* problems = NULL;
char duration[TIME_STRING_MAX];
int r;
// Fetch architecture
const char* arch = pakfire_get_arch(build->pakfire);
- // Set buildroot
- r = pakfire_path(build->pakfire, build->buildroot, "%s",
- PAKFIRE_TMP_DIR "/pakfire-buildroot.XXXXXX");
- if (r)
- goto ERROR;
-
// Open the source package
r = pakfire_commandline_add(build->pakfire, path, &package);
if (r)
goto ERROR;
}
- // Create BUILDROOT
- buildroot = pakfire_mkdtemp(build->buildroot);
- if (!buildroot) {
- ERROR(build->ctx, "Could not create BUILDROOT: %m\n");
- goto ERROR;
- }
-
// Open the makefile
r = pakfire_build_read_makefile(build, &makefile, package);
if (r)
if (problems)
free(problems);
- // Cleanup buildroot
- if (buildroot)
- pakfire_rmtree(buildroot, 0);
-
return r;
}
return r;
}
-#define pakfire_stripper_build_id_path(stripper, buffer, build_id) \
- __pakfire_stripper_build_id_path(stripper, buffer, sizeof(buffer), build_id)
-
-static int __pakfire_stripper_build_id_path(struct pakfire_stripper* stripper,
- char* buffer, size_t length, const char* build_id) {
- const char* buildroot = pakfire_relpath(stripper->pakfire, stripper->path);
-
- return __pakfire_path(stripper->pakfire, buffer, length,
- "%s/usr/lib/debug/.build-id/%c%c/%s.debug",
- buildroot, build_id[0], build_id[1], build_id + 2);
-}
-
static int pakfire_stripper_strip_debug_sections(struct pakfire_stripper* stripper,
struct pakfire_file* file, struct pakfire_elf* elf) {
const char* build_id = NULL;
}
// Make Build ID path
- r = pakfire_stripper_build_id_path(stripper, build_id_path, build_id);
+ r = pakfire_string_format(build_id_path, "%s/usr/lib/debug/.build-id/%c%c/%s.debug",
+ stripper->path, build_id[0], build_id[1], build_id + 2);
if (r < 0)
goto ERROR;
// (Re-)compress everything using Zstandard
"--compress-debug-sections=zstd",
- pakfire_relpath(stripper->pakfire, path),
- pakfire_relpath(stripper->pakfire, build_id_path),
+ // Source File
+ path,
+
+ // Debug Info File
+ build_id_path,
NULL,
};
// Add the debuglink
"--remove-section=.gnu_debuglink",
- "--add-gnu-debuglink", pakfire_relpath(stripper->pakfire, build_id_path),
+ "--add-gnu-debuglink", build_id_path,
+
+ // The source file
+ path,
- pakfire_relpath(stripper->pakfire, path),
+ // The stripped output
pakfire_relpath(stripper->pakfire, tmppath),
NULL,
};