From ed3c06f188656ef5d51053a7ba468562c4e4c6ca Mon Sep 17 00:00:00 2001 From: Roger-luo Date: Sat, 19 Sep 2020 04:40:54 -0400 Subject: [PATCH 1/6] update ignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c275caca..1de7561d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ Manifest.toml /test/bin/ /test/completions/ /test/Foo/deps/ -/test/Foo/Manifest.toml \ No newline at end of file +/test/Foo/Manifest.toml +!/test/Foo/deps/precompile.jl From d0eb4415aad9747f12f752e476f284bc76245da1 Mon Sep 17 00:00:00 2001 From: Roger-luo Date: Sat, 19 Sep 2020 04:41:04 -0400 Subject: [PATCH 2/6] fix README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 153fe260..3f5a8536 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Roger's magic book for command line interfaces.

Comonicon is a   - + Julia Language   package. To install Comonicon, From 7e69cafbe0cd204426f41fbbeedbe50a53f7a6b2 Mon Sep 17 00:00:00 2001 From: Roger-luo Date: Sat, 19 Sep 2020 04:41:24 -0400 Subject: [PATCH 3/6] allow self defined precompile --- src/tools/build.jl | 62 ++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/src/tools/build.jl b/src/tools/build.jl index 8371c1d5..d36d0a87 100644 --- a/src/tools/build.jl +++ b/src/tools/build.jl @@ -30,6 +30,10 @@ const COMONICON_URL = "https://github.com/Roger-luo/Comonicon.jl" # filter_stdlibs=true # cpu_target="native" +# [sysimg.precompile] +# execution_file = ["deps/precopmile.jl"] +# statements_file = ["deps/statements.jl"] + # [download] # host="github.com" # user="Roger-luo" @@ -47,6 +51,10 @@ const DEFAULT_SYSIMG_CONFIG = Dict( "incremental" => true, "filter_stdlibs" => false, "cpu_target" => "native", + "precompile" => Dict{String, Vector{String}}( + "statements_file" => String[], + "execution_file" => String[], + ) ) const COMONICON_TOML = ["Comonicon.toml", "JuliaComonicon.toml"] @@ -86,9 +94,19 @@ function read_configs(mod; kwargs...) install_configs[string(k)] = v end - if k in [:path, :incremental, :filter_stdlibs, :cpu_target] + if k in [ + :path, :incremental, :filter_stdlibs, :cpu_target, :precompile, + # NOTE: we handle these two kwargs in a more flatten way + :precompile_execution_file, :precompile_statements_file + ] sysimg_configs = get!(configs, "sysimg", Dict{String,Any}()) - sysimg_configs[string(k)] = v + + if k in [:precompile_execution_file, :precompile_statements_file] + precompile_configs = get!(sysimg_configs, "precompile", Dict{String, Vector{String}}()) + precompile_configs[string(k)[12:end]] = v + else + sysimg_configs[string(k)] = v + end end if k in [:host, :repo, :user] @@ -331,13 +349,6 @@ function build_sysimg(mod::Module, configs::Dict) mkpath(lib_path) end - # install precompile script - precompile_jl = PATH.project(mod, "deps", "precompile.jl") - @info "generating precompile execution file: $precompile_jl" - open(precompile_jl, "w+") do f - print(f, precompile_script(mod)) - end - project = PATH.project(mod) incremental = sysimg_configs["incremental"] filter_stdlibs = sysimg_configs["filter_stdlibs"] @@ -354,7 +365,8 @@ function build_sysimg(mod::Module, configs::Dict) sysimage_path = image_path, incremental = incremental, project = project, - precompile_execution_file = [precompile_jl, PATH.project(mod, "test", "runtests.jl")], + precompile_statements_file = sysimg_configs["precompile"]["statements_file"], + precompile_execution_file = sysimg_configs["precompile"]["execution_file"], cpu_target = cpu_target, filter_stdlibs = filter_stdlibs, ) @@ -446,36 +458,6 @@ function cmd_script( return join(script, " \\\n ") end -""" - precompile_script(mod) - -Generates a script to execute as `precompile_execution_file` for all the commands. -""" -function precompile_script(mod::Module) - script = "using $mod;\n$mod.command_main([\"-h\"]);\n" - - if isdefined(mod, :CASTED_COMMANDS) - for (name, cmd) in mod.CASTED_COMMANDS - if name != "main" # skip main command - script *= "$mod.command_main([$(precompile_script(mod, cmd))]);\n" - end - end - end - return script -end - -function precompile_script(mod::Module, cmd::EntryCommand) - return precompile_script(mod, cmd.root) -end - -function precompile_script(mod::Module, cmd::LeafCommand) - return "\"$(cmd_name(cmd))\", \"-h\"" -end - -function precompile_script(mod::Module, cmd::NodeCommand) - return join(map(x -> "\"$(cmd_name(cmd))\", " * precompile_script(mod, x), cmd.subcmds)) -end - Base.write(x::EntryCommand) = write(cachefile(), x) """ From dffbe92ee9832080e2a1acce25ac495232728a4a Mon Sep 17 00:00:00 2001 From: Roger-luo Date: Sat, 19 Sep 2020 04:41:39 -0400 Subject: [PATCH 4/6] update test case toml --- test/Foo/Comonicon.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/Foo/Comonicon.toml b/test/Foo/Comonicon.toml index 2a22fcd4..cf69087d 100644 --- a/test/Foo/Comonicon.toml +++ b/test/Foo/Comonicon.toml @@ -12,6 +12,9 @@ incremental=true filter_stdlibs=false cpu_target="native" +[sysimg.precompile] +execution_file = ["deps/precopmile.jl"] + [download] host="github.com" user="Roger-luo" From 4aa764e7eeb495e1ec51f10037ee78a629934c50 Mon Sep 17 00:00:00 2001 From: Roger-luo Date: Sat, 19 Sep 2020 04:41:54 -0400 Subject: [PATCH 5/6] update test --- test/build.jl | 3 +++ test/parse.jl | 11 +---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/test/build.jl b/test/build.jl index bc0e5ebd..3a9b7623 100644 --- a/test/build.jl +++ b/test/build.jl @@ -52,6 +52,9 @@ d = Dict( "cpu_target" => "native", "incremental" => true, "path" => "deps/lib", + "precompile" => Dict( + "execution_file" => ["deps/precopmile.jl"], + ) ), ) diff --git a/test/parse.jl b/test/parse.jl index 5484e5ec..b7a2e03b 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -2,7 +2,7 @@ using Comonicon using Markdown using Comonicon.Types using Comonicon.Parse -using Comonicon.BuildTools: precompile_script, install +using Comonicon.BuildTools: install using Test module Dummy @@ -111,15 +111,6 @@ end @test Dummy.command_main(String["tick", "1.0", "2.0"]) == 0 @test Dummy.command_main(String["tick", "1.0"]) == 0 - -@test precompile_script(Dummy) == """ -using Main.Dummy; -Main.Dummy.command_main(["-h"]); -Main.Dummy.command_main(["goo", "-h"]); -Main.Dummy.command_main(["tick", "-h"]); -Main.Dummy.command_main(["foo", "-h"]); -""" - empty!(ARGS) append!(ARGS, ["2", "--opt1", "3"]) From 22862f45fabe6930565e5e791d8cdee2901aa860 Mon Sep 17 00:00:00 2001 From: Roger-luo Date: Sat, 19 Sep 2020 04:46:01 -0400 Subject: [PATCH 6/6] fix default value --- src/tools/build.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tools/build.jl b/src/tools/build.jl index d36d0a87..23ce42af 100644 --- a/src/tools/build.jl +++ b/src/tools/build.jl @@ -135,6 +135,11 @@ end function merge_defaults(mod, configs) if haskey(configs, "sysimg") configs["sysimg"] = merge(DEFAULT_SYSIMG_CONFIG, configs["sysimg"]) + + if haskey(configs["sysimg"], "precompile") + pr_cfg = configs["sysimg"]["precompile"] + configs["sysimg"]["precompile"] = merge(DEFAULT_SYSIMG_CONFIG["precompile"], pr_cfg) + end end configs["install"] = merge(DEFAULT_INSTALL_CONFIG, configs["install"])