Skip to content

Commit b7bd7a4

Browse files
committed
native/abnativefunctions.cpp: load configuration file early
1 parent 840016a commit b7bd7a4

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

lib/default-defines.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ GO_LDFLAGS=()
108108
unset -f __GOFLAGS
109109
GO_PACKAGES=('.')
110110

111-
if [ -f /etc/autobuild/ab3cfg.sh ]; then
112-
abwarn "Using configurations from Autobuild3"
113-
. /etc/autobuild/ab3cfg.sh
114-
else
115-
. /etc/autobuild/ab4cfg.sh
116-
fi
117-
118111
if bool "$ABSTAGE2"; then
119112
abwarn "Autobuild4 running in stage2 mode ..."
120113
NOCARGOAUDIT=yes

native/abnativefunctions.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <cassert>
1515
#include <cstdio>
1616
#include <cstdlib>
17+
#include <fcntl.h>
1718
#include <fstream>
1819
#include <iostream>
1920
#include <memory>
@@ -426,7 +427,8 @@ static int set_arch_variables(const char *arch = nullptr) {
426427
this_arch = ab_get_current_architecture();
427428
}
428429
// ARCH=$(abdetectarch)
429-
bind_global_variable("ARCH", const_cast<char *>(this_arch.c_str()), ASS_NOEVAL);
430+
bind_global_variable("ARCH", const_cast<char *>(this_arch.c_str()),
431+
ASS_NOEVAL);
430432
// ABHOST=ARCH
431433
bind_global_variable("ABHOST", const_cast<char *>(this_arch.c_str()),
432434
ASS_NOEVAL);
@@ -795,20 +797,20 @@ static int abelf_copy_dbg(WORD_LIST *list) {
795797
int opt = 0;
796798
while ((opt = internal_getopt(list, const_cast<char *>("exrp"))) != -1) {
797799
switch (opt) {
798-
case 'x':
799-
flags |= AB_ELF_STRIP_ONLY;
800-
break;
801-
case 'r':
802-
flags |= AB_ELF_CHECK_ONLY;
803-
break;
804-
case 'e':
805-
flags |= AB_ELF_USE_EU_STRIP;
806-
break;
807-
case 'p':
808-
flags |= AB_ELF_SAVE_WITH_PATH;
809-
break;
810-
default:
811-
return 1;
800+
case 'x':
801+
flags |= AB_ELF_STRIP_ONLY;
802+
break;
803+
case 'r':
804+
flags |= AB_ELF_CHECK_ONLY;
805+
break;
806+
case 'e':
807+
flags |= AB_ELF_USE_EU_STRIP;
808+
break;
809+
case 'p':
810+
flags |= AB_ELF_SAVE_WITH_PATH;
811+
break;
812+
default:
813+
return 1;
812814
}
813815
}
814816

@@ -822,14 +824,14 @@ static int abelf_copy_dbg(WORD_LIST *list) {
822824
return EX_BADUSAGE;
823825
GuardedSet<std::string> symbols{};
824826
GuardedSet<std::string> sonames;
825-
const int ret =
826-
elf_copy_debug_symbols(src, dst, flags, symbols, sonames);
827+
const int ret = elf_copy_debug_symbols(src, dst, flags, symbols, sonames);
827828
if (ret < 0)
828829
return 10;
829830
return 0;
830831
}
831832

832-
static void ab_set_to_bash_array(const char *varname, const std::unordered_set<std::string> &set) {
833+
static void ab_set_to_bash_array(const char *varname,
834+
const std::unordered_set<std::string> &set) {
833835
auto *var = make_new_array_variable(const_cast<char *>(varname));
834836
var->attributes |= att_readonly;
835837
auto *var_a = array_cell(var);
@@ -881,8 +883,8 @@ static int abelf_copy_dbg_parallel(WORD_LIST *list) {
881883
args.pop_back();
882884
std::unordered_set<std::string> so_deps{};
883885
std::unordered_set<std::string> sonames;
884-
const int ret =
885-
elf_copy_debug_symbols_parallel(args, dst.c_str(), so_deps, sonames, flags);
886+
const int ret = elf_copy_debug_symbols_parallel(args, dst.c_str(), so_deps,
887+
sonames, flags);
886888
if (ret < 0)
887889
return 10;
888890
// copy the data to the bash variable
@@ -1285,7 +1287,8 @@ static int ab_parse_set_modifiers(WORD_LIST *list) {
12851287
return 0;
12861288
}
12871289

1288-
static int ab_dump_variables(const std::vector<std::string> &names, bool write_to_file) {
1290+
static int ab_dump_variables(const std::vector<std::string> &names,
1291+
bool write_to_file) {
12891292
const std::string res = autobuild_serialized_variables(names);
12901293
if (write_to_file) {
12911294
std::ofstream file(".srcinfo.json");
@@ -1429,6 +1432,10 @@ void register_all_native_functions() {
14291432
autobuild_register_builtins(functions);
14301433
}
14311434

1435+
static int load_config_file() {
1436+
return autobuild_load_file("/etc/autobuild/ab4cfg.sh", false) == true;
1437+
}
1438+
14321439
int register_builtin_variables() {
14331440
int ret = 0;
14341441
// Initialize logger
@@ -1439,6 +1446,7 @@ int register_builtin_variables() {
14391446
fmt::format("Failed to setup default env variables: {0}", ret));
14401447
return ret;
14411448
}
1449+
(void)load_config_file();
14421450
if ((ret = set_arch_variables())) {
14431451
get_logger()->error(fmt::format(
14441452
"Failed to setup default architecture variables: {0}", ret));
@@ -1509,7 +1517,7 @@ void autobuild_crash_handler(int sig, siginfo_t *info, void *ucontext) {
15091517
}
15101518

15111519
void setup_crash_handler() {
1512-
struct sigaction action {};
1520+
struct sigaction action{};
15131521
action.sa_sigaction = autobuild_crash_handler;
15141522
action.sa_flags = SA_SIGINFO;
15151523
sigaction(SIGSEGV, &action, nullptr);

0 commit comments

Comments
 (0)