build: add support for disabling native command support
This commit is contained in:
+9
-1
@@ -7,6 +7,10 @@ if (NOT DEFINED bshell_interactive)
|
||||
set(bshell_interactive 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED bshell_enable_native_commands)
|
||||
set(bshell_enable_native_commands 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED bshell_verbose)
|
||||
set(bshell_verbose 0)
|
||||
endif ()
|
||||
@@ -15,12 +19,16 @@ if (NOT DEFINED bshell_enable_floating_point)
|
||||
set(bshell_enable_floating_point 1)
|
||||
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)
|
||||
set(required_fx_assemblies ${required_fx_assemblies} fx.term)
|
||||
endif ()
|
||||
|
||||
if (bshell_enable_native_commands)
|
||||
set(required_fx_assemblies ${required_fx_assemblies} fx.diagnostics)
|
||||
endif ()
|
||||
|
||||
find_package(Python COMPONENTS Interpreter REQUIRED)
|
||||
find_package(FX REQUIRED COMPONENTS ${required_fx_assemblies})
|
||||
|
||||
|
||||
@@ -18,3 +18,5 @@ target_include_directories(bshell.core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/includ
|
||||
target_compile_definitions(bshell.core PUBLIC
|
||||
BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point}
|
||||
BSHELL_VERSION="${bshell_version}")
|
||||
|
||||
install(TARGETS bshell.core)
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
set(source_dirs
|
||||
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
|
||||
*.c
|
||||
@@ -15,15 +19,22 @@ endforeach (d)
|
||||
|
||||
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)
|
||||
target_link_libraries(bshell.runtime FX::Term)
|
||||
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_compile_definitions(bshell.runtime PUBLIC
|
||||
BSHELL_VERSION="${bshell_version}"
|
||||
BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point}
|
||||
BSHELL_ENABLE_NATIVE_COMMANDS=${bshell_enable_native_commands}
|
||||
BSHELL_INTERACTIVE=${bshell_interactive}
|
||||
BSHELL_VERBOSE=${bshell_verbose})
|
||||
|
||||
install(TARGETS bshell.runtime)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#if BSHELL_ENABLE_NATIVE_COMMANDS == 1
|
||||
#include <bshell/command/command.h>
|
||||
#include <bshell/command/native-command.h>
|
||||
#include <bshell/format.h>
|
||||
@@ -231,3 +232,4 @@ FX_TYPE_DEFINITION_BEGIN(bshell_native_command)
|
||||
FX_TYPE_INSTANCE_FINI(fini);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct bshell_native_command_p);
|
||||
FX_TYPE_DEFINITION_END(bshell_native_command)
|
||||
#endif
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <bshell/status.h>
|
||||
#include <fx/collections/array.h>
|
||||
#include <fx/collections/hashtable.h>
|
||||
#include <fx/diagnostics/process.h>
|
||||
#include <fx/io/path.h>
|
||||
#include <fx/reflection/assembly.h>
|
||||
#include <fx/reflection/function.h>
|
||||
@@ -15,6 +14,10 @@
|
||||
#include <fx/string.h>
|
||||
#include <fx/vector.h>
|
||||
|
||||
#if BSHELL_ENABLE_NATIVE_COMMANDS == 1
|
||||
#include <fx/diagnostics/process.h>
|
||||
#endif
|
||||
|
||||
#if BSHELL_INTERACTIVE == 1
|
||||
#include <fx/term/print.h>
|
||||
#endif
|
||||
@@ -107,6 +110,7 @@ static bshell_command *resolve_cmdlet(
|
||||
|
||||
static const fx_string *get_path(void)
|
||||
{
|
||||
#if BSHELL_ENABLE_NATIVE_COMMANDS == 1
|
||||
fx_process *self = fx_process_get_self();
|
||||
if (!self) {
|
||||
return NULL;
|
||||
@@ -125,8 +129,12 @@ static const fx_string *get_path(void)
|
||||
const fx_string *path = NULL;
|
||||
fx_value_get_object(path_v, (fx_object **)&path);
|
||||
return path;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if BSHELL_ENABLE_NATIVE_COMMANDS == 1
|
||||
static bshell_command *resolve_native_command_local(
|
||||
struct bshell_cmdcall_p *cmdcall,
|
||||
struct bshell_runtime *rt,
|
||||
@@ -188,6 +196,7 @@ static bshell_command *resolve_native_command(
|
||||
fx_iterator_unref(it);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
static enum bshell_status resolve_call_target(
|
||||
struct bshell_cmdcall_p *cmdcall,
|
||||
@@ -206,11 +215,13 @@ static enum bshell_status resolve_call_target(
|
||||
return BSHELL_SUCCESS;
|
||||
}
|
||||
|
||||
#if BSHELL_ENABLE_NATIVE_COMMANDS == 1
|
||||
if ((cmdcall->cmd_target
|
||||
= resolve_native_command(cmdcall, rt, cmd_name_s))) {
|
||||
cmdcall->cmd_type = CMDCALL_NATIVE;
|
||||
return BSHELL_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *cmd_name_cstr = fx_string_get_cstr(cmd_name_s);
|
||||
#if BSHELL_INTERACTIVE == 1
|
||||
|
||||
@@ -33,3 +33,5 @@ target_compile_definitions(bshell PUBLIC
|
||||
BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point}
|
||||
BSHELL_INTERACTIVE=${bshell_interactive}
|
||||
BSHELL_VERBOSE=${bshell_verbose})
|
||||
|
||||
install(TARGETS bshell)
|
||||
|
||||
+12
-4
@@ -4,10 +4,6 @@
|
||||
#include <bshell/compile.h>
|
||||
#include <bshell/file.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/parse.h>
|
||||
#include <bshell/parse/token.h>
|
||||
@@ -16,6 +12,13 @@
|
||||
#include <fx/io/path.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 {
|
||||
CMD_ROOT,
|
||||
OPT_LEX,
|
||||
@@ -75,6 +78,7 @@ static enum frontend_flags collect_frontend_flags(const fx_arglist *opt)
|
||||
return result;
|
||||
}
|
||||
|
||||
#if BSHELL_INTERACTIVE == 1
|
||||
static void new_line_ed(void)
|
||||
{
|
||||
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);
|
||||
bshell_line_ed_unref(ed);
|
||||
}
|
||||
#endif
|
||||
|
||||
static enum bshell_status load_profile(struct frontend_ctx *ctx)
|
||||
{
|
||||
#if BSHELL_INTERACTIVE == 1
|
||||
enum bshell_status status = BSHELL_SUCCESS;
|
||||
fx_path *config_base_dir = fx_path_get_system(FX_PATH_CONFIG);
|
||||
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);
|
||||
return status;
|
||||
#endif
|
||||
return BSHELL_SUCCESS;
|
||||
}
|
||||
|
||||
static int bshell(
|
||||
|
||||
Reference in New Issue
Block a user