Skip to content

Commit

Permalink
many: logging fixes, fix snapcraft build, fix execution of gcc shell …
Browse files Browse the repository at this point in the history
…script, add missing deps
  • Loading branch information
Meulengracht committed Aug 29, 2024
1 parent 5da9014 commit 5b1799f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 27 deletions.
8 changes: 7 additions & 1 deletion examples/gcc-toolchain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ project:
version: 13.0.0
license: MIT

environment:
host:
packages:
- ca-certificates
- wget

recipes:
- name: gcc
source:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libs/oven/backends/autotools.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions libs/vlog/include/vlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 16 additions & 3 deletions libs/vlog/logf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,6 +105,7 @@ static const char* g_animatorCharacter[] = {
"/",
"-",
"\\",
"/",
"-"
};

Expand Down Expand Up @@ -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]);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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__)
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions tools/bake/commands/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
30 changes: 11 additions & 19 deletions tools/bakectl/commands/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -190,14 +180,16 @@ 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");

// no script no problem
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) {
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 5b1799f

Please sign in to comment.