aboutsummaryrefslogtreecommitdiffstats
path: root/qbs/modules/pluginjson/pluginjson.qbs
blob: 8cba1834370f2b2b1e99a5d1e842c2c0c47442ed (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
107
108
109
110
111
import qbs 1.0
import qbs.File
import qbs.FileInfo
import qbs.TextFile
import qbs.Utilities

Module {
    Depends { id: qtcore; name: "Qt.core" }
    Depends { name: "qtc" }

    // TODO: Wrap the VCS specific stuff in a dedicated module
    property bool hasVcs: Utilities.versionCompare(qbs.version, "1.10") >= 0
    Depends { name: "vcs"; condition: hasVcs }
    Properties {
        condition: hasVcs
        vcs.repoDir: {
            // TODO: Could something like this be incorporated into the vcs module?
            //       Currently, the default repo dir is project.sourceDirectory, which
            //       does not make sense for Qt Creator.
            var dir = sourceDirectory;
            while (true) {
                if (File.exists(FileInfo.joinPaths(dir, ".git")))
                    return dir;
                var newDir = FileInfo.path(dir);
                if (newDir === dir || dir === project.sourceDirectory) {
                    console.warn("No git repository found for product " + product.name
                                 + ", revision information will not be evailable.");
                    break;
                }
                dir = newDir;
            }
        }
    }

    additionalProductTypes: ["qt_plugin_metadata"]

    Rule {
        inputs: ["pluginJsonIn"]

        Artifact {
            fileTags: ["qt_plugin_metadata"]
            filePath: {
                var destdir = FileInfo.joinPaths(product.moduleProperty("Qt.core",
                                                         "generatedHeadersDir"), input.fileName);
                return destdir.replace(/\.[^\.]*$/,'')
            }
        }

        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.description = "prepare " + FileInfo.fileName(output.filePath);
            cmd.highlight = "codegen";
            cmd.pluginJsonReplacements = product.pluginJsonReplacements;
            cmd.plugin_depends = [];
            var deps = product.dependencies;
            for (var d in deps) {
                var depdeps = deps[d].dependencies;
                for (var dd in depdeps) {
                    if (depdeps[dd].name == 'pluginjson') {
                        cmd.plugin_depends.push(deps[d].name);
                        break;
                    }
                }
            }
            cmd.plugin_recommends = product.pluginRecommends
            cmd.plugin_test_depends = product.pluginTestDepends

            cmd.sourceCode = function() {
                var i;
                var vars = pluginJsonReplacements || {};
                var inf = new TextFile(input.filePath);
                var all = inf.readAll();
                // replace quoted quotes
                all = all.replace(/\\\"/g, '"');
                // replace config vars
                var qtcVersion = product.moduleProperty("qtc", "qtcreator_version");
                vars['QTCREATOR_VERSION'] = qtcVersion;
                vars['QTCREATOR_COMPAT_VERSION']
                        = product.moduleProperty("qtc", "qtcreator_compat_version");
                vars['IDE_VERSION_MAJOR'] = product.moduleProperty("qtc", "ide_version_major");
                vars['IDE_VERSION_MINOR'] = product.moduleProperty("qtc", "ide_version_minor");
                vars['IDE_VERSION_RELEASE'] = product.moduleProperty("qtc", "ide_version_release");
                vars['QTCREATOR_COPYRIGHT_YEAR']
                        = product.moduleProperty("qtc", "qtcreator_copyright_year")
                if (!vars['QTC_PLUGIN_REVISION'])
                    vars['QTC_PLUGIN_REVISION'] = product.vcs ? (product.vcs.repoState || "") : "";
                var deplist = [];
                for (i in plugin_depends) {
                    deplist.push("        { \"Name\" : \"" + plugin_depends[i] + "\", \"Version\" : \"" + qtcVersion + "\" }");
                }
                for (i in plugin_recommends) {
                    deplist.push("        { \"Name\" : \"" + plugin_recommends[i] + "\", \"Version\" : \"" + qtcVersion + "\", \"Type\" : \"optional\" }");
                }
                for (i in plugin_test_depends) {
                    deplist.push("        { \"Name\" : \"" + plugin_test_depends[i] + "\", \"Version\" : \"" + qtcVersion + "\", \"Type\" : \"test\" }");
                }
                deplist = deplist.join(",\n")
                vars['dependencyList'] = "\"Dependencies\" : [\n" + deplist + "\n    ]";
                for (i in vars) {
                    all = all.replace(new RegExp('\\\$\\\$' + i + '(?!\w)', 'g'), vars[i]);
                }
                var file = new TextFile(output.filePath, TextFile.WriteOnly);
                file.truncate();
                file.write(all);
                file.close();
            }
            return cmd;
        }
    }
}