From e1f3e467eb1ad04986a57e4059b885e4cef220f4 Mon Sep 17 00:00:00 2001 From: xgdgsc Date: Sun, 14 May 2023 23:28:03 +0800 Subject: [PATCH 1/9] add more hint on unknown command (#243) --- src/builder/cli.jl | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/builder/cli.jl b/src/builder/cli.jl index d9999b29..5be321dd 100644 --- a/src/builder/cli.jl +++ b/src/builder/cli.jl @@ -1,4 +1,4 @@ -function print_builder_help(io::IO = stdout) +function print_builder_help(options::Configs.Comonicon, io::IO = stdout) println(io, "Comonicon - Builder CLI.") println(io) print(io, "Builder CLI for Comonicon Applications. If not sepcified, run the command") @@ -12,12 +12,19 @@ function print_builder_help(io::IO = stdout) printstyled(io, " "^4, "install"; color = :light_blue, bold = true) println(io, " "^21, "install the CLI locally.\n") - - printstyled(io, " "^4, "app"; color = :light_blue, bold = true) + if isnothing(options.application) + printstyled(io, " "^4, "app (disabled, add [application] section in Comonicon.toml to enable) "; color = :light_yellow, bold = true) + else + printstyled(io, " "^4, "app"; color = :light_blue, bold = true) + end printstyled(io, " [tarball]"; color = :blue) println(io, " "^15, "build the application, optionally make a tarball.\n") - - printstyled(io, " "^4, "sysimg"; color = :light_blue, bold = true) + + if isnothing(options.sysimg) + printstyled(io, " "^4, "sysimg (disabled, add [sysimg] section in Comonicon.toml to enable) "; color = :light_yellow, bold = true) + else + printstyled(io, " "^4, "sysimg"; color = :light_blue, bold = true) + end printstyled(io, " [tarball]"; color = :blue) println(io, " "^12, "build the system image, optionally make a tarball.\n") @@ -51,7 +58,7 @@ end function command_main(m::Module, options::Configs.Comonicon) if "-h" in ARGS || "--help" in ARGS || "help" in ARGS - print_builder_help() + print_builder_help(options) return 0 elseif isempty(ARGS) || (first(ARGS) == "install" && length(ARGS) == 1) if options.install.quiet @@ -91,6 +98,6 @@ function command_main(m::Module, options::Configs.Comonicon) printstyled(join(ARGS, " "); color = :red) println() println() - print_builder_help() + print_builder_help(options) return 1 end From bf97cc0f61efe871e8599bf77b85fe39b9f74741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B9=E3=83=8E=E3=83=AB?= Date: Tue, 23 May 2023 10:36:30 -0400 Subject: [PATCH 2/9] Update printing.jl (#244) --- src/ast/printing.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ast/printing.jl b/src/ast/printing.jl index 5d58abe9..e1422f18 100644 --- a/src/ast/printing.jl +++ b/src/ast/printing.jl @@ -167,7 +167,7 @@ function print_head(io::IO, cmd::LeafCommand, t::Terminal) printstyled(io, tab(1), ""; color = t.color.args) end - isempty(cmd.args) || printstyled(io, tab(1), "[options]"; color = t.color.dash) + isempty(cmd.options) || printstyled(io, tab(1), "[options]"; color = t.color.dash) isempty(cmd.flags) || printstyled(io, tab(1), "[flags]"; color = t.color.dash) return end From 73774f4f5cc9ef205912580fb7e4d45f336564f7 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Thu, 25 May 2023 13:15:36 +0800 Subject: [PATCH 3/9] generate batch script entryfile for windows (#241) --- .github/workflows/CI.yml | 13 +++++++++++ src/builder/install.jl | 41 +++++++++++++++++++++++++++++++++++ test/builder/install.jl | 42 ++++++++++++++++++++++++------------ test/codegen/julia/plugin.jl | 10 ++++++--- 4 files changed, 89 insertions(+), 17 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 72e6be2a..b96837dd 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -22,6 +22,19 @@ jobs: - 'Comonicon' - 'lib' - 'example' + include: + - os: windows-latest + version: '1' + arch: x64 + package: 'Comonicon' + - os: windows-latest + version: '1' + arch: x64 + package: 'lib' + # - os: windows-latest + # version: '1' + # arch: x64 + # package: 'example' steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 diff --git a/src/builder/install.jl b/src/builder/install.jl index a4437e24..f5a9dc45 100644 --- a/src/builder/install.jl +++ b/src/builder/install.jl @@ -32,6 +32,9 @@ function install_entryfile(m::Module, options::Configs.Comonicon) bin = install_path(options, "bin") # generate entry file at .juila/bin entryfile = joinpath(bin, options.name) + if Sys.iswindows() + entryfile = entryfile * ".cmd" + end open(entryfile, "w+") do io print(io, entryfile_script(m, options)) end @@ -94,6 +97,14 @@ function completion_script(m::Module, options::Configs.Comonicon, shell::String) end function entryfile_script(m::Module, options::Configs.Comonicon) + if Sys.iswindows() + return _entryfile_script_bat(m, options) + else + return _entryfile_script_bash(m, options) + end +end + +function _entryfile_script_bash(m::Module, options::Configs.Comonicon) cmds = String[] julia_exe = joinpath(Sys.BINDIR, Base.julia_exename()) @@ -126,6 +137,36 @@ function entryfile_script(m::Module, options::Configs.Comonicon) """ end +function _entryfile_script_bat(m::Module, options::Configs.Comonicon) + cmds = String[] + + julia_exe = joinpath(Sys.BINDIR, Base.julia_exename()) + push!(cmds, julia_exe) + if !isnothing(options.sysimg) + dylib = sysimg_dylib(m, options) + push!(cmds, "--sysimage=" * dylib) + end + + if options.install.nthreads > 1 || options.install.nthreads == "auto" + push!(cmds, string("--threads=", options.install.nthreads)) + end + + push!(cmds, "--startup-file=no") + push!(cmds, "--color=yes") + push!(cmds, string("--compile=", options.install.compile)) + push!(cmds, string("--optimize=", options.install.optimize)) + push!(cmds, "-e \"using $m; exit($(nameof(m)).command_main())\" %*") + + return """ + @echo off + :: generated by Comonicon for the CLI Application $(options.name) + setlocal + set JULIA_PROJECT=$(get_scratch!(m, "env")) + $(join(cmds, " ^\n ")) + endlocal + """ +end + function ensure_path(path::String) if !ispath(path) @info "creating $path" diff --git a/test/builder/install.jl b/test/builder/install.jl index b9cbf214..bf59f793 100644 --- a/test/builder/install.jl +++ b/test/builder/install.jl @@ -26,20 +26,34 @@ end @testset "entryfile_script" begin options = Configs.Comonicon(name = "test") script = entryfile_script(TestInstall, options) - - @test occursin("#!/usr/bin/env bash", script) - @test occursin("JULIA_PROJECT=$(get_scratch!(TestInstall, "env"))", script) - julia_exe = joinpath(Sys.BINDIR, Base.julia_exename()) - @test occursin("exec $julia_exe \\\n", script) - @test occursin("--startup-file=no \\\n", script) - @test occursin("--color=yes \\\n", script) - @test occursin("--compile=yes \\\n", script) - @test occursin("--optimize=2 \\\n", script) - @test occursin("-- \"\${BASH_SOURCE[0]}\"", script) - @test occursin( - "using Main.TestBuilderInstall.TestInstall\nexit(TestInstall.command_main())", - script, - ) + if Sys.iswindows() + @test occursin("@echo off", script) + @test occursin("set JULIA_PROJECT=$(get_scratch!(TestInstall, "env"))", script) + julia_exe = joinpath(Sys.BINDIR, Base.julia_exename()) + @test occursin("$julia_exe ^\n", script) + @test occursin("--startup-file=no ^\n", script) + @test occursin("--color=yes ^\n", script) + @test occursin("--compile=yes ^\n", script) + @test occursin("--optimize=2 ^\n", script) + @test occursin( + "using Main.TestBuilderInstall.TestInstall; exit(TestInstall.command_main())", + script, + ) + else + @test occursin("#!/usr/bin/env bash", script) + @test occursin("JULIA_PROJECT=$(get_scratch!(TestInstall, "env"))", script) + julia_exe = joinpath(Sys.BINDIR, Base.julia_exename()) + @test occursin("exec $julia_exe \\\n", script) + @test occursin("--startup-file=no \\\n", script) + @test occursin("--color=yes \\\n", script) + @test occursin("--compile=yes \\\n", script) + @test occursin("--optimize=2 \\\n", script) + @test occursin("-- \"\${BASH_SOURCE[0]}\"", script) + @test occursin( + "using Main.TestBuilderInstall.TestInstall\nexit(TestInstall.command_main())", + script, + ) + end end @testset "test completion script" begin diff --git a/test/codegen/julia/plugin.jl b/test/codegen/julia/plugin.jl index d17b9f28..c380dc5d 100644 --- a/test/codegen/julia/plugin.jl +++ b/test/codegen/julia/plugin.jl @@ -26,7 +26,11 @@ end using Test using Comonicon -withenv("PATH" => "$(pkgdir(Comonicon, "test", "codegen", "julia")):$(ENV["PATH"])") do - Sys.which("node-cmd3") - @test TestPlugin.command_main(["cmd3"]) == 0 +if Sys.iswindows() + @test_broken false +else + withenv("PATH" => "$(pkgdir(Comonicon, "test", "codegen", "julia")):$(ENV["PATH"])") do + Sys.which("node-cmd3") + @test TestPlugin.command_main(["cmd3"]) == 0 + end end From 2589f7d6460e84c8724165e4e9ee90553c90006f Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Mon, 17 Jul 2023 05:56:06 +0800 Subject: [PATCH 4/9] bugfix(windows): handle cmd call error (#245) * windows: handle cmd call error The current batch script provided by #241 unconditionally returns 0 because there is an `endlocal` line at the end. This patch fixes it by checking julia exit code and handles it. * use oneliner version --- src/builder/install.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/builder/install.jl b/src/builder/install.jl index f5a9dc45..08ea5456 100644 --- a/src/builder/install.jl +++ b/src/builder/install.jl @@ -163,6 +163,7 @@ function _entryfile_script_bat(m::Module, options::Configs.Comonicon) setlocal set JULIA_PROJECT=$(get_scratch!(m, "env")) $(join(cmds, " ^\n ")) + if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL% endlocal """ end From f1e069cb4bb7e457c867fd6067ce05d6c7ff5963 Mon Sep 17 00:00:00 2001 From: Kai Xu <5985769+xukai92@users.noreply.github.com> Date: Sun, 3 Sep 2023 19:01:50 -0400 Subject: [PATCH 5/9] fix: brief appended to intro by mistake (#250) Co-authored-by: Kai Xu --- src/ast/printing.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ast/printing.jl b/src/ast/printing.jl index e1422f18..eecc880a 100644 --- a/src/ast/printing.jl +++ b/src/ast/printing.jl @@ -118,10 +118,9 @@ function _print_dash(io::IO, cmd::Union{Option,Flag}, t::Terminal) end function print_content(io::IO, desc::Description, t::Terminal) - isnothing(desc.content) || print_within(io, desc.content, t.width, 0) + isnothing(desc.content) || (print_within(io, desc.content, t.width, 0); return) # if Intro section is empty, use brief description isnothing(desc.brief) || print_within(io, desc.brief, t.width, 0) - return end function print_cmd(io::IO, cmd::Entry, t::Terminal) From f3c8d17e119994df49cfa3973c3eec58f33c1572 Mon Sep 17 00:00:00 2001 From: Kai Xu <5985769+xukai92@users.noreply.github.com> Date: Mon, 4 Sep 2023 22:47:13 -0400 Subject: [PATCH 6/9] test: update test for #244 (#253) Co-authored-by: Kai Xu --- test/ast/ast.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ast/ast.jl b/test/ast/ast.jl index 53c01011..86be4361 100644 --- a/test/ast/ast.jl +++ b/test/ast/ast.jl @@ -42,7 +42,7 @@ leaf = LeafCommand(; ) @test_show MIME"text/plain" begin - " leaf [options] [flags]" in leaf + " leaf [flags]" in leaf "Args\n\n" in leaf " " in leaf "Flags\n\n" in leaf From b3184b8add92cc834a7b46b7dfa817791f578ccd Mon Sep 17 00:00:00 2001 From: Kai Xu <5985769+xukai92@users.noreply.github.com> Date: Mon, 4 Sep 2023 22:48:12 -0400 Subject: [PATCH 7/9] fix: empty user defined hint is used (#251) * fix: empty user defined hint is used * test: add test case for missing user-defined hint --------- Co-authored-by: Kai Xu --- src/frontend/cast.jl | 3 ++- test/frontend/cast.jl | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/frontend/cast.jl b/src/frontend/cast.jl index c4ee9e54..b51307a4 100644 --- a/src/frontend/cast.jl +++ b/src/frontend/cast.jl @@ -646,7 +646,8 @@ function cast_options(doc::JLMD, options::Vector{JLOption}, line) opt = Option(; sym = each.name, name = name, - hint = option.hint, # use user defined hint + hint = isnothing(option.hint) ? each.hint : # fallback to default hint + option.hint, # use user defined hint if provided require = each.require, type = each.type, short = option.short, diff --git a/test/frontend/cast.jl b/test/frontend/cast.jl index 77cc5eb3..bb59f843 100644 --- a/test/frontend/cast.jl +++ b/test/frontend/cast.jl @@ -56,6 +56,7 @@ a test function. - `--option1, -o`: test option. - `--option2 `: test option. - `--option3=`: test option. +- `--option4`: test option. # Flags - `--flag1, -f`: test flag. @@ -68,6 +69,7 @@ function foo( option1 = nothing, option2::Int = 1, option3::String = "abc", + option4::Int = 1, flag1::Bool = false, flag2::Bool = false, ) end @@ -97,6 +99,9 @@ function foo( @test cmd.description == Description("a test function.") @test cmd.line == LineNumberNode(0) + # for PR #251: the default hint should be used in the absence of the user-defined one + @test cmd.options["option4"].hint == "1::Int" + @show cmd.options @test all(keys(cmd.options) .== ["option1", "o", "option2", "option3"]) From ffa0e787c9a56c4f3a481232db32e8d692f4be14 Mon Sep 17 00:00:00 2001 From: Kai Xu <5985769+xukai92@users.noreply.github.com> Date: Tue, 5 Sep 2023 10:20:40 -0400 Subject: [PATCH 8/9] test: fix tests for #251 (#255) Co-authored-by: Kai Xu --- test/frontend/cast.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/frontend/cast.jl b/test/frontend/cast.jl index bb59f843..93eda956 100644 --- a/test/frontend/cast.jl +++ b/test/frontend/cast.jl @@ -38,6 +38,7 @@ options = [ JLOption(:option1, false, Any, "nothing"), JLOption(:option2, false, Int, "1::Int"), JLOption(:option3, false, String, "abc::String"), + JLOption(:option4, false, Int, "1::Int"), ] """ @@ -91,7 +92,7 @@ function foo( @test cmd.options["option1"].name == "option1" @test cmd.options["option2"].name == "option2" @test cmd.options["o"].short == true - @test cmd.options["o"].hint === nothing + @test cmd.options["o"].hint === "nothing" @test cmd.options["option2"].short == false @test cmd.options["option2"].hint == "int" @@ -103,7 +104,7 @@ function foo( @test cmd.options["option4"].hint == "1::Int" @show cmd.options - @test all(keys(cmd.options) .== ["option1", "o", "option2", "option3"]) + @test all(keys(cmd.options) .== ["option1", "o", "option2", "option3", "option4"]) @show cmd.flags @test all(keys(cmd.flags) .== ["flag1", "f", "flag2"]) @@ -119,6 +120,7 @@ end option1 = nothing, option2::Int = 1, option3::String = "abc", + option4::Int = 1, flag1::Bool = false, flag2::Bool = false, ) end From bf94cdb7a730c40a596232f6fa9d138813f4c2d5 Mon Sep 17 00:00:00 2001 From: Roger-luo Date: Tue, 5 Sep 2023 10:21:26 -0400 Subject: [PATCH 9/9] Bump version to 1.0.6 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 45acf508..1a8cb2a9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Comonicon" uuid = "863f3e99-da2a-4334-8734-de3dacbe5542" authors = ["Roger-luo and contributors"] -version = "1.0.5" +version = "1.0.6" [deps] Configurations = "5218b696-f38b-4ac9-8b61-a12ec717816d"