Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCONS run target

Tags:

scons

I've been looking, and looking, and I can't find an answer to my question. I've just started learning scons tonight, and it looks awesome! I'm running into a little confusion though.

For ease of development, I often like to have my make file build my target, and then run it so that I can test a change with one keystroke. This is very simple in a make file:

run: $(exe)
    chmod a+x $(exe)
    $(exe)

I have figured out that I can do it using subprocess like so:

import subprocess import os.path

env = Environment();
result = env.Program(target = "FOO", source = "BAR");
location = os.path.abspath(result[0].name)
subprocess.call([location])

But there's a problem with this solution. As far as I have experimented, scons won't wait until your program is finished building before it starts the subprocess call, so you end up running the old executable, or having an error if it's a build after a clean.

like image 281
Murphy Randle Avatar asked Jan 07 '12 01:01

Murphy Randle


People also ask

How can I speed up my SCons?

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

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 compiler does SCons use?

The Visual C++ compiler option that SCons uses by default to generate PDB information is /Z7 . This works correctly with parallel ( -j ) builds because it embeds the debug information in the intermediate object files, as opposed to sharing a single PDB file between multiple object files.

How do you clean SCons?

When using SCons, it is unnecessary to add special commands or target names to clean up after a build. Instead, you simply use the -c or --clean option when you invoke SCons, and SCons removes the appropriate built files.


2 Answers

What you do in your scons file is a typical beginner error in scons. Your assume that you are writing a script for building your project.

Scons doesn't work like that. The scons files is a script that add targets to the project. This is done through python, and the various objects allows you to create and manipulate targets until the script is done. First then will the project start building.

What you do in your code is to describe the Environment to use, the Program to create, and after that you call a subprocess that runs some program. After this the project will start building - no wonder the old executable is run, the new one haven't started to be built yet.

What you should do is to use a custom builder for executing the program.

env = Environment() #construct your environment
files = "test.cpp" #env.Glob or list some files

#now we create some targets
program = env.Program("test",files) #create the target *program*
execution = env.Command(None,None,"./test") #create the execution target (No input & output

Depends(execution,program) #tell scons that execution depends on program
#there might be a way to get SCons to figure out this dependency itself

#now the script is completed, so the targets are built

Here the dependencies are clear, the program must be built before the execution is done, and it will

like image 97
daramarak Avatar answered Jan 04 '23 09:01

daramarak


I may be a little bit late for you, but I have this solution using Alias. By using the following command, it will build and run the program:

$ scons run
# Define the different target output
program = env.Program('build/output', Glob('build/test/*.cpp'))

env.Default(program)
env.Alias('run', program, program[0].abspath)

note that we use the abspath, so it can be cross platform win/linux (for linux you need to add the "./" before the program name if your PATH is not correctly set.

like image 39
Phong Avatar answered Jan 04 '23 09:01

Phong