[Scons-users] finding out which env causes this error: Two different environments were specified for target

Dominic Binks dominic.binks at thebinkles.net
Fri Mar 25 14:18:21 EDT 2022


Hi Dagg,

I've found the biggest problem with this issue is trying to find out 
where the duplication is arriving from.

To this end, I've created a small function:

def check_for_problem_file(env, scons_nodes, needle_re):
   nodes = env.Flatten([scons_nodes])
   for n in nodes:
     if re.match(needle_re, str(n)):
       print("Filename match {} against {}".format(n, needle_re))
       print_stack()

needle_re is a regular expression and a stack trace is printed whenever 
the regular expression matches the name of a file that is passed in via 
the scons_nodes.

The other part to this is to have a replacement for the function that 
seems to be giving rise to the duplicate entries.  You've identified 
that InstallAs does this, so if you wrap the real InstallAs inside a 
MyInstallAs method, then you can call check_for_problem_file with the 
name of the file that is seeing the duplicate environment to figure out 
where the two environments are originating from.

It's then not too difficult (usually) to eliminate the duplication.

While it's a bit crude, it's proved quite good at helping to eliminate 
(most) of our duplicate environment warnings.

Dominic

On 25/03/2022 17:50, Mats Wichmann wrote:
> On 3/25/22 11:14, daggs wrote:
>>
>>
>>> Sent: Friday, March 25, 2022 at 8:02 PM
>>> From: "Mats Wichmann" <mats at wichmann.us>
>>> To: "daggs" <daggs at gmx.com>
>>> Cc: "SCons users mailing list" <scons-users at scons.org>
>>> Subject: Re: [Scons-users] finding out which env causes this error: Two different environments were specified for target
>>>
>>> On 3/25/22 09:40, daggs wrote:
>>>>
>>>>
>>>>> Sent: Friday, March 25, 2022 at 6:26 PM
>>>>> From: "Mats Wichmann" <mats at wichmann.us>
>>>>> To: "daggs" <daggs at gmx.com>
>>>>> Cc: "SCons users mailing list" <scons-users at scons.org>
>>>>> Subject: Re: [Scons-users] finding out which env causes this error: Two different environments were specified for target
>>>>>
>>>>> On 3/25/22 09:23, daggs wrote:
>>>>>
>>>>>> I do something like this:
>>>>>> for folder in [ a, b, c ]:
>>>>>>      for modes in [ y. z ]:
>>>>>>          export('mode')
>>>>>>          sconscript("src/" + folder + "/SConscript", variant_dir = "out/" + folder + "." + mode, duplicate = 0. export('env'))
>>>>>>
>>>>>> the issue occurs when I define InstallAs in folder b
>>>>>> if I remove it and add prints to the targets, I see them all ok.
>>>>>
>>>>> And what target is defined by the InstallAs call?
>>>>>
>>>>>
>>>>
>>>> "tgt/" + folder + "." + mode + "/" + bin where bin differs for each folder
>>>
>>> Okay, you're saying that you've commented out the InstallAs calls and it
>>> works, but you've printed what the targets would have been for those and
>>> they look suitably unique?  Or is my reparsing of the comment from your
>>> earlier message wrong?
>>>
>>> If so, it seems you've proven where the problem comes from (InstallAs)
>>> and maybe SCons is interpreting that path differently than the pure
>>> Python string comes out?
>>>
>>
>> I'll try to make it clearer, as I pre define the targets, I can print them.
>> when I run scons in dry run mode for targets a.y and a.z, I see the dep tree properly. it has a installAs call.
>> when I do the same for b.z and b.y with the installAs call, I get two envs error with b.y.
>> if I remove the installAs in b and prints the targets, I see no problems in the installAs target dst.
> 
>  From the information here, nothing jumps out.  I'd run with just the "a"
> targets first, capture that tree output; then run with just the "b"
> targets and capture that and do a side-by-side comparison of what you
> got and see if there are any surprises.
> 
> Issue 2769 suggests from a discussion in the mailing list (the tigris
> links are dead so they're no use for prospecting purposes) that calling
> the same sconscript twice was the cause of a problem. You do that,
> intentionally, so maybe we're looking for it getting called the same way
> twice through some accident?
> 
> 
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users


More information about the Scons-users mailing list