pluginspec.qbs 3.88 KB
Newer Older
Joerg Bornemann's avatar
Joerg Bornemann committed
1
import qbs.base 1.0
2
import qbs.fileinfo as FileInfo
Joerg Bornemann's avatar
Joerg Bornemann committed
3 4

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

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

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

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

        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.description = "prepare " + FileInfo.fileName(output.fileName);
            cmd.highlight = "codegen";
21 22 23 24
            cmd.ide_version_major = project.ide_version_major;
            cmd.ide_version_minor = project.ide_version_minor;
            cmd.ide_version_release = project.ide_version_release;
            cmd.qtcreator_version = cmd.ide_version_major + '.' + cmd.ide_version_minor + '.' + cmd.ide_version_release;
Daniel Teske's avatar
Daniel Teske committed
25

26
            cmd.pluginspecreplacements = product.pluginspecreplacements;
27 28 29 30 31 32 33 34 35 36 37 38
            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
39

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

    Rule {
        inputs: ["pluginSpec"]

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

        prepare: {
            var xslFile = project.path + "/src/pluginjsonmetadata.xsl";
87
            var xmlPatternsPath = product.moduleProperty("Qt/core", "binPath") + "/xmlpatterns";
88
            var args = [
Yuchen Deng's avatar
Yuchen Deng committed
89 90 91 92 93
                "-no-format",
                "-output",
                output.fileName,
                xslFile,
                input.fileName
94 95 96 97 98 99 100
            ];
            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
101 102
}