aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/imports/qbs/Probes/GccBinaryProbe.qbs
blob: 9081f5efb5586559568b11502e0ab49d7a163ccb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import qbs.Environment
import qbs.FileInfo
import "path-probe.js" as PathProbeConfigure

BinaryProbe {
    nameSuffixes: undefined // _compilerName already contains ".exe" suffix on Windows
    // Inputs
    property string _compilerName
    property string _toolchainPrefix

    // Outputs
    property string tcPrefix

    platformSearchPaths: {
        var paths = base;
        if (qbs.targetOS.contains("windows") && qbs.hostOS.contains("windows"))
            paths.push(FileInfo.joinPaths(
                           Environment.getEnv("SystemDrive"), "MinGW", "bin"));
        return paths;
    }

    names: {
        var prefixes = [];
        if (_toolchainPrefix) {
            prefixes.push(_toolchainPrefix);
        } else {
            var arch = qbs.architecture;
            if (qbs.targetOS.contains("windows")) {
                if (!arch || arch === "x86") {
                    prefixes.push("mingw32-",
                                  "i686-w64-mingw32-",
                                  "i686-w64-mingw32.shared-",
                                  "i686-w64-mingw32.static-",
                                  "i686-mingw32-",
                                  "i586-mingw32msvc-");
                }
                if (!arch || arch === "x86_64") {
                    prefixes.push("x86_64-w64-mingw32-",
                                  "x86_64-w64-mingw32.shared-",
                                  "x86_64-w64-mingw32.static-",
                                  "amd64-mingw32msvc-");
                }
            }
        }
        return prefixes.map(function(prefix) {
            return prefix + _compilerName;
        }).concat([_compilerName]);
    }

    configure: {
        var selectors;
        var results = PathProbeConfigure.configure(
                    selectors, names, nameSuffixes, nameFilter, candidateFilter, searchPaths,
                    pathSuffixes, platformSearchPaths, environmentPaths, platformEnvironmentPaths,
                    pathListSeparator);

        found = results.found;
        if (!found)
            return;

        var resultsMapper = function(result) {
            (nameSuffixes || [""]).forEach(function(suffix) {
                var end = _compilerName + suffix;
                if (result.fileName.endsWith(end))
                    result.tcPrefix = result.fileName.slice(0, -end.length);
            });
            return result;
        };
        results.files = results.files.map(resultsMapper);
        allResults = results.files;
        var result = results.files[0];
        candidatePaths = result.candidatePaths;
        path = result.path;
        filePath = result.filePath;
        fileName = result.fileName;
        tcPrefix = result.tcPrefix;
    }
}