aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/modules/qbs/common.qbs
blob: d673afcbd8c996035a43af78689916aff1d98de2 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import qbs.base 1.0
import qbs.fileinfo 1.0 as FileInfo

Module {
    property string buildVariant: "debug"
    property bool debugInformation: (buildVariant == "debug")
    property string optimization: (buildVariant == "debug" ? "none" : "fast")
    property string platform: null
    property string hostOS: getHostOS()
    property string hostArchitecture: getHostDefaultArchitecture()
    property string targetOS: null
    property string targetName: null
    property string toolchain: null
    property string architecture: null
    property string endianness: null
    property string installDir: '.'
    property string sysroot
    property string installPrefix: ""
    property string deployRoot: "./deployRoot"
    property string deployInfoFile

    PropertyOptions {
        name: "buildVariant"
        allowedValues: ['debug', 'release']
        description: "name of the build variant"
    }

    PropertyOptions {
        name: "optimization"
        allowedValues: ['none', 'fast', 'small']
        description: "optimization level"
    }

    Rule {
        inputs: ["install"]
        Artifact {
            fileTags: ["installed_content"]
            fileName: {
                var targetPath = input.modules.qbs.installDir + "/" + input.fileName
                if (input.modules.qbs.installPrefix && !FileInfo.isAbsolutePath(targetPath))
                    targetPath = input.modules.qbs.installPrefix + "/" + targetPath
                if (product.module.sysroot && FileInfo.isAbsolutePath(targetPath))
                    targetPath = product.module.sysroot + targetPath
                return targetPath
            }
        }

        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.sourceCode = function() {
                File.remove(output.fileName);
                if (!File.copy(input.fileName, output.fileName))
                    throw "Cannot install '" + input.fileName + "' as '" + output.fileName + "'";
            }
            cmd.description = "installing " + FileInfo.fileName(output.fileName);
            cmd.highlight = "linker";
            return cmd;
        }
    }

    Rule {
        inputs: "deploy"
        multiplex: deployInfoFile != null
        Artifact {
            fileTags: "installed_content"
            fileName: {
                if (product.modules.qbs.deployInfoFile)
                    return product.modules.qbs.deployInfoFile
                return input.modules.qbs.deployRoot + "/" + input.modules.qbs.installPrefix
                    + "/" + input.modules.qbs.installDir + "/" + input.fileName
            }
        }

        prepare: {
            var cmd = new JavaScriptCommand()
            cmd.deployInfo = []
            if (product.modules.qbs.deployInfoFile) {
                for (var i in inputs.deploy) {
                    var sourceFile = inputs.deploy[i].fileName
                    var destFile = product.modules.qbs.installPrefix + "/"
                        + inputs.deploy[i].modules.qbs.installDir + "/"
                        + FileInfo.fileName(sourceFile)
                    destFile = destFile.replace(/\/+/g, "/")
                    destFile = destFile.replace(/\/\.\//g, "/")
                    cmd.deployInfo.push(sourceFile + "|" + destFile)
                }
                cmd.description = "Writing deployment information to '" + output.fileName + "'"
                cmd.sourceCode = function() {
                    var deployInfoFile = new TextFile(output.fileName, TextFile.WriteOnly)
                    for (var i in deployInfo)
                        deployInfoFile.writeLine(deployInfo[i])
                    deployInfoFile.close()
                }
            } else {
                cmd.description = "deploying " + FileInfo.fileName(output.fileName)
                cmd.sourceCode = function() {
                    File.remove(output.fileName)
                    if (!File.copy(input.fileName, output.fileName))
                        throw "Cannot deploy '" + input.fileName + "' to '" + output.fileName + "'"
                }
            }
            cmd.highlight = "linker"
            return cmd
        }
    }
}