1import qbs.File
2import qbs.FileInfo
3import qbs.Probes
4
5Project {
6    references: ["man/man.qbs"]
7
8    Product {
9        name: "qbs documentation"
10        builtByDefault: false
11        type: Qt.core.config.contains("cross_compile") ?
12                  ["qbsdoc.qdoc-html-fixed"] : [ "qbsdoc.qdoc-html-fixed", "qch"]
13
14        property string fixedHtmlDir: FileInfo.joinPaths(buildDirectory, "qdoc-html-fixed")
15        Depends { name: "Qt.core" }
16        Depends { name: "qbsbuildconfig" }
17        Depends { name: "qbsversion" }
18
19        Probes.BinaryProbe {
20            id: pythonProbe
21            names: ["python3", "python"] // on Windows, there's no python3
22        }
23        property string pythonPath: pythonProbe.found ? pythonProbe.filePath : undefined
24
25        files: [
26            "../README.md",
27            "../CONTRIBUTING.md",
28            "classic.css",
29            "external-resources.qdoc",
30            "fixnavi.pl",
31            "howtos.qdoc",
32            "qbs.qdoc",
33            "qbs-online.qdocconf",
34            "config/*.qdocconf",
35            "config/style/qt5-sidebar.html",
36            "appendix/**/*",
37            "reference/**/*",
38            "templates/**/*",
39            "images/**",
40            "targets/**",
41        ]
42        Group {
43            name: "main qdocconf file"
44            files: "qbs.qdocconf"
45            fileTags: "qdocconf-main"
46        }
47        Group {
48            name: "fix-imports script"
49            files: ["fix-qmlimports.py"]
50            fileTags: ["qbsdoc.fiximports"]
51        }
52
53        property string versionTag: qbsversion.version.replace(/\.|-/g, "")
54        Qt.core.qdocEnvironment: [
55            "QBS_VERSION=" + qbsversion.version,
56            "SRCDIR=" + path,
57            "QT_INSTALL_DOCS=" + Qt.core.docPath,
58            "QBS_VERSION_TAG=" + versionTag
59        ]
60
61        Rule {
62            inputs: ["qdoc-png"]
63            explicitlyDependsOn: ["qbsdoc.fiximports"]
64            multiplex: true
65            outputFileTags: ["qdoc-html", "qbsdoc.dummy"] // TODO: Hack. Rule injection to the rescue?
66            outputArtifacts: [{filePath: "dummy", fileTags: ["qbsdoc.dummy"]}]
67            prepare: {
68                if (!product.pythonPath)
69                    throw "Python executable was not found";
70                var scriptPath = explicitlyDependsOn["qbsdoc.fiximports"][0].filePath;
71                var htmlDir = FileInfo.path(FileInfo.path(inputs["qdoc-png"][0].filePath));
72                var fixCmd = new Command(product.pythonPath, [scriptPath, htmlDir]);
73                fixCmd.description = "fixing bogus QML import statements";
74                return [fixCmd];
75            }
76        }
77
78        Rule {
79            inputs: ["qdoc-html"]
80            Artifact {
81                filePath: FileInfo.joinPaths(product.fixedHtmlDir, input.fileName)
82                fileTags: ["qbsdoc.qdoc-html-fixed"]
83            }
84            prepare: {
85                var cmd = new JavaScriptCommand();
86                cmd.silent = true;
87                cmd.sourceCode = function() { File.copy(input.filePath, output.filePath); }
88                return [cmd];
89            }
90        }
91
92        Group {
93            fileTagsFilter: ["qbsdoc.qdoc-html-fixed"]
94            qbs.install: qbsbuildconfig.installHtml
95            qbs.installDir: qbsbuildconfig.docInstallDir
96            qbs.installSourceBase: product.fixedHtmlDir
97        }
98        Group {
99            fileTagsFilter: ["qdoc-css", "qdoc-png"]
100            qbs.install: qbsbuildconfig.installHtml
101            qbs.installDir: qbsbuildconfig.docInstallDir
102            qbs.installSourceBase: Qt.core.qdocOutputDir
103        }
104        Group {
105            fileTagsFilter: ["qch"]
106            qbs.install: qbsbuildconfig.installQch
107            qbs.installDir: qbsbuildconfig.docInstallDir
108        }
109    }
110}
111