How can I add the build version to a scons build -


at moment i'm using magic current git revision scons builds.. grab version stick cppdefines. works quite nicely ... until version changes , scons wants rebuild everything, rather files have changed - becasue define files use has changed.

ideally i'd generate file using custom builder called git_version.cpp , have function in there returns right tag. way 1 file rebuilt.

now i'm sure i've seen tutorial showing how .. can't seem track down. , find custom builder stuff little odd in scons...

so pointers appreciated...

anyway reference i'm doing:

# lets version git # first base version git_sha = subprocess.popen(["git","rev-parse","--short=10","head"], stdout=subprocess.pipe ).communicate()[0].strip() p1 = subprocess.popen(["git", "status"], stdout=subprocess.pipe ) p2 = subprocess.popen(["grep", "changed not updated\\|changes committed"], stdin=p1.stdout,stdout=subprocess.pipe) result = p2.communicate()[0].strip()  if result!="":   git_sha += "[mod]"  print "building version %s"%git_sha  env = environment() env.append( cppdefines={'gitshamod':'"\\"%s\\""'%git_sha} ) 

you don't need custom builder since 1 file. can use function (attached target version file action) generate version file. in example code below, i've computed version , put environment variable. same, or put code makes git calls in version_action function.

version_build_template="""/* * file automatically generated build process * not edit! */  const char version_string[] = "%s";  const char* getversionstring() { return version_string; } """  def version_action(target, source, env):     """     generate version file current version in     """     contents = version_build_template % (env['version'].tostring())     fd = open(target[0].path, 'w')     fd.write(contents)     fd.close()     return 0  build_version = env.command('version.build.cpp', [], action(version_action)) env.alwaysbuild(build_version) 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -