Skip to content

Commit dc8d67b

Browse files
committed
[GR-24618] Fix and add specs for Truffle::Interop.languages.
PullRequest: truffleruby/1740
2 parents 0b68b83 + 278f643 commit dc8d67b

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fails(GR-24618):Truffle::Interop.other_languages? returns true with --polyglot
2+
slow:Truffle::Interop.languages returns only ruby from the RubyLauncher
3+
slow:Truffle::Interop.other_languages? returns false without --polyglot
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 2.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
require_relative '../../ruby/spec_helper'
10+
11+
describe "Truffle::Interop.languages" do
12+
it "returns the public languages" do
13+
Truffle::Interop.languages.should.include?('ruby')
14+
end
15+
16+
guard_not -> { TruffleRuby.native? and Truffle::Boot.was_preinitialized? } do # GR-24618
17+
it "returns only ruby from the RubyLauncher" do
18+
# Use RbConfig.ruby to remove a potential --polyglot option
19+
`#{RbConfig.ruby} -e 'p Truffle::Interop.languages'`.should == "[\"ruby\"]\n"
20+
end
21+
end
22+
end
23+
24+
describe "Truffle::Interop.other_languages?" do
25+
guard_not -> { TruffleRuby.native? } do
26+
it "returns true with --polyglot" do
27+
ruby_exe('p Truffle::Interop.other_languages?', options: '--polyglot').should == "true\n"
28+
end
29+
end
30+
31+
it "returns false without --polyglot" do
32+
# Use RbConfig.ruby to remove a potential --polyglot option
33+
`#{RbConfig.ruby} -e 'p Truffle::Interop.other_languages?'`.should == "false\n"
34+
end
35+
end

src/main/java/org/truffleruby/RubyContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ private Options createOptions(TruffleLanguage.Env env) {
368368

369369
private static boolean computeHasOtherPublicLanguages(Env env) {
370370
for (String language : env.getPublicLanguages().keySet()) {
371-
if (!language.equals(TruffleRuby.LANGUAGE_ID)) {
371+
if (!language.equals(TruffleRuby.LANGUAGE_ID) && !language.equals("llvm") /* GR-24618 */) {
372372
return true;
373373
}
374374
}

src/main/java/org/truffleruby/interop/InteropNodes.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,17 @@ protected DynamicObject languages() {
10511051
getContext(),
10521052
StringOperations.encodeRope(languagesArray[i], UTF8Encoding.INSTANCE));
10531053
}
1054-
return createArray(languagesArray);
1054+
return createArray(rubyStringArray);
1055+
}
1056+
1057+
}
1058+
1059+
@CoreMethod(names = "other_languages?", onSingleton = true, required = 0)
1060+
public abstract static class HasOtherLanguagesNode extends CoreMethodArrayArgumentsNode {
1061+
1062+
@Specialization
1063+
protected boolean hasOtherlanguages() {
1064+
return getContext().hasOtherPublicLanguages();
10551065
}
10561066

10571067
}

0 commit comments

Comments
 (0)