diff --git a/Makefile b/Makefile index aaaabf3909c335..59e0596c218157 100644 --- a/Makefile +++ b/Makefile @@ -148,7 +148,7 @@ BASE_SRCS := $(wildcard base/*.jl base/*/*.jl base/*/*/*.jl) $(build_private_libdir)/sys.o: VERSION $(BASE_SRCS) $(build_docdir)/helpdb.jl $(build_private_libdir)/sys0.$(SHLIB_EXT) @$(call PRINT_JULIA, cd base && \ $(call spawn,$(JULIA_EXECUTABLE)) -C $(JULIA_CPU_TARGET) --build $(call cygpath_w,$(build_private_libdir)/sys) \ - -J$(call cygpath_w,$(build_private_libdir))/$$([ -e $(build_private_libdir)/sys.ji ] && echo sys.ji || echo sys0.ji) -f sysimg.jl \ + -J$(call cygpath_w,$(build_private_libdir))/$$([ -e $(build_private_libdir)/sys.ji ] && echo sys.ji || echo sys0.ji) --startup-file=no sysimg.jl \ || { echo '*** This error is usually fixed by running `make clean`. If the error persists$(,) try `make cleanall`. ***' && false; } ) $(build_bindir)/stringreplace: contrib/stringreplace.c | $(build_bindir) diff --git a/base/client.jl b/base/client.jl index db5266cb77ebd7..4aef121449675c 100644 --- a/base/client.jl +++ b/base/client.jl @@ -1,6 +1,23 @@ ## client.jl - frontend handling command line options, environment setup, ## and REPL +immutable JLOptions + version::Int8 + quiet::Int8 + eval::Ptr{Cchar} + print::Ptr{Cchar} + postboot::Ptr{Cchar} + load::Ptr{Cchar} + nprocs::Clong + machinefile::Ptr{Cchar} + isinteractive::Int8 + color::Int8 + historyfile::Int8 + startupfile::Int8 + worker::Int8 + bindto::Ptr{Cchar} +end + const ARGS = UTF8String[] const text_colors = AnyDict( @@ -183,12 +200,12 @@ end # try to include() a file, ignoring if not found try_include(path::AbstractString) = isfile(path) && include(path) -function init_bind_addr(args::Vector{UTF8String}) +function init_bind_addr() # Treat --bind-to in a position independent manner in ARGS since # --worker, -n and --machinefile options are affected by it - btoidx = findfirst(args, "--bind-to") - if btoidx > 0 - bind_to = split(args[btoidx+1], ":") + opts = unsafe_load(cglobal(:jl_options, JLOptions)) + if opts.bindto != C_NULL + bind_to = split(bytestring(opts.bindto), ":") bind_addr = string(parseip(bind_to[1])) if length(bind_to) > 1 bind_port = parseint(bind_to[2]) @@ -210,113 +227,121 @@ function init_bind_addr(args::Vector{UTF8String}) LPROC.bind_port = uint16(bind_port) end - -function process_options(args::Vector{UTF8String}) - quiet = false - repl = true - startup = true - color_set = false - no_history_file = false - i = 1 - while i <= length(args) - if args[i]=="-q" || args[i]=="--quiet" - quiet = true - elseif args[i]=="--worker" - start_worker() - # doesn't return - elseif args[i]=="--bind-to" - i+=1 # has already been processed - elseif args[i]=="-e" || args[i]=="--eval" - i == length(args) && error("-e,--eval no provided") - repl = false - i+=1 - splice!(ARGS, 1:length(ARGS), args[i+1:end]) - eval(Main,parse_input_line(args[i])) - break - elseif args[i]=="-E" || args[i]=="--print" - i == length(args) && error("-E,--print no provided") - repl = false - i+=1 - splice!(ARGS, 1:length(ARGS), args[i+1:end]) - show(eval(Main,parse_input_line(args[i]))) - println() - break - elseif args[i]=="-P" || args[i]=="--post-boot" - i == length(args) && error("-P,--post-boot no provided") - i+=1 - eval(Main,parse_input_line(args[i])) - elseif args[i]=="-L" || args[i]=="--load" - i == length(args) && error("-L, --load no provided") - i+=1 - require(args[i]) - elseif args[i]=="-p" - i == length(args) && error("-p processes not provided") - i+=1 - if i > length(args) || !isdigit(args[i][1]) - np = Sys.CPU_CORES - i -= 1 - else - np = int(args[i]) - np < 1 && error("-p must be ≥ 1") +let reqarg = Set(UTF8String["--home", "-H", + "--eval", "-e", + "--print", "-E", + "--post-boot", "-P", + "--load", "-L", + "--sysimage", "-J", + "--cpu-target", "-C", + "--procs", "-p", + "--machinefile", + "--color", + "--history-file", + "--startup-file", + "--compile", + "--check-bounds", + "--int-literals", + "--dump-bitcode", + "--depwarn", + "--build", "-b", + "--bind-to"]) + global process_options + function process_options(args::Vector{UTF8String}) + if !isempty(args) && (arg = first(args); arg[1] == '-' && in(arg, reqarg)) + println(STDERR, "julia: option `$arg` is missing an argument") + exit(1) + end + quiet = false + repl = true + startup = true + color_set = false + no_history_file = false + opts = unsafe_load(cglobal(:jl_options, JLOptions)) + while true + # show julia VERSION and quit + if bool(opts.version) + println("julia version ", VERSION) + exit(0) end - addprocs(np) - elseif args[i]=="--machinefile" - i == length(args) && error("--machinefile no provided") - i+=1 - machines = load_machine_file(args[i]) - addprocs(machines) - elseif args[i]=="-v" || args[i]=="--version" - println("julia version ", VERSION) - exit(0) - elseif args[i]=="--no-history" - # deprecated in v0.3 - warn("'--no-history' is deprecated; use '--no-history-file'") - no_history_file = true - elseif args[i] == "--no-history-file" - no_history_file = true - elseif args[i] == "-f" || args[i] == "--no-startup" - startup = false - elseif args[i] == "-F" - # load juliarc now before processing any more options - load_juliarc() - startup = false - elseif args[i] == "-i" - global is_interactive = true - elseif beginswith(args[i], "--color") - if args[i] == "--color" - color_set = true - global have_color = true - elseif args[i][8] == '=' - val = args[i][9:end] - if in(val, ("no","0","false")) - color_set = true - global have_color = false - elseif in(val, ("yes","1","true")) - color_set = true - global have_color = true - end + # startup worker + if bool(opts.worker) + start_worker() # does not return end - if !color_set - error("invalid option: ", args[i]) + # load file immediately on all processors + if opts.load != C_NULL + require(bytestring(opts.load)) end - elseif args[i][1]!='-' - if startup + # show banner + quiet = bool(opts.quiet) + # load ~/.juliarc file + if opts.startupfile == 1 load_juliarc() startup = false + elseif opts.startupfile == 2 + startup = false + end + # load ~/.julia_history file + no_history_file = bool(opts.historyfile) + # add processors + if opts.nprocs > 1 + addprocs(opts.nprocs) + end + # load processes from machine file + if opts.machinefile != C_NULL + addprocs(load_machine_file(bytestring(opt.machinefile))) + end + global is_interactive = bool(opts.isinteractive) + # REPL color + if opts.color == 0 + color_set = false + global have_color = false + elseif opts.color == 1 + color_set = true + global have_color = true + elseif opts.color == 2 + color_set = true + global have_color = false + end + # eval expression + if opts.eval != C_NULL + repl = false + eval(Main, parse_input_line(bytestring(opts.eval))) + break + end + # eval expression and show result + if opts.print != C_NULL + repl = false + show(eval(Main, parse_input_line(bytestring(opts.print)))) + println() + break + end + # eval expression but don't disable interactive mode + if opts.postboot != C_NULL + eval(Main, parse_input_line(bytestring(opts.postboot))) + end + # load file + if !isempty(args) + if args[1][1] != '-' + if startup + load_juliarc() + startup = false + end + # program + repl = false + # remove filename from ARGS + shift!(ARGS) + ccall(:jl_exit_on_sigint, Void, (Cint,), 1) + include(args[1]) + else + println(STDERR, "julia: unknown option `$(args[1])`") + exit(1) + end end - # program - repl = false - # remove julia's arguments - splice!(ARGS, 1:length(ARGS), args[i+1:end]) - ccall(:jl_exit_on_sigint, Void, (Cint,), 1) - include(args[i]) break - else - error("unknown option: ", args[i]) end - i += 1 + return (quiet,repl,startup,color_set,no_history_file) end - return (quiet,repl,startup,color_set,no_history_file) end const roottask = current_task() @@ -388,7 +413,7 @@ import .REPL function _start() try init_parallel() - init_bind_addr(ARGS) + init_bind_addr() any(a->(a=="--worker"), ARGS) || init_head_sched() (quiet,repl,startup,color_set,no_history_file) = process_options(copy(ARGS)) diff --git a/base/inference.jl b/base/inference.jl index 8d1751244e4346..bfd3542aa0e7d8 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -1161,6 +1161,7 @@ function tmerge(typea::ANY, typeb::ANY) return u end + tchanged(n::ANY, o::ANY) = is(o,NF) || (!is(n,NF) && !(n <: o)) stupdate(state::(), changes::VarTable, vars) = copy(changes) diff --git a/src/init.c b/src/init.c index ae0ded2a646037..584acff0a8666e 100644 --- a/src/init.c +++ b/src/init.c @@ -103,6 +103,22 @@ jl_compileropts_t jl_compileropts = { NULL, // julia_home 1, // depwarn }; +jl_options_t jl_options = { 0, // version + 0, // quiet + NULL, // eval + NULL, // print + NULL, // postboot + NULL, // load + 0, // nprocs + NULL, // machinefile + 0, // isinteractive + 0, // color + 0, // historyfile + 0, // startupfile + 0, // worker + NULL, // bindto +}; + int jl_boot_file_loaded = 0; int exit_on_sigint = 0; diff --git a/src/julia.h b/src/julia.h index e39f0987dd4e24..2dd3176159e290 100644 --- a/src/julia.h +++ b/src/julia.h @@ -1344,6 +1344,7 @@ extern DLLEXPORT jl_compileropts_t jl_compileropts; #define JL_COMPILEROPT_CHECK_BOUNDS_DEFAULT 0 #define JL_COMPILEROPT_CHECK_BOUNDS_ON 1 #define JL_COMPILEROPT_CHECK_BOUNDS_OFF 2 + #define JL_COMPILEROPT_COMPILE_DEFAULT 1 #define JL_COMPILEROPT_COMPILE_OFF 0 #define JL_COMPILEROPT_COMPILE_ON 1 @@ -1355,11 +1356,33 @@ extern DLLEXPORT jl_compileropts_t jl_compileropts; // julia options -------------------------------------------------------------- typedef struct { - compiler_opts_t *compiler_opts; -} jl_options_t + int8_t version; + int8_t quiet; + const char *eval; + const char *print; + const char *postboot; + const char *load; + long nprocs; + const char *machinefile; + int8_t isinteractive; + int8_t color; + int8_t historyfile; + int8_t startupfile; + int8_t worker; + const char *bindto; +} jl_options_t; extern DLLEXPORT jl_options_t jl_options; +#define JL_OPTIONS_COLOR_ON 1 +#define JL_OPTIONS_COLOR_OFF 2 + +#define JL_OPTIONS_HISTORYFILE_ON 1 +#define JL_OPTIONS_HISTORYFILE_OFF 0 + +#define JL_OPTIONS_STARTUPFILE_ON 1 +#define JL_OPTIONS_STARTUPFILE_OFF 2 + // Version information #include "julia_version.h" diff --git a/test/Makefile b/test/Makefile index 2fe67f6e0ca406..8c97294bc5bc15 100644 --- a/test/Makefile +++ b/test/Makefile @@ -6,7 +6,7 @@ TESTS = all linalg $(filter-out TestHelpers runtests testdefs,$(subst .jl,,$(wil default: all $(TESTS) :: - @$(call PRINT_JULIA, $(call spawn,$(JULIA_EXECUTABLE)) --check-bounds=yes -f ./runtests.jl $@) + @$(call PRINT_JULIA, $(call spawn,$(JULIA_EXECUTABLE)) --check-bounds=yes --startup-file=no ./runtests.jl $@) perf: @$(MAKE) -C perf all diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl new file mode 100644 index 00000000000000..8b6ccc3a12f3c9 --- /dev/null +++ b/test/cmdlineargs.jl @@ -0,0 +1,87 @@ +exename = joinpath(JULIA_HOME, (ccall(:jl_is_debugbuild, Cint, ()) == 0 ? "julia" : "julia-debug")) + +# --version +let v = split(readall(`$exename -v`), "julia version ")[end] + @test VERSION == VersionNumber(v) +end +@test readall(`$exename -v`) == readall(`$exename --version`) + +# --eval +@test !success(`$exename -e "exit(1)"`) +@test !success(`$exename --eval="exit(1)"`) +@test !success(`$exename -e`) +@test !success(`$exename --eval`) + +# --print +@test readall(`$exename -E "1+1"`) == "2\n" +@test readall(`$exename --print="1+1"`) == "2\n" +@test !success(`$exename -E`) +@test !success(`$exename --print`) + +# --post-boot +@test success(`$exename -P "exit(0)"`) +@test success(`$exename --post-boot="exit(0)"`) +@test !success(`$exename -P`) +@test !success(`$exename --post-boot`) + +# --load +let testfile = joinpath(dirname(@__FILE__), "test_loadfile.jl") + @test split(readchomp(`$exename --load=$testfile -P "println(a)"`), '\n')[end] == "test" + @test split(readchomp(`$exename -P "println(a)" -L $testfile`), '\n')[end] == "test" + @test !success(`$exename -L`) + @test !success(`$exename --load`) +end + +# --procs +@test readchomp(`$exename -q -p 2 -P "println(nworkers()); exit(0)"`) == "2" +@test !success(`$exename -p 0`) +@test !success(`$exename --procs=1.0`) + +# isinteractive +@test readchomp(`$exename -E "isinteractive()"`) == "false" +@test readchomp(`$exename -E "isinteractive()" -i`) == "true" + +# --color +@test readchomp(`$exename --color=yes -E "Base.have_color"`) == "true" +@test readchomp(`$exename --color=no -E "Base.have_color"`) == "false" +@test !success(`$exename --color=false`) + +# --int-literals +# readchomp(`$exename --int-literals=32 -E "sizeof(Int)"`) +# readchomp(`$exename --int-literals=64 -E "sizeof(Int)"`) + +# --code-coverage +@test readchomp(`$exename -E "bool(Base.compileropts().code_coverage)"`) == "false" +@test readchomp(`$exename -E "bool(Base.compileropts().code_coverage)" --code-coverage=none`) == "false" + +@test readchomp(`$exename -E "bool(Base.compileropts().code_coverage)" --code-coverage`) == "true" +@test readchomp(`$exename -E "bool(Base.compileropts().code_coverage)" --code-coverage=user`) == "true" + +# --track-allocation +@test readchomp(`$exename -E "bool(Base.compileropts().malloc_log)"`) == "false" +@test readchomp(`$exename -E "bool(Base.compileropts().malloc_log)" --track-allocation=none`) == "false" + +@test readchomp(`$exename -E "bool(Base.compileropts().malloc_log)" --track-allocation`) == "true" +@test readchomp(`$exename -E "bool(Base.compileropts().malloc_log)" --track-allocation=user`) == "true" + +# --check-bounds +@test int(readchomp(`$exename -E "int(Base.compileropts().check_bounds)"`)) == 0 +@test int(readchomp(`$exename -E "int(Base.compileropts().check_bounds)" --check-bounds=yes`)) == 1 +@test int(readchomp(`$exename -E "int(Base.compileropts().check_bounds)" --check-bounds=no`)) == 2 +@test !success(`$exename -E "exit(0)" --check-bounds=false`) + +# --optimize +@test readchomp(`$exename -E "bool(Base.compileropts().opt_level)"`) == "false" +@test readchomp(`$exename -E "bool(Base.compileropts().opt_level)" -O`) == "true" +@test readchomp(`$exename -E "bool(Base.compileropts().opt_level)" --optimize`) == "true" + +# --depwarn +@test readchomp(`$exename --depwarn=no -E "Base.syntax_deprecation_warnings(true)"`) == "false" +@test readchomp(`$exename --depwarn=yes -E "Base.syntax_deprecation_warnings(false)"`) == "true" +@test !success(`$exename --depwarn=false`) + +# pass arguments +let testfile = joinpath(dirname(@__FILE__), "test_loadfile.jl") + @test readchomp(`$exename $testfile foo -bar --baz`) == "UTF8String[\"foo\",\"-bar\",\"--baz\"]" + @test !success(`$exename --foo $testfile`) +end diff --git a/test/runtests.jl b/test/runtests.jl index 316080e746f61b..96ed4a4066b183 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,8 +10,8 @@ testnames = [ "floatapprox", "readdlm", "reflection", "regex", "float16", "combinatorics", "sysinfo", "rounding", "ranges", "mod2pi", "euler", "show", "lineedit", "replcompletions", "repl", "test", "goto", - "llvmcall", "grisu", "nullable", "meta", "profile", - "libgit2", "docs" + "llvmcall", "grisu", "nullable", "meta", "profile", "libgit2", "docs", + "cmdlineargs" ] if isdir(joinpath(JULIA_HOME, Base.DOCDIR, "examples")) diff --git a/test/test_loadfile.jl b/test/test_loadfile.jl new file mode 100644 index 00000000000000..0c7d3d5aa59f0b --- /dev/null +++ b/test/test_loadfile.jl @@ -0,0 +1,2 @@ +a = :test +println(ARGS) diff --git a/ui/repl.c b/ui/repl.c index 04ac813e2330c3..de21621b83a990 100644 --- a/ui/repl.c +++ b/ui/repl.c @@ -44,60 +44,97 @@ static int imagepathspecified = 0; static const char *usage = "julia [options] [program] [args...]\n"; static const char *opts = - " -v, --version Display version information\n" - " -h, --help Print this message\n" - " -q, --quiet Quiet startup without banner\n" - " -H, --home Set location of julia executable\n\n" + " -v, --version Display version information\n" + " -h, --help Print this message\n" + " -q, --quiet Quiet startup without banner\n" + " -H, --home Set location of julia executable\n\n" - " -e, --eval Evaluate \n" - " -E, --print Evaluate and show \n" - " -P, --post-boot Evaluate , but don't disable interactive mode\n" - " -L, --load Load immediately on all processors\n" - " -J, --sysimage Start up with the given system image file\n" - " -C --cpu-target Limit usage of cpu features up to \n\n" + " -e, --eval Evaluate \n" + " -E, --print Evaluate and show \n" + " -P, --post-boot Evaluate , but don't disable interactive mode\n" + " -L, --load Load immediately on all processors\n" + " -J, --sysimage Start up with the given system image file\n" + " -C, --cpu-target Limit usage of cpu features up to \n\n" - " -p Run n local processes\n" - " --machinefile Run processes on hosts listed in \n\n" + " -p, --procs Run n local processes\n" + " --machinefile Run processes on hosts listed in \n\n" - " -i Force isinteractive() to be true\n" - " --no-history-file Don't load or save history\n" - " -f, --no-startup Don't load ~/.juliarc.jl\n" - " -F Load ~/.juliarc.jl, then handle remaining inputs\n" - " --color={yes|no} Enable or disable color text\n\n" + " -i Force isinteractive() to be true\n" + " --color={yes|no} Enable or disable color text\n\n" + " --history-file={yes|no} Load or save history\n" + " --startup-file={yes|no} Load ~/.juliarc.jl\n" + " -f, --no-startup Don't load ~/.juliarc (deprecated, use --startup-file=no)\n" + " -F Load ~/.juliarc (deprecated, use --startup-file=yes)\n" - " --compile={yes|no|all} Enable or disable compiler, or request exhaustive compilation\n\n" + " --compile={yes|no|all} Enable or disable compiler, or request exhaustive compilation\n\n" " --code-coverage={none|user|all}, --code-coverage\n" - " Count executions of source lines (omitting setting is equivalent to 'user')\n" - " --track-allocation={none|user|all}\n" - " Count bytes allocated by each source line\n" - " --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)\n" - " -O, --optimize Run time-intensive code optimizations\n" - " --int-literals={32|64} Select integer literal size independent of platform\n" - " --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)\n" - " --depwarn={yes|no} Enable or disable syntax and method deprecation warnings\n"; + " Count executions of source lines (omitting setting is equivalent to 'user')\n\n" + + " --track-allocation={none|user|all}, --track-allocation\n" + " Count bytes allocated by each source line\n\n" + " -O, --optimize\n" + " Run time-intensive code optimizations\n\n" + + " --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)\n" + " --int-literals={32|64} Select integer literal size independent of platform\n" + " --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)\n" + " --depwarn={yes|no} Enable or disable syntax and method deprecation warnings\n"; void parse_opts(int *argcp, char ***argvp) { - static char* shortopts = "+H:hJ:C:O"; + enum { machinefile = 300, + color, + history_file, + no_history_file, + startup_file, + compile, + code_coverage, + track_allocation, + check_bounds, + int_literals, + dump_bitcode, + depwarn, + worker, + bind_to + }; + static char* shortopts = "+vhqFfH:e:E:P:L:J:C:ip:Ob:"; static struct option longopts[] = { - { "home", required_argument, 0, 'H' }, - { "build", required_argument, 0, 'b' }, - { "lisp", no_argument, &lisp_prompt, 1 }, - { "help", no_argument, 0, 'h' }, - { "sysimage", required_argument, 0, 'J' }, - { "code-coverage", optional_argument, 0, 'c' }, - { "cpu-target", required_argument, 0, 'C' }, - { "track-allocation",required_argument, 0, 'm' }, - { "check-bounds", required_argument, 0, 300 }, - { "optimize", no_argument, 0, 'O' }, - { "int-literals", required_argument, 0, 301 }, - { "dump-bitcode", required_argument, 0, 302 }, - { "compile", required_argument, 0, 303 }, - { "depwarn", required_argument, 0, 304 }, + // exposed command line options + { "version", no_argument, 0, 'v' }, + { "help", no_argument, 0, 'h' }, + { "quiet", no_argument, 0, 'q' }, + { "home", required_argument, 0, 'H' }, + { "eval", required_argument, 0, 'e' }, + { "print", required_argument, 0, 'E' }, + { "post-boot", required_argument, 0, 'P' }, + { "load", required_argument, 0, 'L' }, + { "sysimage", required_argument, 0, 'J' }, + { "cpu-target", required_argument, 0, 'C' }, + { "procs", required_argument, 0, 'p' }, + { "machinefile", required_argument, 0, machinefile }, + { "color", required_argument, 0, color }, + { "history-file", required_argument, 0, history_file }, + { "no-history-file", no_argument, 0, no_history_file }, // deprecated + { "startup-file", required_argument, 0, startup_file }, + { "no-startup", no_argument, 0, 'f' }, // deprecated + { "compile", required_argument, 0, compile }, + { "code-coverage", optional_argument, 0, code_coverage }, + { "track-allocation",optional_argument, 0, track_allocation }, + { "optimize", no_argument, 0, 'O' }, + { "check-bounds", required_argument, 0, check_bounds }, + { "int-literals", required_argument, 0, int_literals }, + { "dump-bitcode", required_argument, 0, dump_bitcode }, + { "depwarn", required_argument, 0, depwarn }, + // hidden command line options + { "build", required_argument, 0, 'b' }, + { "worker", no_argument, 0, worker }, + { "bind-to", required_argument, 0, bind_to }, + { "lisp", no_argument, &lisp_prompt, 1 }, { 0, 0, 0, 0 } }; int c; + char *endptr; opterr = 0; int skip = 0; int lastind = optind; @@ -106,31 +143,103 @@ void parse_opts(int *argcp, char ***argvp) case 0: break; case '?': - if (optind != lastind) skip++; - lastind = optind; + if (optind != lastind) skip++; + lastind = optind; + break; + case 'v': // version + jl_options.version = 1; + break; + case 'h': // help + ios_printf(ios_stdout, "%s%s", usage, opts); + exit(0); + case 'q': // quiet + jl_options.quiet = 1; break; - case 'H': + case 'H': // home jl_compileropts.julia_home = strdup(optarg); break; - case 'b': - jl_compileropts.build_path = strdup(optarg); - if (!imagepathspecified) - jl_compileropts.image_file = NULL; + case 'e': // eval + jl_options.eval = strdup(optarg); + break; + case 'E': // print + jl_options.print = strdup(optarg); + break; + case 'P': // post-boot + jl_options.postboot = strdup(optarg); + break; + case 'L': // load + jl_options.load = strdup(optarg); break; - case 'J': + case 'J': // sysimage jl_compileropts.image_file = strdup(optarg); imagepathspecified = 1; break; - case 'C': + case 'C': // cpu-target jl_compileropts.cpu_target = strdup(optarg); break; - case 'h': - ios_printf(ios_stdout, "%s%s", usage, opts); - exit(0); - case 'O': - jl_compileropts.opt_level = 1; + case 'p': // procs + errno = 0; + jl_options.nprocs = strtol(optarg, &endptr, 10); + if (errno != 0 || optarg == endptr || *endptr != 0 || jl_options.nprocs < 1) { + ios_printf(ios_stderr, "julia: -p,--procs= must be an integer >= 1\n"); + exit(1); + } + break; + case machinefile: + jl_options.machinefile = strdup(optarg); + break; + case color: + if (!strcmp(optarg,"yes")) + jl_options.color = JL_OPTIONS_COLOR_ON; + else if (!strcmp(optarg,"no")) + jl_options.color = JL_OPTIONS_COLOR_OFF; + else { + ios_printf(ios_stderr, "julia: invalid argument to --color={yes|no} (%s)\n", optarg); + exit(1); + } + break; + case history_file: + if (!strcmp(optarg,"yes")) + jl_options.historyfile = JL_OPTIONS_HISTORYFILE_ON; + else if (!strcmp(optarg,"no")) + jl_options.historyfile = JL_OPTIONS_HISTORYFILE_OFF; + else { + ios_printf(ios_stderr, "julia: invalid argument to --history-file={yes|no} (%s)\n", optarg); + exit(1); + } + break; + case no_history_file: + jl_options.historyfile = JL_OPTIONS_HISTORYFILE_OFF; + break; + case startup_file: + if (!strcmp(optarg,"yes")) + jl_options.startupfile = JL_OPTIONS_STARTUPFILE_ON; + else if (!strcmp(optarg,"no")) + jl_options.startupfile = JL_OPTIONS_STARTUPFILE_OFF; + else { + ios_printf(ios_stderr, "julia: invalid argument to --startup-file={yes|no} (%s)\n", optarg); + exit(1); + } + break; + case 'f': + jl_options.startupfile = JL_OPTIONS_STARTUPFILE_OFF; + break; + case 'F': + jl_options.startupfile = JL_OPTIONS_STARTUPFILE_ON; + break; + case compile: + if (!strcmp(optarg,"yes")) + jl_compileropts.compile_enabled = JL_COMPILEROPT_COMPILE_ON; + else if (!strcmp(optarg,"no")) + jl_compileropts.compile_enabled = JL_COMPILEROPT_COMPILE_OFF; + else if (!strcmp(optarg,"all")) + jl_compileropts.compile_enabled = JL_COMPILEROPT_COMPILE_ALL; + else { + ios_printf(ios_stderr, "julia: invalid argument to --compile (%s)\n", optarg); + exit(1); + } break; - case 'c': + case code_coverage: if (optarg != NULL) { if (!strcmp(optarg,"user")) codecov = JL_LOG_USER; @@ -144,7 +253,7 @@ void parse_opts(int *argcp, char ***argvp) codecov = JL_LOG_USER; } break; - case 'm': + case track_allocation: if (optarg != NULL) { if (!strcmp(optarg,"user")) malloclog = JL_LOG_USER; @@ -154,50 +263,63 @@ void parse_opts(int *argcp, char ***argvp) malloclog = JL_LOG_NONE; break; } - case 300: + else { + malloclog = JL_LOG_USER; + } + break; + case 'O': // optimize + jl_compileropts.opt_level = 1; + break; + case 'i': // isinteractive + jl_options.isinteractive = 1; + break; + case check_bounds: if (!strcmp(optarg,"yes")) jl_compileropts.check_bounds = JL_COMPILEROPT_CHECK_BOUNDS_ON; else if (!strcmp(optarg,"no")) jl_compileropts.check_bounds = JL_COMPILEROPT_CHECK_BOUNDS_OFF; + else { + ios_printf(ios_stderr, "julia: invalid argument to --check-bounds={yes|no} (%s)\n", optarg); + exit(1); + } break; - case 301: + case int_literals: if (!strcmp(optarg,"32")) jl_compileropts.int_literals = 32; else if (!strcmp(optarg,"64")) jl_compileropts.int_literals = 64; else { - ios_printf(ios_stderr, "julia: invalid integer literal size (%s)\n", optarg); + ios_printf(ios_stderr, "julia: invalid argument to --int-literals={32|64} (%s)\n", optarg); exit(1); } break; - case 302: + case dump_bitcode: if (!strcmp(optarg,"yes")) jl_compileropts.dumpbitcode = JL_COMPILEROPT_DUMPBITCODE_ON; else if (!strcmp(optarg,"no")) jl_compileropts.dumpbitcode = JL_COMPILEROPT_DUMPBITCODE_OFF; break; - case 303: - if (!strcmp(optarg,"yes")) - jl_compileropts.compile_enabled = 1; - else if (!strcmp(optarg,"no")) - jl_compileropts.compile_enabled = 0; - else if (!strcmp(optarg,"all")) - jl_compileropts.compile_enabled = 2; - else { - ios_printf(ios_stderr, "julia: invalid argument to --compile (%s)\n", optarg); - exit(1); - } - break; - case 304: + case depwarn: if (!strcmp(optarg,"yes")) jl_compileropts.depwarn = 1; else if (!strcmp(optarg,"no")) jl_compileropts.depwarn = 0; else { - ios_printf(ios_stderr, "julia: invalid argument to --depwarn (%s)\n", optarg); + ios_printf(ios_stderr, "julia: invalid argument to --depwarn={yes|no} (%s)\n", optarg); exit(1); } break; + case 'b': // build + jl_compileropts.build_path = strdup(optarg); + if (!imagepathspecified) + jl_compileropts.image_file = NULL; + break; + case worker: + jl_options.worker = 1; + break; + case bind_to: + jl_options.bindto = strdup(optarg); + break; default: ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c); ios_printf(ios_stderr, "This is a bug, please report it.\n"); @@ -205,7 +327,7 @@ void parse_opts(int *argcp, char ***argvp) } } jl_compileropts.code_coverage = codecov; - jl_compileropts.malloc_log = malloclog; + jl_compileropts.malloc_log = malloclog; optind -= skip; *argvp += optind; *argcp -= optind;