"conf",
"build",
"disable_ccache",
- "disable_snapshot",
"confirm_callback",
NULL,
};
int offline = 0;
int build = 0;
int disable_ccache = 1;
- int disable_snapshot = 1;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOppzpppO", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOppzppO", kwlist,
&path, &arch, &self->callbacks.log, &interactive, &offline, &conf, &build,
- &disable_ccache, &disable_snapshot, &self->callbacks.confirm))
+ &disable_ccache, &self->callbacks.confirm))
return -1;
// Check if log callback is callable
if (disable_ccache)
flags |= PAKFIRE_FLAGS_DISABLE_CCACHE;
-
- if (disable_snapshot)
- flags |= PAKFIRE_FLAGS_DISABLE_SNAPSHOT;
}
// Configure callbacks
char* kwlist[] = {
"path",
"build_id",
+ "disable_snapshot",
NULL,
};
const char* path = NULL;
const char* build_id = NULL;
+ int disable_snapshot = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|z", kwlist, &path, &build_id))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zp", kwlist, &path, &build_id,
+ &disable_snapshot))
return NULL;
+ int flags = 0;
+
+ // Disable snapshot if requested
+ if (disable_snapshot)
+ flags |= PAKFIRE_BUILD_DISABLE_SNAPSHOT;
+
// Run build
- int r = pakfire_build(self->pakfire, path, NULL, build_id, 0);
+ int r = pakfire_build(self->pakfire, path, NULL, build_id, flags);
return execute_return_value(r);
}
#include <pakfire/repo.h>
#include <pakfire/request.h>
#include <pakfire/scriptlet.h>
+#include <pakfire/snapshot.h>
#include <pakfire/util.h>
// We guarantee 2 GiB of memory to every build container
"\n" \
"exit 0\n"
+static int pakfire_build_has_flag(struct pakfire_build* build, int flag) {
+ return build->flags & flag;
+}
+
static int pakfire_build_run_script(struct pakfire_build* build, const char* filename,
const char* args[], char** output) {
char* script = NULL;
return 0;
}
+static int pakfire_build_install_packages(struct pakfire_build* build,
+ int* snapshot_needs_update) {
+ char** packages = NULL;
+ int r = 1;
+
+ // Fetch configuration
+ struct pakfire_config* config = pakfire_get_config(build->pakfire);
+ if (!config) {
+ ERROR(build->pakfire, "Could not fetch configuration: %m\n");
+ r = 1;
+ goto ERROR;
+ }
+
+ // Fetch build environment
+ const char* requires = pakfire_config_get(config, "build", "requires", NULL);
+ if (!requires) {
+ ERROR(build->pakfire, "No build requirements have been defined\n");
+ goto ERROR;
+ }
+
+ // Split requirements into packages
+ packages = pakfire_split_string(requires, ',');
+ if (!packages)
+ goto ERROR;
+
+ int changed = 0;
+
+ // Install everything
+ r = pakfire_install(build->pakfire, 0, 0, (const char**)packages, NULL, 0,
+ &changed, NULL, NULL);
+ if (r) {
+ ERROR(build->pakfire, "Could not install build dependencies: %m\n");
+ goto ERROR;
+ }
+
+ // Mark snapshot as changed if new packages were installed
+ if (changed)
+ *snapshot_needs_update = 1;
+
+ // Update everything
+ r = pakfire_sync(build->pakfire, 0, 0, &changed, NULL, NULL);
+ if (r) {
+ ERROR(build->pakfire, "Could not update packages: %m\n");
+ goto ERROR;
+ }
+
+ // Has anything changed?
+ if (changed)
+ *snapshot_needs_update = 1;
+
+ // Success
+ r = 0;
+
+ERROR:
+ if (config)
+ pakfire_config_unref(config);
+
+ if (packages) {
+ for (char** package = packages; *package; package++)
+ free(*package);
+ free(packages);
+ }
+
+ return r;
+}
+
+static int pakfire_build_extract_snapshot(struct pakfire_build* build) {
+ char path[PATH_MAX];
+ int r;
+
+ // Check if the user wants a snapshot extracted
+ if (!pakfire_build_has_flag(build, PAKFIRE_BUILD_DISABLE_SNAPSHOT)) {
+ DEBUG(build->pakfire, "Snapshot extraction has been disabled for this build\n");
+ return 0;
+ }
+
+ // Extract snapshot
+ r = pakfire_make_cache_path(build->pakfire, path, "%s", "snapshot.tar.zst");
+ if (r < 0) {
+ ERROR(build->pakfire, "Could not compose snapshot path: %m\n");
+ return 1;
+ }
+
+ // Open the snapshot
+ FILE* f = fopen(path, "r");
+
+ // Try restoring the snapshot
+ if (f) {
+ r = pakfire_snapshot_restore(build->pakfire, f);
+ if (r) {
+ fclose(f);
+ return r;
+ }
+ }
+
+ // Tells us whether we need to (re-)create the snapshot
+ int snapshot_needs_update = 0;
+
+ // Install or update any build dependencies
+ r = pakfire_build_install_packages(build, &snapshot_needs_update);
+ if (r)
+ return r;
+
+ if (snapshot_needs_update) {
+ // Open snapshot file for writing
+ f = fopen(path, "w");
+ if (!f) {
+ ERROR(build->pakfire, "Could not open snapshot file for writing: %m\n");
+ return 1;
+ }
+
+ // Create a new snapshot
+ r = pakfire_snapshot_create(build->pakfire, f);
+ fclose(f);
+
+ if (r)
+ return r;
+ }
+
+ return 0;
+}
+
PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* path) {
struct pakfire_archive* archive = NULL;
struct pakfire_package* package = NULL;
INFO(build->pakfire, "Building %s...\n", nevra);
+ // Extract the snapshot
+ r = pakfire_build_extract_snapshot(build);
+ if (r) {
+ ERROR(build->pakfire, "Could not extract snapshot: %m\n");
+ goto ERROR;
+ }
+
// Setup build environment
r = pakfire_build_setup(build->pakfire);
if (r)
struct pakfire_build;
+enum pakfire_build_flags {
+ PAKFIRE_BUILD_DISABLE_SNAPSHOT = (1 << 0),
+};
+
int pakfire_build_create(struct pakfire_build** build,
struct pakfire* pakfire, const char* id, int flags);
PAKFIRE_FLAGS_OFFLINE = (1 << 1),
PAKFIRE_FLAGS_BUILD = (1 << 2),
PAKFIRE_FLAGS_DISABLE_CCACHE = (1 << 3),
- PAKFIRE_FLAGS_DISABLE_SNAPSHOT = (1 << 4),
};
// Callbacks
#include <pakfire/pwd.h>
#include <pakfire/repo.h>
#include <pakfire/request.h>
-#include <pakfire/snapshot.h>
#include <pakfire/transaction.h>
#include <pakfire/ui.h>
#include <pakfire/util.h>
// Build Stuff
-static int pakfire_build_install_packages(struct pakfire* pakfire, int* snapshot_needs_update) {
- char** packages = NULL;
- int r = 1;
-
- // Fetch build environment
- const char* requires = pakfire_config_get(pakfire->config, "build", "requires", NULL);
- if (!requires) {
- ERROR(pakfire, "No build requirements have been defined\n");
- goto ERROR;
- }
-
- // Split requirements into packages
- packages = pakfire_split_string(requires, ',');
- if (!packages)
- goto ERROR;
-
- int changed = 0;
-
- // Install everything
- r = pakfire_install(pakfire, 0, 0, (const char**)packages, NULL, 0, &changed, NULL, NULL);
- if (r) {
- ERROR(pakfire, "Could not install build dependencies: %m\n");
- goto ERROR;
- }
-
- // Mark snapshot as changed if new packages were installed
- if (changed)
- *snapshot_needs_update = 1;
-
- // Update everything
- r = pakfire_sync(pakfire, 0, 0, &changed, NULL, NULL);
- if (r) {
- ERROR(pakfire, "Could not update packages: %m\n");
- goto ERROR;
- }
-
- // Has anything changed?
- if (changed)
- *snapshot_needs_update = 1;
-
- // Success
- r = 0;
-
-ERROR:
- if (packages) {
- for (char** package = packages; *package; package++)
- free(*package);
- free(packages);
- }
-
- return r;
-}
-
int pakfire_build_setup(struct pakfire* pakfire) {
// This function can only be called when in build mode
if (!pakfire_has_flag(pakfire, PAKFIRE_FLAGS_BUILD)) {
}
}
- // Extract snapshot
- if (!pakfire_has_flag(pakfire, PAKFIRE_FLAGS_DISABLE_SNAPSHOT)) {
- r = pakfire_make_cache_path(pakfire, path, "%s", "snapshot.tar.zst");
- if (r < 0)
- return r;
-
- // Open the snapshot
- FILE* f = fopen(path, "r");
-
- // Try restoring the snapshot
- if (f) {
- r = pakfire_snapshot_restore(pakfire, f);
- if (r) {
- fclose(f);
- return r;
- }
- }
-
- // Tells us whether we need to (re-)create the snapshot
- int snapshot_needs_update = 0;
-
- // Install or update any build dependencies
- r = pakfire_build_install_packages(pakfire, &snapshot_needs_update);
- if (r)
- return r;
-
- if (snapshot_needs_update) {
- // Open snapshot file for writing
- f = fopen(path, "w");
- if (!f) {
- ERROR(pakfire, "Could not open snapshot file for writing: %m\n");
- return 1;
- }
-
- // Create a new snapshot
- r = pakfire_snapshot_create(pakfire, f);
- fclose(f);
-
- if (r)
- return r;
- }
- }
-
// Build setup done
pakfire->build_setup = 1;
arch=arch,
logger=logger,
- # Enable build mode and disable snapshots
+ # Enable build mode
build=True,
- disable_snapshot=True,
interactive=False,
)
finally:
os.unlink(self.pakfire_conf)
# Run the build in a new thread
- thread = asyncio.to_thread(p.build, pkg, **kwargs)
+ thread = asyncio.to_thread(p.build, pkg, disable_snapshot=True, **kwargs)
# Return a task
return asyncio.create_task(thread)
# Enable build mode
build=build,
- disable_snapshot=ns.disable_snapshot,
)
def __call__(self):
p.build(
package,
build_id="%s" % ns.build_id if ns.build_id else None,
+ disable_snapshot=ns.disable_snapshot,
)
# Cleanup the temporary directory