Fix POSIX CI failures

This commit is contained in:
signalspike->korze 2026-03-11 12:17:00 -07:00
commit edb771370b
2 changed files with 26 additions and 27 deletions

36
build.h
View file

@ -2,6 +2,10 @@
#ifndef INCLUDEBUILD_H
#define INCLUDEBUILD_H
#if !defined(_WIN32) && !defined(_POSIX_C_SOURCE)
#define _POSIX_C_SOURCE 200809L
#endif
#include <stdbool.h>
#include <stddef.h>
@ -118,6 +122,8 @@ const char* ib_version(void);
#include <dirent.h>
#include <unistd.h>
#include <sys/wait.h>
extern FILE* popen(const char* command, const char* mode);
extern int pclose(FILE* stream);
#define IB_PATH_SEPARATOR '/'
#endif
@ -246,7 +252,7 @@ static char* ib_path_dirname(ib_context* ctx, const char* path);
static const char* ib_basename_ptr(const char* path);
static bool ib_path_exists(const char* path);
static bool ib_is_dir(const char* path);
static time_t ib_file_mtime(const char* path);
static unsigned long long ib_file_mtime(const char* path);
static bool ib_path_is_within(const char* root, const char* path);
static char* ib_path_relative_to_root(ib_context* ctx, const char* root, const char* path);
static char* ib_path_display(ib_context* ctx, const char* root, const char* path);
@ -853,12 +859,22 @@ static bool ib_is_dir(const char* path) {
#endif
}
static time_t ib_file_mtime(const char* path) {
static unsigned long long ib_file_mtime(const char* path) {
struct stat st;
if (!path || stat(path, &st) != 0) {
return (time_t)0;
return 0;
}
return st.st_mtime;
#ifdef _WIN32
return (unsigned long long)st.st_mtime * 1000000000ULL;
#elif defined(__APPLE__)
return ((unsigned long long)st.st_mtimespec.tv_sec * 1000000000ULL) +
(unsigned long long)st.st_mtimespec.tv_nsec;
#elif defined(__linux__)
return ((unsigned long long)st.st_mtim.tv_sec * 1000000000ULL) +
(unsigned long long)st.st_mtim.tv_nsec;
#else
return (unsigned long long)st.st_mtime * 1000000000ULL;
#endif
}
static bool ib_path_component_equal(const char* a, const char* b, size_t len) {
#ifdef _WIN32
@ -2036,7 +2052,7 @@ static bool ib_compile_action_needs_rebuild(ib_project* project, const ib_compil
unsigned long long manifest_hash = 0;
ib_strvec deps;
size_t i;
time_t obj_mtime;
unsigned long long obj_mtime;
if (!ib_path_exists(action->object_path) || !ib_path_exists(action->depfile_path) || !ib_path_exists(action->manifest_path)) {
return true;
}
@ -2044,12 +2060,12 @@ static bool ib_compile_action_needs_rebuild(ib_project* project, const ib_compil
return true;
}
obj_mtime = ib_file_mtime(action->object_path);
if (obj_mtime == (time_t)0 || ib_status_failed(ib_read_depfile(project, action->depfile_path, &deps))) {
if (obj_mtime == 0 || ib_status_failed(ib_read_depfile(project, action->depfile_path, &deps))) {
return true;
}
for (i = 0; i < deps.count; ++i) {
time_t dep_mtime = ib_file_mtime(deps.items[i]);
if (dep_mtime == (time_t)0 || dep_mtime > obj_mtime) {
unsigned long long dep_mtime = ib_file_mtime(deps.items[i]);
if (dep_mtime == 0 || dep_mtime > obj_mtime) {
ib_strvec_free(&deps);
return true;
}
@ -2061,7 +2077,7 @@ static bool ib_compile_action_needs_rebuild(ib_project* project, const ib_compil
static bool ib_link_action_needs_rebuild(ib_project* project, const ib_build_plan* plan, const ib_link_action* action) {
unsigned long long manifest_hash = 0;
size_t i;
time_t out_mtime;
unsigned long long out_mtime;
if (!ib_path_exists(action->output_path) || !ib_path_exists(action->manifest_path)) {
return true;
}
@ -2069,7 +2085,7 @@ static bool ib_link_action_needs_rebuild(ib_project* project, const ib_build_pla
return true;
}
out_mtime = ib_file_mtime(action->output_path);
if (out_mtime == (time_t)0) {
if (out_mtime == 0) {
return true;
}
for (i = 0; i < action->compile_count; ++i) {

View file

@ -123,15 +123,6 @@ compile_driver() {
popd >/dev/null
}
file_mtime() {
local path="$1"
if stat -f %m "${path}" >/dev/null 2>&1; then
stat -f %m "${path}"
else
stat -c %Y "${path}"
fi
}
echo -e "${GREEN}IncludeBuild core fixture runner (Bash)${NC}"
echo -e "${CYAN}Using compiler: ${CC_BIN}${NC}"
@ -198,16 +189,12 @@ clean_fixture "${flag_rebuild}"
compile_driver "${flag_rebuild}"
run_named_executable "${flag_rebuild}" "build" "1"
[ "${RUN_STATUS}" -eq 0 ] || fail "flag_rebuild initial build failed: ${RUN_OUTPUT}"
flag_object="${flag_rebuild}/.ibuild/obj/debug/app/main.o"
flag_time_one="$(file_mtime "${flag_object}")"
run_named_executable "${flag_rebuild}" "app"
[ "${RUN_STATUS}" -eq 0 ] || fail "flag_rebuild first executable failed: ${RUN_OUTPUT}"
assert_contains "${RUN_OUTPUT}" "VALUE=1" "flag_rebuild first executable output incorrect"
sleep 1.2
run_named_executable "${flag_rebuild}" "build" "2"
[ "${RUN_STATUS}" -eq 0 ] || fail "flag_rebuild second build failed: ${RUN_OUTPUT}"
flag_time_two="$(file_mtime "${flag_object}")"
[ "${flag_time_two}" -gt "${flag_time_one}" ] || fail "flag_rebuild object was not rebuilt after flag change"
run_named_executable "${flag_rebuild}" "app"
[ "${RUN_STATUS}" -eq 0 ] || fail "flag_rebuild second executable failed: ${RUN_OUTPUT}"
assert_contains "${RUN_OUTPUT}" "VALUE=2" "flag_rebuild second executable output incorrect"
@ -219,14 +206,10 @@ original_header="$(cat "${nested_header}")"
trap 'printf "%s" "${original_header}" > "${nested_header}"' EXIT
run_named_executable "${nested_headers}" "build"
[ "${RUN_STATUS}" -eq 0 ] || fail "nested_headers initial build failed: ${RUN_OUTPUT}"
nested_object="${nested_headers}/.ibuild/obj/debug/app/main.o"
nested_time_one="$(file_mtime "${nested_object}")"
printf "%s" "${original_header//10/11}" > "${nested_header}"
sleep 1.2
run_named_executable "${nested_headers}" "build"
[ "${RUN_STATUS}" -eq 0 ] || fail "nested_headers rebuild failed: ${RUN_OUTPUT}"
nested_time_two="$(file_mtime "${nested_object}")"
[ "${nested_time_two}" -gt "${nested_time_one}" ] || fail "nested_headers object was not rebuilt after nested include changed"
run_named_executable "${nested_headers}" "app"
[ "${RUN_STATUS}" -eq 0 ] || fail "nested_headers executable failed: ${RUN_OUTPUT}"
assert_contains "${RUN_OUTPUT}" "nested=11" "nested_headers executable output incorrect after header change"