diff --git a/spec/compiler/data/interpreter/sum.c b/spec/compiler/data/interpreter/sum.c index 299304dd34b4..5043ce91c735 100644 --- a/spec/compiler/data/interpreter/sum.c +++ b/spec/compiler/data/interpreter/sum.c @@ -25,3 +25,7 @@ long sum_int(int count, ...) { return total; } + +int simple_sum_int(int a, int b) { + return a + b; +} diff --git a/spec/compiler/interpreter/lib_spec.cr b/spec/compiler/interpreter/lib_spec.cr index ef4a51a915b3..7b99c1555e99 100644 --- a/spec/compiler/interpreter/lib_spec.cr +++ b/spec/compiler/interpreter/lib_spec.cr @@ -54,4 +54,26 @@ describe Crystal::Repl::Interpreter do FileUtils.rm_rf(SPEC_CRYSTAL_LOADER_LIB_PATH) end end + + context "command expansion" do + before_all do + FileUtils.mkdir_p(SPEC_CRYSTAL_LOADER_LIB_PATH) + build_c_dynlib(compiler_datapath("interpreter", "sum.c")) + end + + it "expands ldflags" do + interpret(<<-CR).should eq 4 + @[Link(ldflags: "-L#{SPEC_CRYSTAL_LOADER_LIB_PATH} -l`echo sum`")] + lib LibSum + fun simple_sum_int(a : Int32, b : Int32) : Int32 + end + + LibSum.simple_sum_int(2, 2) + CR + end + + after_all do + FileUtils.rm_rf(SPEC_CRYSTAL_LOADER_LIB_PATH) + end + end end diff --git a/src/compiler/crystal/interpreter/context.cr b/src/compiler/crystal/interpreter/context.cr index c0ad99160c1a..b89c2bfe1286 100644 --- a/src/compiler/crystal/interpreter/context.cr +++ b/src/compiler/crystal/interpreter/context.cr @@ -357,7 +357,11 @@ class Crystal::Repl::Context end getter(loader : Loader) { - args = Process.parse_arguments(program.lib_flags) + lib_flags = program.lib_flags + # Execute and expand `subcommands`. + lib_flags = lib_flags.gsub(/`(.*?)`/) { `#{$1}` } + + args = Process.parse_arguments(lib_flags) # FIXME: Part 1: This is a workaround for initial integration of the interpreter: # The loader can't handle the static libgc.a usually shipped with crystal and loading as a shared library conflicts # with the compiler's own GC.