File: pluginjson.qbs

package info (click to toggle)
qtcreator 18.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 261,240 kB
  • sloc: cpp: 1,581,554; ansic: 528,781; python: 48,245; xml: 34,678; javascript: 15,495; sh: 2,670; asm: 2,049; perl: 1,039; lex: 737; java: 695; objc: 409; makefile: 111; yacc: 86; cs: 41; ruby: 33; sed: 22
file content (124 lines) | stat: -rw-r--r-- 5,533 bytes parent folder | download | duplicates (3)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
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" }

    property var replacements

    // TODO: Wrap the VCS specific stuff in a dedicated module
    property bool useVcsData: true
    Depends { name: "vcs"; condition: useVcsData }
    Properties {
        condition: useVcsData
        vcs.headerFileName: undefined
        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 = product.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", "pluginjson.license", "pluginjson.longDescription"]
        multiplex: true

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

        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.description = "prepare " + FileInfo.fileName(output.filePath);
            cmd.highlight = "codegen";
            cmd.pluginJsonReplacements = product.pluginjson.replacements;
            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.toLowerCase());
                        break;
                    }
                }
            }
            cmd.plugin_recommends = product.pluginRecommends
            cmd.plugin_test_depends = product.pluginTestDepends

            cmd.sourceCode = function() {
                var i;
                var vars = pluginJsonReplacements || {};
                var inf = new TextFile(inputs.pluginJsonIn[0].filePath);
                var all = inf.readAll();
                // replace config vars
                var qtcVersion = product.moduleProperty("qtc", "qtcreator_version");
                vars['IDE_VERSION'] = qtcVersion;
                vars['IDE_VERSION_COMPAT']
                        = 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['IDE_COPYRIGHT'] = product.moduleProperty("qtc", "ide_copyright_string");
                if (!vars['QTC_PLUGIN_REVISION'])
                    vars['QTC_PLUGIN_REVISION'] = product.vcs ? (product.vcs.repoState || "") : "";
                var deplist = [];
                for (i in plugin_depends) {
                    deplist.push("        { \"Id\" : \"" + plugin_depends[i] + "\", \"Version\" : \"" + qtcVersion + "\" }");
                }
                for (i in plugin_recommends) {
                    deplist.push("        { \"Id\" : \"" + plugin_recommends[i] + "\", \"Version\" : \"" + qtcVersion + "\", \"Type\" : \"optional\" }");
                }
                for (i in plugin_test_depends) {
                    deplist.push("        { \"Id\" : \"" + plugin_test_depends[i] + "\", \"Version\" : \"" + qtcVersion + "\", \"Type\" : \"test\" }");
                }
                deplist = deplist.join(",\n")
                vars['IDE_PLUGIN_DEPENDENCIES'] = "\"Dependencies\" : [\n" + deplist + "\n    ]";
                vars['LICENSE'] = '"No license"';
                var licenseInputs = inputs["pluginjson.license"];
                if (licenseInputs) {
                    var licFile = new TextFile(licenseInputs[0].filePath);
                    vars['LICENSE'] = JSON.stringify(licFile.readAll());
                }
                vars['LONG_DESCRIPTION'] = '""';
                var longDescriptionInputs = inputs["pluginjson.longDescription"];
                if (longDescriptionInputs) {
                    var longDescFile = new TextFile(longDescriptionInputs[0].filePath);
                    vars['LONG_DESCRIPTION'] = JSON.stringify(longDescFile.readAll());
                }

                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;
        }
    }
}