pluginspec.qbs 3.73 KB
Newer Older
Joerg Bornemann's avatar
Joerg Bornemann committed
1
import qbs.base 1.0
Christian Kandeler's avatar
Christian Kandeler committed
2
import qbs.TextFile
3
import qbs.FileInfo
Joerg Bornemann's avatar
Joerg Bornemann committed
4 5

Module {
Yuchen Deng's avatar
Yuchen Deng committed
6
    Depends { id: qtcore; name: "Qt.core" }
7

8
    additionalProductFileTags: qtcore.versionMajor < 5 ? ["pluginSpec"] : ["qt_plugin_metadata"]
Daniel Teske's avatar
Daniel Teske committed
9

Joerg Bornemann's avatar
Joerg Bornemann committed
10 11 12 13 14
    Rule {
        inputs: ["pluginSpecIn"]

        Artifact {
            fileTags: ["pluginSpec"]
15
            fileName: input.fileName.replace(/\.[^\.]*$/,'')
Joerg Bornemann's avatar
Joerg Bornemann committed
16 17 18 19 20 21
        }

        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.description = "prepare " + FileInfo.fileName(output.fileName);
            cmd.highlight = "codegen";
22
            cmd.pluginspecreplacements = product.pluginspecreplacements;
23 24 25 26 27 28 29 30 31 32 33 34
            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 == 'pluginspec') {
                        cmd.plugin_depends.push(deps[d].name);
                        break;
                    }
                }
            }
            cmd.plugin_recommends = product.pluginRecommends
Daniel Teske's avatar
Daniel Teske committed
35

Joerg Bornemann's avatar
Joerg Bornemann committed
36 37
            cmd.sourceCode = function() {
                var i;
Daniel Teske's avatar
Daniel Teske committed
38
                var vars = pluginspecreplacements || {};
Joerg Bornemann's avatar
Joerg Bornemann committed
39 40 41
                var inf = new TextFile(input.fileName);
                var all = inf.readAll();
                // replace quoted quotes
Yuchen Deng's avatar
Yuchen Deng committed
42
                all = all.replace(/\\\"/g, '"');
Joerg Bornemann's avatar
Joerg Bornemann committed
43
                // replace config vars
44
                vars['QTCREATOR_VERSION'] = project.qtcreator_version;
Eike Ziller's avatar
Eike Ziller committed
45
                vars['QTCREATOR_COMPAT_VERSION'] = project.qtcreator_compat_version;
46 47 48
                vars['IDE_VERSION_MAJOR'] = project.ide_version_major;
                vars['IDE_VERSION_MINOR'] = project.ide_version_minor;
                vars['IDE_VERSION_RELEASE'] = project.ide_version_release;
49 50
                var deplist = ["<dependencyList>"];
                for (i in plugin_depends) {
51
                    deplist.push("        <dependency name=\"" + plugin_depends[i] + "\" version=\"" + project.qtcreator_version + "\"/>");
52 53
                }
                for (i in plugin_recommends) {
54
                    deplist.push("        <dependency name=\"" + plugin_recommends[i] + "\" version=\"" + project.qtcreator_version + "\" type=\"optional\"/>");
55 56 57
                }
                deplist.push("    </dependencyList>");
                vars['dependencyList'] = deplist.join("\n");
Joerg Bornemann's avatar
Joerg Bornemann committed
58
                for (i in vars) {
59
                    all = all.replace(new RegExp('\\\$\\\$' + i + '(?!\w)', 'g'), vars[i]);
Joerg Bornemann's avatar
Joerg Bornemann committed
60 61 62 63 64 65 66 67 68
                }
                var file = new TextFile(output.fileName, TextFile.WriteOnly);
                file.truncate();
                file.write(all);
                file.close();
            }
            return cmd;
        }
    }
69 70 71 72 73

    Rule {
        inputs: ["pluginSpec"]

        Artifact {
74
            fileTags: ["qt_plugin_metadata"]
75
            fileName: {
76
                var destdir = FileInfo.joinPaths(product.moduleProperty("Qt/core", "generatedFilesDir"),
77 78 79 80 81 82
                                                 input.fileName);
                return destdir.replace(/\.[^\.]*$/, '.json');
            }
        }

        prepare: {
83
            var xslFile = project.path + "/../pluginjsonmetadata.xsl"; // project is "Plugins"
84
            var xmlPatternsPath = product.moduleProperty("Qt/core", "binPath") + "/xmlpatterns";
85
            var args = [
Yuchen Deng's avatar
Yuchen Deng committed
86 87 88 89 90
                "-no-format",
                "-output",
                output.fileName,
                xslFile,
                input.fileName
91 92 93 94 95 96 97
            ];
            var cmd = new Command(xmlPatternsPath, args);
            cmd.description = "generating " + FileInfo.fileName(output.fileName);
            cmd.highlight = "codegen";
            return cmd;
        }
    }
Joerg Bornemann's avatar
Joerg Bornemann committed
98 99
}