Skip to content

Commit

Permalink
Interpreter: Apply shell expansion in ldflags (#12094)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwagner authored and Ary Borenszweig committed Jun 29, 2022
1 parent 1b2b80f commit b6e742b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions spec/compiler/data/interpreter/sum.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ long sum_int(int count, ...) {

return total;
}

int simple_sum_int(int a, int b) {
return a + b;
}
22 changes: 22 additions & 0 deletions spec/compiler/interpreter/lib_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion src/compiler/crystal/interpreter/context.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b6e742b

Please sign in to comment.