Skip to content

Commit 10bc544

Browse files
committed
Allow passing arguments to compiled scripts
now the installer is not added as a `--compile` step but instead baked into the binary itself
1 parent b4c13bf commit 10bc544

File tree

3 files changed

+35
-46
lines changed

3 files changed

+35
-46
lines changed

build/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The released binaries are special because they need to be portable. We achieve t
4343
1. Get `linuxdeploy-x86_64.AppImage` from https://github.com/linuxdeploy/linuxdeploy/, into this `build` folder
4444
1. Get `linuxdeploy-plugin-gtk.sh` from https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh
4545
1. In that same file, *delete the line* `export GTK_THEME="$APPIMAGE_GTK_THEME" # Custom themes are broken` (this is a temporary fix ([issue](https://github.com/linuxdeploy/linuxdeploy-plugin-gtk/issues/39)))
46-
1. Instead of `shards build`, run `./build.sh --release`. This also does shards build, but also does the AppImage magic and attaches the installer. The `--release` flag results in slower compilation and faster output binary.
46+
1. Instead of `shards build`, run `./build.sh --release`. This also does shards build, but also does the AppImage magic. The `--release` flag results in slower compilation and faster output binary.
4747
1. Find your final binary `ahk_x11-[version]-x86_64.AppImage` in the `build` folder. It's about 30 MiB in size.
4848
4949
There's a script to call `./build.sh`, make a new release and publish it etc., it's `../release.sh`. You most likely can't run it yourself though.

build/build.sh

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version=$(shards version)
77

88
cd ..
99
# Cannot overwrite CRYSTAL_LIBRARY_PATH because crystal#12380, need link-flag instead.
10-
# -no-pie prevents
10+
# -no-pie prevents
1111
shards build -Dpreview_mt --link-flags="-L$PWD/build" \
1212
"$@"
1313
# Flags lik -Dgc_none or --release or --debug should be passed from outside
@@ -25,17 +25,4 @@ rm -rf AppDir
2525
bin_name=ahk_x11-"$version"-x86_64.AppImage
2626
mv ahk_x11-x86_64.AppImage "$bin_name"
2727

28-
# Attaching the installer:
29-
# The installer is not shipped separately and instead bundled with the binary by doing this.
30-
# Bundling is the same thing as compiling a script as a user.
31-
# It is possible to repeatedly compile a binary, with each script being appended at the end each time.
32-
# Only the last one actually executed - and only if no params are passed to the program.
33-
# There's no point in compiling multiple times, but it allows us to ship a default script (the installer)
34-
# for when no arguments are passed.
35-
# In other words, this is possible for a user:
36-
# ahk_x11 --compile script1.ahk && ./script1 --compile script2.ahk && ./script2
37-
# but no one will ever do that.
38-
./"$bin_name" --compile ../src/installer.ahk tmp
39-
mv tmp "$bin_name"
40-
4128
echo "success!"

src/ahk_x11.cr

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,41 @@ end
5858

5959
script_file = nil
6060
version = {{ read_file("./shard.yml").split("\n")[1][9..] }}
61-
if ARGV[0]?
62-
if ARGV[0] == "-v" || ARGV[0] == "--version"
63-
puts "AHK_X11 version: #{version}\nTargets to partially implement Classic Windows AutoHotkey specification: v1.0.24 (2004). AutoHotkey is a scripting language."
64-
::exit
65-
elsif ARGV[0] == "-h" || ARGV[0] == "--help"
66-
puts "AHK_X11 is a Linux implementation for AutoHotkey classic version 1.0.24 (2004). Internal version: #{version}. Full up to date documentation can be found at https://phil294.github.io/AHK_X11/.\n\nPossible methods of invocation:\n\nahk_x11.AppImage \"path to script.ahk\"\nahk_x11.AppImage <<< $'MsgBox, 1\\nMsgBox, 2'\nahk_x11.AppImage --repl\nahk_x11.AppImage --windowspy\nahk_x11.AppImage --compile \"path to script.ahk\" \"optional: output executable file path\"\n\nAlternatively, just run the program without arguments to open the graphical installer. Once installed, you should be able to run and/or compile any .ahk file in your file manager by selecting it from the right click context menu."
67-
::exit
68-
elsif ARGV[0] == "--repl"
69-
lines = ["#Persistent"]
70-
elsif ARGV[0] == "--windowspy"
71-
lines = {{ read_file("./src/window-spy.ahk").split("\n") }}
72-
elsif ARGV[0] == "--compile"
73-
build_error "Syntax: ahk_x11 --compile FILE_NAME [OUTPUT_FILENAME]" if ARGV.size < 2
74-
Compiler.new.compile(filename_to_path(ARGV[1]), ARGV[2]? ? filename_to_path(ARGV[2]) : nil)
75-
::exit
76-
else
77-
script_file = filename_to_path(ARGV[0])
78-
begin
79-
ahk_str = File.read(script_file)
80-
rescue
81-
build_error "File '#{ARGV[0]}' could not be read."
61+
lines = Compiler.new.extract.try &.split('\n')
62+
if ! lines
63+
# Only needed for installer script, this can't (yet) really be part of ahk code. TODO: rm on exit
64+
File.write("/tmp/tmp_ahk_x11_logo.png", logo_blob)
65+
if ARGV[0]?
66+
if ARGV[0] == "-v" || ARGV[0] == "--version"
67+
puts "AHK_X11 version: #{version}\nTargets to partially implement Classic Windows AutoHotkey specification: v1.0.24 (2004). AutoHotkey is a scripting language."
68+
::exit
69+
elsif ARGV[0] == "-h" || ARGV[0] == "--help"
70+
puts "AHK_X11 is a Linux implementation for AutoHotkey classic version 1.0.24 (2004). Internal version: #{version}. Full up to date documentation can be found at https://phil294.github.io/AHK_X11/.\n\nPossible methods of invocation:\n\nahk_x11.AppImage \"path to script.ahk\"\nahk_x11.AppImage <<< $'MsgBox, 1\\nMsgBox, 2'\nahk_x11.AppImage --repl\nahk_x11.AppImage --windowspy\nahk_x11.AppImage --compile \"path to script.ahk\" \"optional: output executable file path\"\n\nAlternatively, just run the program without arguments to open the graphical installer. Once installed, you should be able to run and/or compile any .ahk file in your file manager by selecting it from the right click context menu."
71+
::exit
72+
elsif ARGV[0] == "--repl"
73+
lines = ["#Persistent"]
74+
elsif ARGV[0] == "--windowspy"
75+
lines = {{ read_file("./src/window-spy.ahk").split("\n") }}
76+
elsif ARGV[0] == "--compile"
77+
build_error "Syntax: ahk_x11 --compile FILE_NAME [OUTPUT_FILENAME]" if ARGV.size < 2
78+
Compiler.new.compile(filename_to_path(ARGV[1]), ARGV[2]? ? filename_to_path(ARGV[2]) : nil)
79+
::exit
80+
else
81+
script_file = filename_to_path(ARGV[0])
82+
begin
83+
ahk_str = File.read(script_file)
84+
rescue
85+
build_error "File '#{ARGV[0]}' could not be read."
86+
end
87+
lines = ahk_str.split(/\r?\n/)
8288
end
83-
lines = ahk_str.split(/\r?\n/)
84-
end
85-
else
86-
stdin = Hacks.get_all_stdin_if_available
87-
if stdin
88-
lines = stdin.split('\n')
8989
else
90-
lines = Compiler.new.extract.try &.split('\n')
91-
abort "Argument missing." if ! lines
92-
# Only needed for installer script, this can't (yet) really be part of ahk code. TODO: rm on exit
93-
File.write("/tmp/tmp_ahk_x11_logo.png", logo_blob)
90+
stdin = Hacks.get_all_stdin_if_available
91+
if stdin
92+
lines = stdin.split('\n')
93+
else
94+
lines = {{ read_file("./src/installer.ahk").split("\n") }}
95+
end
9496
end
9597
end
9698

0 commit comments

Comments
 (0)