Skip to content

Commit 83abd2e

Browse files
committed
[GR-19220] Include the major kernel version in RUBY_PLATFORM on macOS like MRI (#1860).
PullRequest: truffleruby/1211
2 parents 7b0b725 + 11f0e7e commit 83abd2e

File tree

8 files changed

+81
-2
lines changed

8 files changed

+81
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Compatibility:
7070
* Implemented `Comparable#clamp` (#1517).
7171
* Implemented `rb_gc_register_mark_object` and `rb_enc_str_asciionly_p` (#1856, @chrisseaton).
7272
* Implemented `rb_io_set_nonblock` (#1741).
73+
* Include the major kernel version in `RUBY_PLATFORM` on macOS like MRI (#1860, @eightbitraptor).
7374

7475
Performance:
7576

mx.truffleruby/suite.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"dir": "src/annotations",
122122
"sourceDirs": ["java"],
123123
"javaCompliance": "8+",
124+
"checkstyle": "org.truffleruby",
124125
"workingSets": "TruffleRuby",
125126
"checkPackagePrefix": "false",
126127
"license": ["EPL-2.0"],
@@ -137,6 +138,7 @@
137138
"TRUFFLERUBY-PROCESSOR",
138139
],
139140
"javaCompliance": "8+",
141+
"checkstyle": "org.truffleruby",
140142
"workingSets": "TruffleRuby",
141143
"checkPackagePrefix": "false",
142144
"license": ["EPL-2.0"],
@@ -150,6 +152,7 @@
150152
"truffle:TRUFFLE_API",
151153
],
152154
"javaCompliance": "8+",
155+
"checkstyle": "org.truffleruby",
153156
"workingSets": "TruffleRuby",
154157
"checkPackagePrefix": "false",
155158
"license": ["EPL-2.0"],
@@ -162,6 +165,7 @@
162165
"sdk:GRAAL_SDK",
163166
],
164167
"javaCompliance": "8+",
168+
"checkstyle": "org.truffleruby",
165169
"workingSets": "TruffleRuby",
166170
"checkPackagePrefix": "false",
167171
"license": ["EPL-2.0"],
@@ -224,6 +228,7 @@
224228
"sdk:LAUNCHER_COMMON",
225229
],
226230
"javaCompliance": "8+",
231+
"checkstyle": "org.truffleruby",
227232
"workingSets": "TruffleRuby",
228233
"checkPackagePrefix": "false",
229234
"license": ["EPL-2.0"],
@@ -238,6 +243,7 @@
238243
"mx:JUNIT",
239244
],
240245
"javaCompliance": "8+",
246+
"checkstyle": "org.truffleruby",
241247
"checkPackagePrefix": "false",
242248
"license": ["EPL-2.0"],
243249
},
@@ -248,6 +254,7 @@
248254
"sourceDirs": ["java", "ruby"],
249255
"dependencies": ["truffle:TRUFFLE_TCK"],
250256
"javaCompliance": "8+",
257+
"checkstyle": "org.truffleruby",
251258
"license": ["EPL-2.0"],
252259
},
253260

spec/ruby/core/builtin_constants/builtin_constants_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
it "is a String" do
3535
RUBY_PLATFORM.should be_kind_of(String)
3636
end
37+
38+
platform_is :darwin do
39+
it 'contains the current kernel major version' do
40+
kernel_version = `uname -r`
41+
RUBY_PLATFORM.should =~ /#{kernel_version.split('.').first}/
42+
end
43+
end
3744
end
3845

3946
describe "RUBY_RELEASE_DATE" do

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@
6464
})
6565
public class RubyLanguage extends TruffleLanguage<RubyContext> {
6666

67-
public static final String PLATFORM = String.format("%s-%s", Platform.getArchitecture(), Platform.getOSName());
67+
public static final String PLATFORM = String.format(
68+
"%s-%s%s",
69+
Platform.getArchitecture(),
70+
Platform.getOSName(),
71+
Platform.getKernelMajorVersion());
6872

6973
public static final String LLVM_BITCODE_MIME_TYPE = "application/x-llvm-ir-bitcode";
7074

src/processor/java/org/truffleruby/processor/BuildInformationProcessor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class BuildInformationProcessor extends AbstractProcessor {
5050
private int rubyRevision;
5151
private String revision;
5252
private String compileDate;
53+
private String kernelMajorVersion;
5354

5455
@Override
5556
public synchronized void init(ProcessingEnvironment env) {
@@ -61,11 +62,17 @@ public synchronized void init(ProcessingEnvironment env) {
6162
rubyRevision = Integer.parseInt(runCommand("tool/query-versions-json.rb ruby.revision"));
6263
revision = runCommand("git rev-parse --short=8 HEAD");
6364
compileDate = runCommand("git log -1 --date=short --pretty=format:%cd");
65+
kernelMajorVersion = findKernelMajorVersion();
6466
} catch (Throwable e) {
6567
throw new Error(e);
6668
}
6769
}
6870

71+
private String findKernelMajorVersion() throws IOException, InterruptedException {
72+
final String kernelVersion = runCommand("uname -r");
73+
return kernelVersion.split(Pattern.quote("."))[0];
74+
}
75+
6976
private File findHome() throws URISyntaxException {
7077
final CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
7178
final File jarOrClassPath;
@@ -159,7 +166,7 @@ private void processBuildInformation(TypeElement element) throws Exception {
159166
stream.println("package " + packageName + ";");
160167
stream.println();
161168
stream.println("// GENERATED BY " + getClass().getName());
162-
stream.println("// This file is automatically generated from versions.json");
169+
stream.println("// This file is automatically generated from versions.json and other sources");
163170
stream.println();
164171
stream.println(
165172
"public class " + element.getSimpleName() + SUFFIX + " implements " + element.getSimpleName() +
@@ -199,6 +206,9 @@ private void processBuildInformation(TypeElement element) throws Exception {
199206
case "getCompileDate":
200207
value = compileDate;
201208
break;
209+
case "getKernelMajorVersion":
210+
value = kernelMajorVersion;
211+
break;
202212
default:
203213
throw new UnsupportedOperationException(name + " method not understood");
204214
}

src/shared/java/org/truffleruby/shared/BasicPlatform.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,12 @@ public static String getArchitecture() {
9595

9696
return architecture;
9797
}
98+
99+
public static String getKernelMajorVersion() {
100+
if (OS == OS_TYPE.DARWIN) {
101+
return BuildInformationImpl.INSTANCE.getKernelMajorVersion();
102+
} else {
103+
return "";
104+
}
105+
}
98106
}

src/shared/java/org/truffleruby/shared/BuildInformation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ public interface BuildInformation {
2424

2525
String getCompileDate();
2626

27+
String getKernelMajorVersion();
28+
2729
}

tool/jt.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,11 @@ def bootstrap_toolchain
18751875
raise 'use --env jvm-ce instead' if options.delete('--graal')
18761876
raise 'use --env native instead' if options.delete('--native')
18771877

1878+
if os_version_changed?
1879+
warn "Kernel version changed since last build: #{build_kernel_ver.inspect} -> #{host_kernel_ver.inspect}"
1880+
remove_shared_compile_artifacts
1881+
end
1882+
18781883
env = if (i = options.index('--env') || options.index('-e'))
18791884
options.delete_at i
18801885
options.delete_at i
@@ -1905,6 +1910,7 @@ def bootstrap_toolchain
19051910
mx_args = ['-p', TRUFFLERUBY_DIR, '--env', env, *mx_options]
19061911

19071912
env = ENV['JT_CACHE_TOOLCHAIN'] ? { 'SULONG_BOOTSTRAP_GRAALVM' => bootstrap_toolchain } : {}
1913+
19081914
mx(env, *mx_args, 'build', *mx_build_options)
19091915
build_dir = mx(*mx_args, 'graalvm-home', capture: true).lines.last.chomp
19101916

@@ -1945,6 +1951,40 @@ def bootstrap_toolchain
19451951
end
19461952
end
19471953

1954+
def remove_shared_compile_artifacts
1955+
if build_information_path.file?
1956+
warn "Deleting shared build artifacts to trigger rebuild: #{shared_path}"
1957+
shared_path.rmtree
1958+
end
1959+
end
1960+
1961+
def os_version_changed?
1962+
build_kernel_ver != host_kernel_ver
1963+
end
1964+
1965+
def host_kernel_ver
1966+
`uname -r`[/^\d+/]
1967+
end
1968+
1969+
def build_kernel_ver
1970+
return '' unless build_information_path.file?
1971+
1972+
build_information = build_information_path.readlines
1973+
build_os_ver_loc = build_information.index { |l| l.include?('getKernelMajorVersion') }
1974+
return '' unless build_os_ver_loc
1975+
1976+
build_information[build_os_ver_loc + 1][/^\d+/]
1977+
end
1978+
1979+
def shared_path
1980+
Pathname.new("#{TRUFFLERUBY_DIR}/mxbuild/org.truffleruby.shared")
1981+
end
1982+
1983+
def build_information_path
1984+
shared_path
1985+
.join('src_gen/org/truffleruby/shared/BuildInformationImpl.java')
1986+
end
1987+
19481988
def next(*args)
19491989
puts `cat spec/tags/core/**/**.txt | grep 'fails:'`.lines.sample
19501990
end

0 commit comments

Comments
 (0)