From 5b1799ffbf0e74634783a480dadfce26a17d0863 Mon Sep 17 00:00:00 2001 From: Philip Meulengracht Date: Thu, 29 Aug 2024 10:57:11 +0200 Subject: [PATCH] many: logging fixes, fix snapcraft build, fix execution of gcc shell script, add missing deps --- examples/gcc-toolchain.yaml | 8 +++++++- libs/oven/backends/autotools.c | 2 +- libs/vlog/include/vlog.h | 1 + libs/vlog/logf.c | 19 ++++++++++++++++--- snap/snapcraft.yaml | 2 +- tools/bake/commands/run.c | 9 +++++++-- tools/bakectl/commands/source.c | 30 +++++++++++------------------- 7 files changed, 44 insertions(+), 27 deletions(-) diff --git a/examples/gcc-toolchain.yaml b/examples/gcc-toolchain.yaml index 08171aa0..4ec4f0b0 100644 --- a/examples/gcc-toolchain.yaml +++ b/examples/gcc-toolchain.yaml @@ -11,6 +11,12 @@ project: version: 13.0.0 license: MIT +environment: + host: + packages: + - ca-certificates + - wget + recipes: - name: gcc source: @@ -19,7 +25,7 @@ recipes: git-branch: releases/gcc-13 script: | if build.subsystem.platform_host() == "linux" then - build.shell("contrib/download_prerequisites") + build.shell("contrib/download_prerequisites", "") end steps: - name: config diff --git a/libs/oven/backends/autotools.c b/libs/oven/backends/autotools.c index 3d41b13b..22598748 100644 --- a/libs/oven/backends/autotools.c +++ b/libs/oven/backends/autotools.c @@ -203,7 +203,7 @@ int configure_main(struct oven_backend_data* data, union chef_backend_options* o int written; - configurePath = strpathcombine(data->paths.project, "autotools"); + configurePath = strpathcombine(data->paths.project, "configure"); if (configurePath == NULL) { return -1; } diff --git a/libs/vlog/include/vlog.h b/libs/vlog/include/vlog.h index 817bd1ba..a9c0d9d7 100644 --- a/libs/vlog/include/vlog.h +++ b/libs/vlog/include/vlog.h @@ -121,6 +121,7 @@ enum vlog_content_status_type { }; extern void vlog_start(FILE* handle, const char* header, const char* footer, int contentLineCount); +extern void vlog_end(void); extern void vlog_content_set_index(int index); extern void vlog_content_set_prefix(const char* header); extern void vlog_content_set_status(enum vlog_content_status_type status); diff --git a/libs/vlog/logf.c b/libs/vlog/logf.c index e7b19bff..2146660e 100644 --- a/libs/vlog/logf.c +++ b/libs/vlog/logf.c @@ -64,6 +64,7 @@ struct vlog_context { mtx_t lock; const char* title; const char* footer; + int view_enabled; int content_line_count; int content_line_index; struct vlog_content_line* lines; @@ -104,6 +105,7 @@ static const char* g_animatorCharacter[] = { "/", "-", "\\", + "/", "-" }; @@ -325,7 +327,7 @@ static void __fmt_indicator(char* buffer, enum vlog_content_status_type status) if (status == VLOG_CONTENT_STATUS_WORKING) { long long seconds = g_vlog.animator_time / 1000; long long ms = (g_vlog.animator_time % 1000) / 100; - int index = g_vlog.animator_index % 5; + int index = g_vlog.animator_index % 6; sprintf(buffer, "%s %lli.%llis", g_animatorCharacter[index], seconds, ms); } else { strcpy(buffer, g_statusNames[status]); @@ -336,6 +338,10 @@ static void __refresh_view(struct vlog_output* output, int clear) { char indicator[20] = { 0 }; + if (!g_vlog.view_enabled) { + return; + } + if (mtx_trylock(&g_vlog.lock) != thrd_success) { return; } @@ -385,10 +391,17 @@ void vlog_start(FILE* handle, const char* header, const char* footer, int conten g_vlog.content_line_count = contentLineCount; g_vlog.content_line_index = 0; g_vlog.lines = calloc(contentLineCount, sizeof(struct vlog_content_line)); - + g_vlog.view_enabled = 1; + __refresh_view(output, 0); } +void vlog_end(void) +{ + // disable + g_vlog.view_enabled = 0; +} + void vlog_content_set_index(int index) { if (index < 0 || index >= g_vlog.content_line_count) { @@ -448,7 +461,7 @@ void vlog_output(enum vlog_level level, const char* tag, const char* format, ... // if the output is a tty we handle it differently, unless vlog_start // was not configured - if (g_vlog.content_line_count > 0 && isatty(fileno(output->handle))) { + if (g_vlog.view_enabled && isatty(fileno(output->handle))) { char* nl; #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 03305550..62bd6cd7 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -6,7 +6,7 @@ description: | built as a lightweight alternative to current package managers. Its not only for package management, but also as an application format. -base: core24 +base: core22 grade: stable confinement: strict diff --git a/tools/bake/commands/run.c b/tools/bake/commands/run.c index 41954433..f7fe88ea 100644 --- a/tools/bake/commands/run.c +++ b/tools/bake/commands/run.c @@ -211,12 +211,16 @@ static void __cleanup_systems(int sig) { // printing as a part of a signal handler is not safe // but we live dangerously - printf("termination requested, cleaning up\n"); + vlog_content_set_status(VLOG_CONTENT_STATUS_FAILED); + vlog_end(); // cleanup the kitchen, this will take out most of the systems // setup as a part of all this. kitchen_destroy(&g_kitchen); + // cleanup logging + vlog_cleanup(); + // Do a quick exit, which is recommended to do in signal handlers // and use the signal as the exit code _Exit(-sig); @@ -427,9 +431,10 @@ int run_main(int argc, char** argv, char** envp, struct bake_command_options* op // update status of logging vlog_content_set_status(VLOG_CONTENT_STATUS_DONE); - vlog_refresh(stdout); cleanup: + vlog_refresh(stdout); + vlog_end(); kitchen_destroy(&g_kitchen); return status; } diff --git a/tools/bakectl/commands/source.c b/tools/bakectl/commands/source.c index 3b4712f7..d79599ad 100644 --- a/tools/bakectl/commands/source.c +++ b/tools/bakectl/commands/source.c @@ -47,15 +47,6 @@ static void __cleanup_systems(int sig) _Exit(0); } -static void __output_handler(const char* line, enum platform_spawn_output_type type) -{ - if (type == PLATFORM_SPAWN_OUTPUT_TYPE_STDOUT) { - VLOG_TRACE("bakectl", line); - } else { - VLOG_ERROR("bakectl", line); - } -} - struct __source_options { const char* source_root; const char* project_root; @@ -106,17 +97,17 @@ static int __prepare_git(const char* root, struct recipe_part_source_git* git, s } snprintf(&buffer[0], sizeof(buffer), - "clone %s .", + "clone -q %s .", git->url ); // start out by checking out main repo + VLOG_TRACE("bakectl", "Cloning repository for %s\n", options->part); status = platform_spawn( "git", &buffer[0], (const char* const*)options->envp, &(struct platform_spawn_options) { - .cwd = root, - .output_handler = __output_handler + .cwd = root } ); if (status) { @@ -142,8 +133,7 @@ static int __prepare_git(const char* root, struct recipe_part_source_git* git, s "git", &buffer[0], (const char* const*)options->envp, &(struct platform_spawn_options) { - .cwd = root, - .output_handler = __output_handler + .cwd = root } ); if (status) { @@ -153,12 +143,12 @@ static int __prepare_git(const char* root, struct recipe_part_source_git* git, s } // checkout submodules if any + VLOG_TRACE("bakectl", "Cloning submodules for %s\n", options->part); status = platform_spawn( - "git", "submodule update --init --recursive", + "git", "submodule update -q --init --recursive", (const char* const*)options->envp, &(struct platform_spawn_options) { - .cwd = root, - .output_handler = __output_handler + .cwd = root } ); if (status) { @@ -190,7 +180,7 @@ static int __cleanup_existing(const char* path) return 0; } -static int __execute_source_script(const char* root, struct recipe_part_source* source) +static int __execute_source_script(const char* root, const char* part, struct recipe_part_source* source) { VLOG_DEBUG("bakectl", "__execute_source_script()\n"); @@ -198,6 +188,8 @@ static int __execute_source_script(const char* root, struct recipe_part_source* if (source->script == NULL) { return 0; } + + VLOG_TRACE("bakectl", "Executing source script for %s\n", part); return oven_script( source->script, &(struct oven_script_options) { @@ -251,7 +243,7 @@ static int __prepare_source(const char* part, struct recipe_part_source* source, } if (status == 0) { - status = __execute_source_script(sourceRoot, source); + status = __execute_source_script(sourceRoot, options->part, source); if (status) { VLOG_ERROR("bakectl", "__prepare_source: failed to execute source script\n"); }