Skip to content

Commit 9ff1b63

Browse files
committed
Allowing to build njs util without interactive shell support.
1 parent 4c7497f commit 9ff1b63

File tree

4 files changed

+24
-32
lines changed

4 files changed

+24
-32
lines changed

auto/make

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ NJS_TYPES_VER = \$(NJS_VER)
2626

2727
NPM = npm
2828

29-
default: $NJS_DEFAULT_TARGET
29+
default: njs
3030

3131
NJS_LIB_INCS = -Isrc -I$NJS_BUILD_DIR
3232

@@ -69,8 +69,6 @@ done
6969

7070
# njs cli.
7171

72-
if [ $NJS_HAVE_READLINE = YES ]; then
73-
7472
cat << END >> $NJS_MAKEFILE
7573

7674
$NJS_BUILD_DIR/njs: \\
@@ -84,21 +82,6 @@ $NJS_BUILD_DIR/njs: \\
8482

8583
END
8684

87-
else
88-
89-
cat << END >> $NJS_MAKEFILE
90-
91-
$NJS_BUILD_DIR/njs:
92-
@echo
93-
@echo " error: to make njs CLI \"readline\" library is required."
94-
@echo
95-
@exit 1
96-
97-
END
98-
99-
fi
100-
101-
10285
# njs fuzzer.
10386

10487
cat << END >> $NJS_MAKEFILE
@@ -209,7 +192,7 @@ $NJS_BUILD_DIR/njs_auto_config.h:
209192
@exit 1
210193

211194
all: $NJS_BUILD_DIR/njs_auto_config.h \\
212-
$NJS_DEFAULT_TARGET ts test lib_test benchmark
195+
njs ts test lib_test benchmark
213196

214197
njs: $NJS_BUILD_DIR/njs_auto_config.h $NJS_BUILD_DIR/njs
215198
njs_fuzzer: $NJS_BUILD_DIR/njs_auto_config.h \\

auto/readline

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ if [ $njs_found = no ]; then
6868
. auto/feature
6969
fi
7070

71-
NJS_DEFAULT_TARGET=libnjs
72-
7371
if [ $njs_found = yes ]; then
7472
NJS_HAVE_READLINE=YES
73+
njs_define=NJS_HAVE_READLINE . auto/define
7574
NJS_READLINE_LIB=$njs_feature_libs
76-
NJS_DEFAULT_TARGET="$NJS_DEFAULT_TARGET njs"
7775

7876
else
7977
NJS_HAVE_READLINE=NO
80-
echo " - building interactive shell is not possible"
78+
echo " - njs CLI is built without interactive shell support"
8179
fi

auto/summary

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ fi
2121

2222
echo
2323
echo " njs build dir: $NJS_BUILD_DIR"
24-
25-
if [ $NJS_HAVE_READLINE = YES ]; then
26-
echo " njs CLI: $NJS_BUILD_DIR/njs"
27-
fi
24+
echo " njs CLI: $NJS_BUILD_DIR/njs"
2825

2926
echo

src/njs_shell.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <njs_main.h>
99

10-
#ifndef NJS_FUZZER_TARGET
10+
#if (!defined NJS_FUZZER_TARGET && defined NJS_HAVE_READLINE)
1111

1212
#include <locale.h>
1313
#if (NJS_HAVE_EDITLINE)
@@ -101,10 +101,13 @@ static njs_int_t njs_process_script(njs_opts_t *opts,
101101
static njs_int_t njs_options_parse(njs_opts_t *opts, int argc, char **argv);
102102
static void njs_options_free(njs_opts_t *opts);
103103
static njs_int_t njs_process_file(njs_opts_t *opts, njs_vm_opt_t *vm_options);
104+
105+
#ifdef NJS_HAVE_READLINE
104106
static njs_int_t njs_interactive_shell(njs_opts_t *opts,
105107
njs_vm_opt_t *vm_options);
106108
static njs_int_t njs_editline_init(void);
107109
static char *njs_completion_generator(const char *text, int state);
110+
#endif
108111

109112
#endif
110113

@@ -282,10 +285,16 @@ main(int argc, char **argv)
282285
vm_options.ast = opts.ast;
283286
vm_options.unhandled_rejection = opts.unhandled_rejection;
284287

288+
#ifdef NJS_HAVE_READLINE
289+
285290
if (opts.interactive) {
286291
ret = njs_interactive_shell(&opts, &vm_options);
287292

288-
} else if (opts.command) {
293+
} else
294+
295+
#endif
296+
297+
if (opts.command) {
289298
vm = njs_create_vm(&opts, &vm_options);
290299
if (vm != NULL) {
291300
command.start = (u_char *) opts.command;
@@ -314,9 +323,14 @@ njs_options_parse(njs_opts_t *opts, int argc, char **argv)
314323
njs_uint_t n;
315324

316325
static const char help[] =
317-
"Interactive njs shell.\n"
326+
"njs [options] [-c string | script.js | -] [script args]\n"
318327
"\n"
319-
"njs [options] [-c string | script.js | -] [script args]"
328+
"Interactive shell: "
329+
#ifdef NJS_HAVE_READLINE
330+
"enabled\n"
331+
#else
332+
"disabled\n"
333+
#endif
320334
"\n"
321335
"Options:\n"
322336
" -a print AST.\n"
@@ -914,7 +928,7 @@ njs_process_script(njs_opts_t *opts, njs_console_t *console,
914928
}
915929

916930

917-
#ifndef NJS_FUZZER_TARGET
931+
#if (!defined NJS_FUZZER_TARGET && defined NJS_HAVE_READLINE)
918932

919933
static njs_int_t
920934
njs_interactive_shell(njs_opts_t *opts, njs_vm_opt_t *vm_options)

0 commit comments

Comments
 (0)