Seems like you're trying to add the object
file without actually compiling the cpp
file.
I made a small example that should help clear up the situation. Basically, since you configured the suffix, and src_suffix in the call to Builder, the sources and targets are correctly setup by SCons, and you dont need the emitter.
def cpp_emit (target,source, env):
for t in target:
print 'Emitter target: %s' % (t)
for s in source:
print 'Emitter source: %s' % (s.name)
return (target,source)
# Tangle to .cpp
builder = Builder(
action='/home/notroot/projects/sandbox/Emitter/builder.sh $SOURCES $TARGET',
suffix='.cc',
src_suffix='.nw',
emitter=cpp_emit)
env = Environment()
env['BUILDERS']['tangle'] = builder
tangleTarget = env.tangle(target='main.cc', source='main.nw')
env.Object(source=tangleTarget)
And here is the output:
$ scons
scons: Reading SConscript files ...
Emitter target: main.cc
Emitter source: main.nw
scons: done reading SConscript files.
scons: Building targets ...
/home/notroot/projects/sandbox/Emitter/builder.sh main.nw main.cc
g++ -o main.o -c main.cc
scons: done building targets.
$ scons -c
scons: Reading SConscript files ...
Emitter target: main.cc
Emitter source: main.nw
scons: done reading SConscript files.
scons: Cleaning targets ...
Removed main.cc
Removed main.o
scons: done cleaning targets.
I did the following to get the Builder to generate the cc
file and compile it, but it doesnt clean the object
file.
import os
def cpp_emit(target,source, env):
for s in source:
print 'Emitter source: %s' % (s.name)
for t in target:
print 'Emitter target: %s' % (t)
return (target,source)
def build_function(target, source, env):
# Code to build "target" from "source"
for t in target:
print 'Builder target: %s' % (t.name)
for s in source:
print 'Builder source: %s' % (s.name)
buildStr='/home/notroot/projects/sandbox/Emitter/builder.sh %s %s' % (source[0].name, target[0].name)
os.system(buildStr)
trgt = env.Object(source=target[0])
# return 0 or None upon success
return None
# Tangle to .cc and .o
builder = Builder(
action=build_function,
suffix='.cc',
src_suffix='.nw',
emitter=cpp_emit)
env = Environment()
env['BUILDERS']['tangle'] = builder
tangleTarget = env.tangle(target='main.cc', source='main.nw')
Here is the output:
$ scons
scons: Reading SConscript files ...
Emitter source: main.nw
Emitter target: main.cc
scons: done reading SConscript files.
scons: Building targets ...
build_function(["main.cc"], ["main.nw"])
Builder target: main.cc
Builder source: main.nw
scons: done building targets.
$ scons -c
scons: Reading SConscript files ...
Emitter source: main.nw
Emitter target: main.cc
scons: done reading SConscript files.
scons: Cleaning targets ...
Removed main.cc
scons: done cleaning targets.
In this second example, if you add the object file as a target, you will get the following error (rightly so)
scons: *** [main.cc] Multiple ways to build the same target were specified for: main.o (from ['main.nw'] and from ['main.cc'])