diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2017-08-15 10:44:15 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2017-08-18 14:05:53 +0000 |
commit | 20f0c38190fb853b92066901ab8f543bfe80c84f (patch) | |
tree | 1419dbf7a343a340b16dc040fd1c8f95e5dcc281 /share | |
parent | a26612b9e3e86ccaff93a75cf83c4a2621e1dbf4 (diff) |
Introduce the vcs module
Every once in a while, users ask how they can best achieve to get access
to their current git HEAD, so we provide a module that does it for them.
[ChangeLog] Added the vcs module to provide VCS repository information.
Git and Subversion are supported initially.
Change-Id: Ib425547bf9f04406cda35bf81bcb878f6ea4b9ce
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'share')
-rw-r--r-- | share/qbs/modules/vcs/vcs-module.qbs | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/share/qbs/modules/vcs/vcs-module.qbs b/share/qbs/modules/vcs/vcs-module.qbs new file mode 100644 index 000000000..290547713 --- /dev/null +++ b/share/qbs/modules/vcs/vcs-module.qbs @@ -0,0 +1,153 @@ +import qbs +import qbs.File +import qbs.FileInfo +import qbs.Process +import qbs.TextFile +import qbs.Utilities + +Module { + property string type: typeProbe.type + property string repoDir: project.sourceDirectory + property string toolFilePath: { + if (type === "git") + return "git"; + if (type === "svn") + return "svn"; + } + + property string headerFileName: "vcs-repo-state.h" + readonly property string repoState: gitProbe.repoState || subversionProbe.repoState + + // Internal + readonly property string includeDir: FileInfo.joinPaths(product.buildDirectory, "vcs-include") + readonly property string metaDataBaseDir: typeProbe.metaDataBaseDir + + PropertyOptions { + name: "type" + allowedValues: ["git", "svn"] + description: "the version control system your project is using" + } + + Depends { name: "cpp"; condition: headerFileName } + Properties { + condition: headerFileName + cpp.includePaths: [includeDir] + } + + Probe { + id: typeProbe + + property string tool: toolFilePath + property string theRepoDir: repoDir + + property string type + property string metaDataBaseDir + + configure: { + var detector = new Process(); + try { + detector.setWorkingDirectory(theRepoDir); + if (detector.exec(tool || "git", ["rev-parse", "--git-dir"]) === 0) { + found = true; + type = "git"; + metaDataBaseDir = detector.readStdOut().trim(); + return; + } + if (detector.exec(tool || "svn", + ["info", "--show-item", "wc-root", "--no-newline"]) === 0) { + found = true + type = "svn"; + metaDataBaseDir = FileInfo.joinPaths(detector.readStdOut(), ".svn"); + return; + } else if (detector.exec(tool || "svn", ["info"]) === 0) { + if (detector.exec(tool || "svn", ["--version", "--quiet"]) === 0 + && Utilities.versionCompare(detector.readStdOut().trim(), "1.9") < 0) { + throw "svn too old, version >= 1.9 required"; + } + } + } finally { + detector.close(); + } + } + } + + Probe { + id: gitProbe + condition: type === "git" + + property string tool: toolFilePath + property string theRepoDir: repoDir + property string filePath: FileInfo.joinPaths(metaDataBaseDir, "logs/HEAD") + property var timestamp: File.lastModified(filePath) + + property string repoState + + configure: { + if (!File.exists(filePath)) + return; // No commits yet. + var proc = new Process(); + try { + proc.setWorkingDirectory(theRepoDir); + proc.exec(tool, ["describe", "--always", "HEAD"], true); + repoState = proc.readStdOut().trim(); + if (repoState) + found = true; + } finally { + proc.close(); + } + } + } + + Probe { + id: subversionProbe + condition: type === "svn" + + property string tool: toolFilePath + property string theRepoDir: repoDir + property string filePath: FileInfo.joinPaths(metaDataBaseDir, "wc.db") + property var timestamp: File.lastModified(filePath) + + property string repoState + + configure: { + var proc = new Process(); + try { + proc.setWorkingDirectory(theRepoDir); + proc.exec(tool, ["info", "-r", "HEAD", "--show-item", "revision", "--no-newline"], + true); + repoState = proc.readStdOut(); + if (repoState) + found = true; + } finally { + proc.close(); + } + } + } + + Rule { + condition: repoState && headerFileName + multiplex: true + Artifact { + filePath: FileInfo.joinPaths(product.vcs.includeDir, product.vcs.headerFileName) + fileTags: ["hpp"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "generating " + output.fileName; + cmd.highlight = "codegen"; + cmd.repoState = product.vcs.repoState; + cmd.sourceCode = function() { + var f = new TextFile(output.filePath, TextFile.WriteOnly); + try { + f.writeLine("#ifndef VCS_REPO_STATE_H"); + f.writeLine("#define VCS_REPO_STATE_H"); + f.writeLine('#define VCS_REPO_STATE "' + repoState + '"') + f.writeLine("#endif"); + } finally { + f.close(); + } + }; + return [cmd]; + } + } +} |