Skip to content

Specifying PCH source on main build sources causes explosions #2505

Closed

Description

@bdbaddog

This issue was originally created at: 2009-10-27 13:21:10.
This issue was reported by: coppro.

coppro said at 2009-10-27 13:21:10

On 1.2.0.d20090919 (no appropriate version entry on the issue tracker), specifying a source file both as your PCH source file and on a main build line causes SCons to see a circular dependency that isn't there, and possibly more errors on bigger projects. It also refuses to build the targets. Sample:

env = Environment()
env['PCH'] = env.PCH('Source1.cpp')
env['PCHSTOP'] = 'Header1.hpp'
env.Program('foo', ['Source2.cpp', 'Source1.cpp']) 

Ideally, SCons would just notice that Source1.cpp is repeated and ignore it (because it's not worth the headache of removing that file from a Glob()). Failing that, it should at least fail gracefully rather than refusing to build the target with unhelpful error messages.

bdbaddog said at 2009-10-27 13:28:04

Updated version (added version : 1.2.0.d20090919 as valid version in issue tracker)

stevenknight said at 2009-12-15 17:34:15

SK to research, if not fixable quickly then 2.1 p3

stevenknight said at 2009-12-15 18:11:57

actually assign to SK

stevenknight said at 2010-01-06 11:35:21

I think I have a solution, although it's kind of fragile (as is our PCH support in general).

First, there's a slight problem in the supplied test case, although the problem is masked by the dependency cycle error. The actual documented way to use env.PCH() is to extract the 0th element from the returned list, like so:

    env['PCH'] = env.PCH('Source1.cpp')[0]

env.PCH() returns both the .pch and the .obj file generated by the compilation, and unless you set env['PCH'] to just the .pch file, the link blows up when it tries to expand $PCH in $CCPCHFLAGS and gets ... /Fp['Source1.pch', 'Source1.obj'] ..." in a command line.

(Yeah, having to select the element by hand sucks, but that's the current reality.)

Trying to have the $CCPCHFLAGS expansion detect the list and use just the .pch file is really hairy and doesn't look worthwhile.

The fix (?) is to have the object_emitter() realize that the base names of Source1.pch and Source1.obj match, assume that this means they're actually being generated by the same call to env.PCH(), and to then avoid adding the explicit .obj => .pch dependency. That assumption feels a little risky, but only a little, because to construct a configuration that breaks the assumption would require something like checking in a source file named Source1.pch and setting env['PCH'] by hand, instead of using the env.PCH() builder.

If it turns out that there really are cases like this out in the wild, then the fix for that would probably be to have the pch_emitter() turn the .pch file into a Node.File object and annotate that object with a flag that says, "Yeah, I was generated by env.PCH(), so don't add me as a dependency to any same-named .obj file that you try to build." That doesn't seem worth the trouble to code, but I'll add a pointer to this issue in a comment there in case it happens.

stevenknight said at 2010-01-06 13:56:29

Fixed in r4596:

https://scons.tigris.org/source/browse/scons?view=rev&revision=4596 (dead link)

Probably not going to be in 1.3 (train's basically left the station), and 2.0 is going to be minimal (drop backwards compatibility with old Python versions). Marking this for 2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions