Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import qbs.File
- import qbs.FileInfo
- import qbs.TextFile
- import qbs.Process
- Project {
- Product {
- name: "AppVer"
- type: ["hpp"]
- builtByDefault: false
- readonly property path ver_file: FileInfo.joinPaths( buildDirectory, "MyAppVer.h" )
- readonly property bool need_update: ( !curver.found ) || ( curver.version != svnver.version )
- readonly property string new_ver: svnver.version
- readonly property string cur_ver: curver.version
- readonly property string new_txt: "#define MY_VERSION " + svnver.version + "\n";
- Probe {
- id: svnver
- property string version
- readonly property path src_dir: product.sourceDirectory
- configure: {
- var p = new Process();
- p.exec( "svnversion", [src_dir], true );
- var txt = p.readStdOut();
- p.close();
- version = '' + parseInt( txt, 10 );
- found = true;
- console.info( 'svn revision: ' + version );
- }
- }
- Probe {
- id: curver
- property string version: '0'
- readonly property path ver_file: product.ver_file
- configure: {
- found = false;
- if ( File.exists( ver_file ) )
- {
- var f = new TextFile( ver_file );
- var txt = f.readAll();
- f.close();
- var ar = txt.match( /MY_VERSION\s+(\d+)/ );
- if ( ar !== null && ar !== false )
- {
- found = true;
- version = ar[1];
- console.info( 'current revision: ' + version );
- }
- else
- console.warning( 'error parsing current revision' );
- }
- else
- console.info( ver_file + ' not found' );
- }
- }
- Rule {
- multiplex: true
- requiresInputs: false
- alwaysRun: true
- //alwaysRun: need_update
- Artifact { fileTags:["hpp"]; filePath: product.ver_file }
- prepare: {
- var cmd = new JavaScriptCommand();
- cmd.dst = product.ver_file;
- cmd.txt = product.new_txt;
- if ( product.need_update )
- {
- cmd.description = "Update " + cmd.dst + ' ' + product.cur_ver + ' -> ' + product.new_ver;
- cmd.sourceCode = function(){
- var file = new TextFile( dst, TextFile.WriteOnly );
- file.write( txt );
- file.close();
- };
- }
- else
- {
- cmd.description = "Keep existing " + cmd.dst + " rev. " + product.cur_ver;
- cmd.sourceCode = function(){};
- }
- return [cmd];
- }
- }
- Export {
- Depends { name: "cpp" }
- cpp.includePaths: [exportingProduct.buildDirectory]
- Group { fileTagsFilter: ["hpp"] }
- }
- }
- CppApplication {
- name: "a"
- consoleApplication: true
- install: true
- Depends { name: "AppVer" }
- files: ["m.cpp"]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement