build: add support for disabling native command support

This commit is contained in:
2026-07-19 13:34:09 +01:00
parent 422416e99b
commit f189643cf4
7 changed files with 52 additions and 8 deletions
+9 -1
View File
@@ -7,6 +7,10 @@ if (NOT DEFINED bshell_interactive)
set(bshell_interactive 1) set(bshell_interactive 1)
endif () endif ()
if (NOT DEFINED bshell_enable_native_commands)
set(bshell_enable_native_commands 1)
endif ()
if (NOT DEFINED bshell_verbose) if (NOT DEFINED bshell_verbose)
set(bshell_verbose 0) set(bshell_verbose 0)
endif () endif ()
@@ -15,12 +19,16 @@ if (NOT DEFINED bshell_enable_floating_point)
set(bshell_enable_floating_point 1) set(bshell_enable_floating_point 1)
endif () endif ()
set(required_fx_assemblies fx.runtime fx.collections fx.io fx.diagnostics fx.cmdline) set(required_fx_assemblies fx.runtime fx.collections fx.cmdline fx.io)
if (bshell_interactive) if (bshell_interactive)
set(required_fx_assemblies ${required_fx_assemblies} fx.term) set(required_fx_assemblies ${required_fx_assemblies} fx.term)
endif () endif ()
if (bshell_enable_native_commands)
set(required_fx_assemblies ${required_fx_assemblies} fx.diagnostics)
endif ()
find_package(Python COMPONENTS Interpreter REQUIRED) find_package(Python COMPONENTS Interpreter REQUIRED)
find_package(FX REQUIRED COMPONENTS ${required_fx_assemblies}) find_package(FX REQUIRED COMPONENTS ${required_fx_assemblies})
+2
View File
@@ -18,3 +18,5 @@ target_include_directories(bshell.core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/includ
target_compile_definitions(bshell.core PUBLIC target_compile_definitions(bshell.core PUBLIC
BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point} BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point}
BSHELL_VERSION="${bshell_version}") BSHELL_VERSION="${bshell_version}")
install(TARGETS bshell.core)
+13 -2
View File
@@ -1,6 +1,10 @@
set(source_dirs set(source_dirs
ast compile parse parse/lex parse/syntax ast compile parse parse/lex parse/syntax
format runtime command line-editor) format runtime command)
if (bshell_interactive)
set(source_dirs ${source_dirs} line-editor)
endif ()
file(GLOB sources file(GLOB sources
*.c *.c
@@ -15,15 +19,22 @@ endforeach (d)
add_library(bshell.runtime SHARED ${sources}) add_library(bshell.runtime SHARED ${sources})
target_link_libraries(bshell.runtime FX::Runtime FX::Collections FX::Io FX::Diagnostics) target_link_libraries(bshell.runtime FX::Runtime FX::Collections FX::Io)
if (bshell_interactive) if (bshell_interactive)
target_link_libraries(bshell.runtime FX::Term) target_link_libraries(bshell.runtime FX::Term)
endif () endif ()
if (bshell_enable_native_commands)
target_link_libraries(bshell.runtime FX::Diagnostics)
endif ()
target_include_directories(bshell.runtime PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(bshell.runtime PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_definitions(bshell.runtime PUBLIC target_compile_definitions(bshell.runtime PUBLIC
BSHELL_VERSION="${bshell_version}" BSHELL_VERSION="${bshell_version}"
BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point} BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point}
BSHELL_ENABLE_NATIVE_COMMANDS=${bshell_enable_native_commands}
BSHELL_INTERACTIVE=${bshell_interactive} BSHELL_INTERACTIVE=${bshell_interactive}
BSHELL_VERBOSE=${bshell_verbose}) BSHELL_VERBOSE=${bshell_verbose})
install(TARGETS bshell.runtime)
+2
View File
@@ -1,3 +1,4 @@
#if BSHELL_ENABLE_NATIVE_COMMANDS == 1
#include <bshell/command/command.h> #include <bshell/command/command.h>
#include <bshell/command/native-command.h> #include <bshell/command/native-command.h>
#include <bshell/format.h> #include <bshell/format.h>
@@ -231,3 +232,4 @@ FX_TYPE_DEFINITION_BEGIN(bshell_native_command)
FX_TYPE_INSTANCE_FINI(fini); FX_TYPE_INSTANCE_FINI(fini);
FX_TYPE_INSTANCE_PRIVATE(struct bshell_native_command_p); FX_TYPE_INSTANCE_PRIVATE(struct bshell_native_command_p);
FX_TYPE_DEFINITION_END(bshell_native_command) FX_TYPE_DEFINITION_END(bshell_native_command)
#endif
+12 -1
View File
@@ -7,7 +7,6 @@
#include <bshell/status.h> #include <bshell/status.h>
#include <fx/collections/array.h> #include <fx/collections/array.h>
#include <fx/collections/hashtable.h> #include <fx/collections/hashtable.h>
#include <fx/diagnostics/process.h>
#include <fx/io/path.h> #include <fx/io/path.h>
#include <fx/reflection/assembly.h> #include <fx/reflection/assembly.h>
#include <fx/reflection/function.h> #include <fx/reflection/function.h>
@@ -15,6 +14,10 @@
#include <fx/string.h> #include <fx/string.h>
#include <fx/vector.h> #include <fx/vector.h>
#if BSHELL_ENABLE_NATIVE_COMMANDS == 1
#include <fx/diagnostics/process.h>
#endif
#if BSHELL_INTERACTIVE == 1 #if BSHELL_INTERACTIVE == 1
#include <fx/term/print.h> #include <fx/term/print.h>
#endif #endif
@@ -107,6 +110,7 @@ static bshell_command *resolve_cmdlet(
static const fx_string *get_path(void) static const fx_string *get_path(void)
{ {
#if BSHELL_ENABLE_NATIVE_COMMANDS == 1
fx_process *self = fx_process_get_self(); fx_process *self = fx_process_get_self();
if (!self) { if (!self) {
return NULL; return NULL;
@@ -125,8 +129,12 @@ static const fx_string *get_path(void)
const fx_string *path = NULL; const fx_string *path = NULL;
fx_value_get_object(path_v, (fx_object **)&path); fx_value_get_object(path_v, (fx_object **)&path);
return path; return path;
#else
return NULL;
#endif
} }
#if BSHELL_ENABLE_NATIVE_COMMANDS == 1
static bshell_command *resolve_native_command_local( static bshell_command *resolve_native_command_local(
struct bshell_cmdcall_p *cmdcall, struct bshell_cmdcall_p *cmdcall,
struct bshell_runtime *rt, struct bshell_runtime *rt,
@@ -188,6 +196,7 @@ static bshell_command *resolve_native_command(
fx_iterator_unref(it); fx_iterator_unref(it);
return result; return result;
} }
#endif
static enum bshell_status resolve_call_target( static enum bshell_status resolve_call_target(
struct bshell_cmdcall_p *cmdcall, struct bshell_cmdcall_p *cmdcall,
@@ -206,11 +215,13 @@ static enum bshell_status resolve_call_target(
return BSHELL_SUCCESS; return BSHELL_SUCCESS;
} }
#if BSHELL_ENABLE_NATIVE_COMMANDS == 1
if ((cmdcall->cmd_target if ((cmdcall->cmd_target
= resolve_native_command(cmdcall, rt, cmd_name_s))) { = resolve_native_command(cmdcall, rt, cmd_name_s))) {
cmdcall->cmd_type = CMDCALL_NATIVE; cmdcall->cmd_type = CMDCALL_NATIVE;
return BSHELL_SUCCESS; return BSHELL_SUCCESS;
} }
#endif
const char *cmd_name_cstr = fx_string_get_cstr(cmd_name_s); const char *cmd_name_cstr = fx_string_get_cstr(cmd_name_s);
#if BSHELL_INTERACTIVE == 1 #if BSHELL_INTERACTIVE == 1
+2
View File
@@ -33,3 +33,5 @@ target_compile_definitions(bshell PUBLIC
BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point} BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point}
BSHELL_INTERACTIVE=${bshell_interactive} BSHELL_INTERACTIVE=${bshell_interactive}
BSHELL_VERBOSE=${bshell_verbose}) BSHELL_VERBOSE=${bshell_verbose})
install(TARGETS bshell)
+12 -4
View File
@@ -4,10 +4,6 @@
#include <bshell/compile.h> #include <bshell/compile.h>
#include <bshell/file.h> #include <bshell/file.h>
#include <bshell/format.h> #include <bshell/format.h>
#include <bshell/line-editor/core.h>
#include <bshell/line-editor/highlight.h>
#include <bshell/line-editor/line-editor.h>
#include <bshell/line-editor/syntax.h>
#include <bshell/parse/lex.h> #include <bshell/parse/lex.h>
#include <bshell/parse/parse.h> #include <bshell/parse/parse.h>
#include <bshell/parse/token.h> #include <bshell/parse/token.h>
@@ -16,6 +12,13 @@
#include <fx/io/path.h> #include <fx/io/path.h>
#include <stdio.h> #include <stdio.h>
#if BSHELL_INTERACTIVE == 1
#include <bshell/line-editor/core.h>
#include <bshell/line-editor/highlight.h>
#include <bshell/line-editor/line-editor.h>
#include <bshell/line-editor/syntax.h>
#endif
enum { enum {
CMD_ROOT, CMD_ROOT,
OPT_LEX, OPT_LEX,
@@ -75,6 +78,7 @@ static enum frontend_flags collect_frontend_flags(const fx_arglist *opt)
return result; return result;
} }
#if BSHELL_INTERACTIVE == 1
static void new_line_ed(void) static void new_line_ed(void)
{ {
bshell_line_ed_core *ed_core = bshell_line_ed_core_create(); bshell_line_ed_core *ed_core = bshell_line_ed_core_create();
@@ -96,9 +100,11 @@ static void new_line_ed(void)
fx_string_unref(line); fx_string_unref(line);
bshell_line_ed_unref(ed); bshell_line_ed_unref(ed);
} }
#endif
static enum bshell_status load_profile(struct frontend_ctx *ctx) static enum bshell_status load_profile(struct frontend_ctx *ctx)
{ {
#if BSHELL_INTERACTIVE == 1
enum bshell_status status = BSHELL_SUCCESS; enum bshell_status status = BSHELL_SUCCESS;
fx_path *config_base_dir = fx_path_get_system(FX_PATH_CONFIG); fx_path *config_base_dir = fx_path_get_system(FX_PATH_CONFIG);
fx_path *profile_path = fx_path_join_list( fx_path *profile_path = fx_path_join_list(
@@ -124,6 +130,8 @@ static enum bshell_status load_profile(struct frontend_ctx *ctx)
} }
fx_path_unref(profile_path); fx_path_unref(profile_path);
return status; return status;
#endif
return BSHELL_SUCCESS;
} }
static int bshell( static int bshell(