]> git.kaiwu.me - njs.git/commitdiff
Allowing to build njs util without interactive shell support.
authorDmitry Volyntsev <xeioex@nginx.com>
Mon, 29 Nov 2021 14:41:09 +0000 (14:41 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Mon, 29 Nov 2021 14:41:09 +0000 (14:41 +0000)
auto/make
auto/readline
auto/summary
src/njs_shell.c

index a4e3bca34419a7133dbbaa28a19199fa6d640d7c..9a807a8fee437a4fdcd212be24059b6ff1dee016 100644 (file)
--- 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 \\
index 6ffdf3f87c1c73f76b0259cdca60551da7abf055..505e11e403bf3edb7e86b68cf19a03226c0d75da 100644 (file)
@@ -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
index 90bac3de2aceb38272cd32437931f8a2ebdaf37e..154d47c66eb3e73d4d75db4b2dc255c1b4a93507 100644 (file)
@@ -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
index 5abb1719eb67518de5eaffee4bb6bb37b555cc95..89dcede74397a05745e7f0776f229248bb894d35 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <njs_main.h>
 
-#ifndef NJS_FUZZER_TARGET
+#if (!defined NJS_FUZZER_TARGET && defined NJS_HAVE_READLINE)
 
 #include <locale.h>
 #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)