From 9ff1b638576338a5b64df64584d621e7708eef36 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Mon, 29 Nov 2021 14:41:09 +0000 Subject: [PATCH] Allowing to build njs util without interactive shell support. --- auto/make | 21 ++------------------- auto/readline | 6 ++---- auto/summary | 5 +---- src/njs_shell.c | 24 +++++++++++++++++++----- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/auto/make b/auto/make index a4e3bca3..9a807a8f 100644 --- a/auto/make +++ b/auto/make @@ -26,7 +26,7 @@ NJS_TYPES_VER = \$(NJS_VER) NPM = npm -default: $NJS_DEFAULT_TARGET +default: njs NJS_LIB_INCS = -Isrc -I$NJS_BUILD_DIR @@ -69,8 +69,6 @@ done # njs cli. -if [ $NJS_HAVE_READLINE = YES ]; then - cat << END >> $NJS_MAKEFILE $NJS_BUILD_DIR/njs: \\ @@ -84,21 +82,6 @@ $NJS_BUILD_DIR/njs: \\ END -else - -cat << END >> $NJS_MAKEFILE - -$NJS_BUILD_DIR/njs: - @echo - @echo " error: to make njs CLI \"readline\" library is required." - @echo - @exit 1 - -END - -fi - - # njs fuzzer. cat << END >> $NJS_MAKEFILE @@ -209,7 +192,7 @@ $NJS_BUILD_DIR/njs_auto_config.h: @exit 1 all: $NJS_BUILD_DIR/njs_auto_config.h \\ - $NJS_DEFAULT_TARGET ts test lib_test benchmark + njs ts test lib_test benchmark njs: $NJS_BUILD_DIR/njs_auto_config.h $NJS_BUILD_DIR/njs njs_fuzzer: $NJS_BUILD_DIR/njs_auto_config.h \\ diff --git a/auto/readline b/auto/readline index 6ffdf3f8..505e11e4 100644 --- a/auto/readline +++ b/auto/readline @@ -68,14 +68,12 @@ if [ $njs_found = no ]; then . auto/feature fi -NJS_DEFAULT_TARGET=libnjs - if [ $njs_found = yes ]; then NJS_HAVE_READLINE=YES + njs_define=NJS_HAVE_READLINE . auto/define NJS_READLINE_LIB=$njs_feature_libs - NJS_DEFAULT_TARGET="$NJS_DEFAULT_TARGET njs" else NJS_HAVE_READLINE=NO - echo " - building interactive shell is not possible" + echo " - njs CLI is built without interactive shell support" fi diff --git a/auto/summary b/auto/summary index 90bac3de..154d47c6 100644 --- a/auto/summary +++ b/auto/summary @@ -21,9 +21,6 @@ fi echo echo " njs build dir: $NJS_BUILD_DIR" - -if [ $NJS_HAVE_READLINE = YES ]; then - echo " njs CLI: $NJS_BUILD_DIR/njs" -fi +echo " njs CLI: $NJS_BUILD_DIR/njs" echo diff --git a/src/njs_shell.c b/src/njs_shell.c index 5abb1719..89dcede7 100644 --- a/src/njs_shell.c +++ b/src/njs_shell.c @@ -7,7 +7,7 @@ #include -#ifndef NJS_FUZZER_TARGET +#if (!defined NJS_FUZZER_TARGET && defined NJS_HAVE_READLINE) #include #if (NJS_HAVE_EDITLINE) @@ -101,10 +101,13 @@ static njs_int_t njs_process_script(njs_opts_t *opts, static njs_int_t njs_options_parse(njs_opts_t *opts, int argc, char **argv); static void njs_options_free(njs_opts_t *opts); static njs_int_t njs_process_file(njs_opts_t *opts, njs_vm_opt_t *vm_options); + +#ifdef NJS_HAVE_READLINE static njs_int_t njs_interactive_shell(njs_opts_t *opts, njs_vm_opt_t *vm_options); static njs_int_t njs_editline_init(void); static char *njs_completion_generator(const char *text, int state); +#endif #endif @@ -282,10 +285,16 @@ main(int argc, char **argv) vm_options.ast = opts.ast; vm_options.unhandled_rejection = opts.unhandled_rejection; +#ifdef NJS_HAVE_READLINE + if (opts.interactive) { ret = njs_interactive_shell(&opts, &vm_options); - } else if (opts.command) { + } else + +#endif + + if (opts.command) { vm = njs_create_vm(&opts, &vm_options); if (vm != NULL) { command.start = (u_char *) opts.command; @@ -314,9 +323,14 @@ njs_options_parse(njs_opts_t *opts, int argc, char **argv) njs_uint_t n; static const char help[] = - "Interactive njs shell.\n" + "njs [options] [-c string | script.js | -] [script args]\n" "\n" - "njs [options] [-c string | script.js | -] [script args]" + "Interactive shell: " +#ifdef NJS_HAVE_READLINE + "enabled\n" +#else + "disabled\n" +#endif "\n" "Options:\n" " -a print AST.\n" @@ -914,7 +928,7 @@ njs_process_script(njs_opts_t *opts, njs_console_t *console, } -#ifndef NJS_FUZZER_TARGET +#if (!defined NJS_FUZZER_TARGET && defined NJS_HAVE_READLINE) static njs_int_t njs_interactive_shell(njs_opts_t *opts, njs_vm_opt_t *vm_options) -- 2.47.3