Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get SCons to replace text in installed text files

I'd like to be able to replace a template variable ('$(SOFTWARE_VERSION)') while installing some python scripts from scons. Does scons already have such functionality? If not, what's the best way to hook into the scons install process so I can do this during install?

like image 483
John Calcote Avatar asked Feb 15 '11 22:02

John Calcote


People also ask

How do I run a SCons script?

Click the start button, (on XP click Run), then type cmd and from the command line type python -V. It should say something like Python 2.7. 2. Any version 2.4 or higher is ok for SCons.

What is SCons command?

DESCRIPTION. The scons utility builds software (or other files) by determining which component pieces must be rebuilt and executing the necessary commands to rebuild them.

What is SConstruct?

The SConstruct File. If you're used to build systems like Make you've already figured out that the SConstruct file is the SCons equivalent of a Makefile. That is, the SConstruct file is the input file that SCons reads to control the build.

How can I speed up my SCons?

The command 'scons --max-drift=1 --implicit-deps-unchanged' will execute your build as fast as possible.


1 Answers

You could use the Substfile method. This takes a input file and produces an output file substituting marked variables. So if you have script.py.in:

#!/usr/bin/python
print "$SOFTWARE_VERSION"

Then you can use the following SConsctruct file to generate an output:

env = Environment(tools=['textfile'])
script_dict = {'\$SOFTWARE_VERSION': '1.0'}
env.Substfile('script.py.in', SUBST_DICT = script_dict)

You need to escape the $ in the string '\$SOFTWARE_VERSION' otherwise SCons interprets it as an internal environment variable. The result would be a file script.py with this contents:

#!/usr/bin/python
print "1.0"

You can then install this resulting substituted file using env.Install.

like image 55
richq Avatar answered Sep 30 '22 23:09

richq