Search in sources :

Example 1 with ArchitectureInternal

use of org.gradle.nativeplatform.platform.internal.ArchitectureInternal in project gradle by gradle.

the class GccVersionDeterminer method transform.

private GccVersionResult transform(String output, File gccBinary) {
    BufferedReader reader = new BufferedReader(new StringReader(output));
    String line;
    Map<String, String> defines = new HashMap<String, String>();
    try {
        while ((line = reader.readLine()) != null) {
            Matcher matcher = DEFINE_PATTERN.matcher(line);
            if (!matcher.matches()) {
                return new BrokenResult(String.format("Could not determine %s version: %s produced unexpected output.", getDescription(), gccBinary.getName()));
            }
            defines.put(matcher.group(1), matcher.group(2));
        }
    } catch (IOException e) {
        // Should not happen reading from a StringReader
        throw new UncheckedIOException(e);
    }
    if (!defines.containsKey("__GNUC__")) {
        return new BrokenResult(String.format("Could not determine %s version: %s produced unexpected output.", getDescription(), gccBinary.getName()));
    }
    int major;
    int minor;
    int patch;
    if (clang) {
        if (!defines.containsKey("__clang__")) {
            return new BrokenResult(String.format("%s appears to be GCC rather than Clang. Treating it as GCC.", gccBinary.getName()));
        }
        major = toInt(defines.get("__clang_major__"));
        minor = toInt(defines.get("__clang_minor__"));
        patch = toInt(defines.get("__clang_patchlevel__"));
    } else {
        if (defines.containsKey("__clang__")) {
            return new BrokenResult(String.format("XCode %s is a wrapper around Clang. Treating it as Clang and not GCC.", gccBinary.getName()));
        }
        major = toInt(defines.get("__GNUC__"));
        minor = toInt(defines.get("__GNUC_MINOR__"));
        patch = toInt(defines.get("__GNUC_PATCHLEVEL__"));
    }
    final ArchitectureInternal architecture = determineArchitecture(defines);
    return new DefaultGccVersionResult(new VersionNumber(major, minor, patch, null), architecture, clang);
}
Also used : HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) VersionNumber(org.gradle.util.VersionNumber) ArchitectureInternal(org.gradle.nativeplatform.platform.internal.ArchitectureInternal)

Example 2 with ArchitectureInternal

use of org.gradle.nativeplatform.platform.internal.ArchitectureInternal in project gradle by gradle.

the class GccVersionDeterminer method determineArchitecture.

private ArchitectureInternal determineArchitecture(Map<String, String> defines) {
    boolean i386 = defines.containsKey("__i386__");
    boolean amd64 = defines.containsKey("__amd64__");
    final ArchitectureInternal architecture;
    if (i386) {
        architecture = Architectures.forInput("i386");
    } else if (amd64) {
        architecture = Architectures.forInput("amd64");
    } else {
        architecture = DefaultNativePlatform.getCurrentArchitecture();
    }
    return architecture;
}
Also used : ArchitectureInternal(org.gradle.nativeplatform.platform.internal.ArchitectureInternal)

Aggregations

ArchitectureInternal (org.gradle.nativeplatform.platform.internal.ArchitectureInternal)2 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 VersionNumber (org.gradle.util.VersionNumber)1