diff options
| author | Jack Jamison <jackqjamison@gmail.com> | 2026-07-25 10:59:24 -0400 |
|---|---|---|
| committer | Jack Jamison <jackqjamison@gmail.com> | 2026-07-25 10:59:24 -0400 |
| commit | 507d1d7d7a9487f76c72217832d115f3c429c7be (patch) | |
| tree | 85a75632807e1ddf037510da133cf3e792210406 /snag | |
| parent | 17d0447a55b971f66e383e5f3b0c12213949dbc9 (diff) | |
create build directory
Diffstat (limited to 'snag')
| -rw-r--r-- | snag/src/build_db.c | 49 | ||||
| -rw-r--r-- | snag/src/build_db.h | 9 | ||||
| -rw-r--r-- | snag/src/main.c | 4 | ||||
| -rw-r--r-- | snag/src/source_db.c | 4 | ||||
| -rw-r--r-- | snag/src/source_db.h | 2 |
5 files changed, 61 insertions, 7 deletions
diff --git a/snag/src/build_db.c b/snag/src/build_db.c index 01ff6bc..778ebd5 100644 --- a/snag/src/build_db.c +++ b/snag/src/build_db.c @@ -1,21 +1,65 @@ #include "build_db.h" + +#include "source_db.h" #include "util.h" #include <poll.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> #include <sys/wait.h> +#include <sys/stat.h> #include <errno.h> +const char build_db_path[] = "./var/snag/builds"; +const size_t build_db_path_len = strlen(build_db_path); + #define PKG_BUILD_CMD "./scripts/run_pkg_build.sh" #define API_MESSAGE_NONE 0 #define API_MESSAGE_FINISHED 1 #define API_MESSAGE_TEST 2 -void package_run_build(const package_info_t* info) { +bool package_setup_build(const package_info_t* info, package_build_t* build) { + + // get timestamp string + char timestamp_str[32]; + { + // get time in ms + struct timespec ts; + if (clock_gettime(CLOCK_REALTIME, &ts) != 0) die("failed to get time: %s", strerror(errno)); + unsigned long long total_ms = ((unsigned long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000); + snprintf(timestamp_str, sizeof(timestamp_str), "%llu", total_ms); + } + + // create build info + memset(build, 0, sizeof(*build)); + build->package = info; + build->directory = vastrcat(build_db_path, "/", info->attrs.id, "-", timestamp_str); + + // create build directory + if (mkdir(build->directory, 0777) == -1) die("failed to create build directory: %s", strerror(errno)); + + // (re)create symlink to build directory + char* symlink_name = vastrcat(build_db_path, "/", info->attrs.id); + if (unlink(symlink_name) == -1 && errno != ENOENT) die("failed to remove build symlink '%s': %s", symlink_name, strerror(errno)); + if (symlink(build->directory + build_db_path_len + 1, symlink_name) == -1) die("failed to create build symlink '%s': %s", symlink_name, strerror(errno)); + free(symlink_name); + + // unpack package source (eventually this will be done by swenu api) + build->source_directory = join_path(build->directory, "source"); + unpack_source(&info->attrs.source, build->source_directory); + + // todo - create paths for log files + // todo - create rebuild script + + return true; +} + +void build_run(const package_build_t* build) { int api_from_sh[2] = {0}; if (pipe(api_from_sh) < 0) die("failed to open api endpoint pipe: %s", strerror(errno)); @@ -43,7 +87,7 @@ void package_run_build(const package_info_t* info) { char buf2[1024]; snprintf(buf2, sizeof(buf2), "%d", api_to_sh[0]); // exec into install script - char* argv[] = { PKG_BUILD_CMD, buf1, buf2, info->script_path, NULL }; + char* argv[] = { PKG_BUILD_CMD, buf1, buf2, build->package->script_path, NULL }; char* envp[] = { NULL }; execve(PKG_BUILD_CMD, argv, envp); // what are you still doing here? @@ -89,6 +133,7 @@ void package_run_build(const package_info_t* info) { write(api_to_sh[1], "api test\n", strlen("api test\n")); break; case API_MESSAGE_NONE: + break; } } } diff --git a/snag/src/build_db.h b/snag/src/build_db.h index 007f794..dda9cfd 100644 --- a/snag/src/build_db.h +++ b/snag/src/build_db.h @@ -3,6 +3,13 @@ #include "package.h" -void package_run_build(const package_info_t* info); +typedef struct { + const package_info_t* package; + char* directory; + char* source_directory; +} package_build_t; + +bool package_setup_build(const package_info_t* info, package_build_t* build); +void build_run(const package_build_t* info); #endif diff --git a/snag/src/main.c b/snag/src/main.c index 5835859..fb32298 100644 --- a/snag/src/main.c +++ b/snag/src/main.c @@ -52,7 +52,9 @@ int cmd_install(char* cmd_name, ArgParser* parser) { } // run the package install - package_run_build(&info); + package_build_t build; + package_setup_build(&info, &build); + build_run(&build); } } diff --git a/snag/src/source_db.c b/snag/src/source_db.c index 86bab8b..d49e0c4 100644 --- a/snag/src/source_db.c +++ b/snag/src/source_db.c @@ -22,7 +22,7 @@ void ensure_libcurl(); // note: fixed location of source database for now const char source_db_path[] = "./var/snag/sources"; -char* get_source_path(source_info_t* source) { return join_path(source_db_path, source->name); } +char* get_source_path(const source_info_t* source) { return join_path(source_db_path, source->name); } bool verify_source(source_info_t* source) { // verify source exists @@ -103,7 +103,7 @@ static size_t download_write_callback(char* ptr, size_t size, size_t nmemb, void return written; } -bool unpack_source(source_info_t* source, char* dest_path) { +bool unpack_source(const source_info_t* source, char* dest_path) { char* source_path = get_source_path(source); char* command = vastrcat(EXTRACT_TAR_SCRIPT, " ", source_path, " ", dest_path); diff --git a/snag/src/source_db.h b/snag/src/source_db.h index e22f221..9eb4527 100644 --- a/snag/src/source_db.h +++ b/snag/src/source_db.h @@ -5,6 +5,6 @@ bool verify_source(source_info_t* source); bool download_source(source_info_t* source); -bool unpack_source(source_info_t* source, char* dest_path); +bool unpack_source(const source_info_t* source, char* dest_path); #endif |
