tags:

views:

565

answers:

2

In a SCons script I create a base environment from which I derived others environments. Something like this :

base = Environment()
base['CXXFLAGS'] += ['-DBOOST_HAS_PTHREAD', '-D__STDC_CONSTANT_MACROS', '-DFILELOG_MAX_LEVEL=4', '-Wall']

opt = base.Clone()
opt['CXXFLAGS'] += ['-DNDEBUG', '-O3']

This way, I can create more environment (release/debug/instrumented/pgo) from the base environment. In the SCons documentation it's said that env.Clone() does a deep copy of env. But in fact it doesn't seem to work. because in the example, the base environment would have the -DNDEBUG and -O3 flags applied.

A I doing something wrong?

edit : Here is the real code. There is two print statements in this code and I think they should print the same things, but they don't. The output follows:

# -*- coding: utf-8 -*-

import os.path
import glob

local_env = Environment()

local_env['CXXFLAGS'] += ['-DBOOST_HAS_PTHREAD', '-D__STDC_CONSTANT_MACROS', '-DFILELOG_MAX_LEVEL=4', '-Wall']
local_env.Append(LIBS = ['pthread', 'boost_thread', 'boost_filesystem', 'boost_program_options', 'boost_iostreams'])

opt = local_env.Clone()

opt['CXXFLAGS'] += ['-DNDEBUG', '-O3']

print opt['CXXFLAGS']

instr = opt.Clone()
instr['CXXFLAGS'] += ['-fprofile-arcs']
instr['LIBS'] += ['gcov']

print opt['CXXFLAGS']

The output :

|| scons: Reading SConscript files ...
|| -DBOOST_HAS_PTHREAD -D__STDC_CONSTANT_MACROS -DFILELOG_MAX_LEVEL=4 -Wall -DNDEBUG -O3
|| -DBOOST_HAS_PTHREAD -D__STDC_CONSTANT_MACROS -DFILELOG_MAX_LEVEL=4 -Wall -DNDEBUG -O3 -fprofile-arcs
|| scons: done reading SConscript files.
|| scons: Building targets ...
|| scons: `.' is up to date.
|| scons: done building targets.

Edit 2:

It's a bug with SCons http://scons.tigris.org/issues/show_bug.cgi?id=2390

Edit 3:

Will be fixed in 1.3.1 and 2.0.1

+1  A: 

Assuming this is a Scons issue (code/docs discrepancy), what about adding

import copy

at the script's head, and using

opt = copy.deepcopy(Base)

i.e exploiting the fact that Scons is in Python...?

Alex Martelli
+1  A: 

I faced this today, and it seems like an SCons bug. Things used to work.

Facing this on: Ubuntu 9.04 x64, Python 2.6.2, SCons v1.2.0.r3842

Presuming it is a change of API between 0.9.8 and 1.2.0 here is how to overcome it.

Was:

  e2= env.Clone()
  e2["CXXFLAGS"].remove( "-Werror" )
  e2["CXXFLAGS"].append( "-Wno-error" )

Now (1.2.0):

  import copy
  ...
  e2= env.Clone( CXXFLAGS= copy.deepcopy(env["CXXFLAGS"]) )
  e2["CXXFLAGS"].remove( "-Werror" )
  e2.AppendUnique( CXXFLAGS= "-Wno-error" )

Note that using the .Append() or .AppendUnique() methods treats the lists separately, not changing the original source. However, there does not seem to be such a method to remove a particular item from a list. This is why the '.remove()' is needed and that causes the headache.

Suggestions for easier methods or a pointer to knowing wheather this is a bug or feature of SCons 1.2.0 would be welcome.

akauppi
Hi, I found a reference to this bug in the scons issue tracker (http://scons.tigris.org/issues/show_bug.cgi?id=2390). It seems that the developpers are not able to reproduce the bug, so they marked it as RESOLVED.
Mathieu Pagé
The bug is reopened and hopefully will be fixed in the next releases.
techtonik