Skip to content

Commit

Permalink
[GR-17457] Fail early if truffleruby jars are run on Windows
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/3975
(cherry picked from commit 26231c4)
  • Loading branch information
eregon committed Sep 5, 2023
1 parent 52dede9 commit eed858a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
24 changes: 8 additions & 16 deletions src/main/java/org/truffleruby/core/support/IONodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
import org.truffleruby.language.control.RaiseException;
import org.truffleruby.language.library.RubyStringLibrary;
import org.truffleruby.language.objects.AllocationTracing;
import org.truffleruby.platform.Platform;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
Expand Down Expand Up @@ -153,9 +152,6 @@ boolean fnmatch(Object pattern, Object path, int flags,
flags) != FNM_NOMATCH;
}


private static final boolean DOSISH = Platform.IS_WINDOWS;

private static final int FNM_NOESCAPE = 0x01;
private static final int FNM_PATHNAME = 0x02;
private static final int FNM_DOTMATCH = 0x04;
Expand All @@ -164,7 +160,7 @@ boolean fnmatch(Object pattern, Object path, int flags,
public static final int FNM_NOMATCH = 1;

private static boolean isdirsep(char c) {
return c == '/' || DOSISH && c == '\\';
return c == '/';
}

private static boolean isdirsep(byte c) {
Expand Down Expand Up @@ -259,19 +255,15 @@ private static int fnmatch_helper(byte[] bytes, int pstart, int pend, byte[] str
if (s >= send) {
return FNM_NOMATCH;
}
if (DOSISH && (pathname && isdirsep(c) && isdirsep(string[s]))) {
} else {
if (nocase) {
if (Character.toLowerCase(c) != Character.toLowerCase((char) string[s])) {
return FNM_NOMATCH;
}

} else {
if (c != (char) (string[s] & 0xFF)) {
return FNM_NOMATCH;
}
if (nocase) {
if (Character.toLowerCase(c) != Character.toLowerCase((char) string[s])) {
return FNM_NOMATCH;
}

} else {
if (c != (char) (string[s] & 0xFF)) {
return FNM_NOMATCH;
}
}
s++;
break;
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/truffleruby/platform/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ public abstract class Platform extends BasicPlatform {
public static final String LIB_SUFFIX = determineLibSuffix();
public static final String CEXT_SUFFIX = OS == OS_TYPE.DARWIN ? ".bundle" : LIB_SUFFIX;

public static final boolean IS_WINDOWS = OS == OS_TYPE.WINDOWS;

private static String determineLibSuffix() {
switch (OS) {
case WINDOWS:
return ".dll";
case DARWIN:
return ".dylib";
default:
Expand Down
16 changes: 4 additions & 12 deletions src/shared/java/org/truffleruby/shared/BasicPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public abstract class BasicPlatform {

public enum OS_TYPE {
LINUX("linux"),
DARWIN("darwin"),
SOLARIS("solaris"),
WINDOWS("mswin32");
DARWIN("darwin");

private final String rubyName;

Expand All @@ -54,8 +52,7 @@ public enum OS_TYPE {

public enum ARCH {
AMD64("x86_64"),
AARCH64("aarch64"),
UNKNOWN("unknown");
AARCH64("aarch64");

private final String rubyName;

Expand All @@ -79,14 +76,9 @@ public static OS_TYPE determineOS() {
final String osName = System.getProperty("os.name");

final String lowerOSName = osName.toLowerCase(Locale.ENGLISH);
if (lowerOSName.contains("windows")) {
return OS_TYPE.WINDOWS;
}

if (lowerOSName.startsWith("mac") || lowerOSName.startsWith("darwin")) {
return OS_TYPE.DARWIN;
} else if (lowerOSName.startsWith("sunos") || lowerOSName.startsWith("solaris")) {
return OS_TYPE.SOLARIS;
}

final String upperOSName = osName.toUpperCase(Locale.ENGLISH);
Expand All @@ -96,7 +88,7 @@ public static OS_TYPE determineOS() {
}
}

throw new UnsupportedOperationException("Unknown platform: " + osName);
throw new UnsupportedOperationException("Unsupported operating system: " + osName);
}

private static ARCH determineArchitecture() {
Expand All @@ -110,7 +102,7 @@ private static ARCH determineArchitecture() {
case "arm64":
return ARCH.AARCH64;
default:
return ARCH.UNKNOWN;
throw new UnsupportedOperationException("Unsupported CPU architecture: " + architecture);
}
}

Expand Down

0 comments on commit eed858a

Please sign in to comment.