From 691afa1d6e679513dc9a7f2d2c279c923a343c48 Mon Sep 17 00:00:00 2001 From: Daniel Moody Date: Thu, 4 Jun 2020 22:16:59 -0400 Subject: added is_sconscript for checking if node is a sconscript node or not --- CHANGES.txt | 3 +++ SCons/Node/NodeTests.py | 13 +++++++++++++ SCons/Node/__init__.py | 7 +++++++ SCons/Script/SConscript.py | 3 ++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index ecf3255..45899ad 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -15,6 +15,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER SConstruct/SConscript will still cause "scons: Reading SConscript files ..." to be printed, since the option is not set when the build scripts first get read. - Added check for SONAME in environment to setup symlinks correctly (Github Issue #3246) + - Added storage of SConstructs and SConscripts nodes into global set for checking + if a given node is a SConstruct/SConscript. + Added new node function SCons.Node.is_sconscript(self) (Github Issue #3625) From James Benton: - Improve Visual Studio solution/project generation code to add support diff --git a/SCons/Node/NodeTests.py b/SCons/Node/NodeTests.py index 2ea22ed..f09d367 100644 --- a/SCons/Node/NodeTests.py +++ b/SCons/Node/NodeTests.py @@ -1244,6 +1244,19 @@ class NodeTestCase(unittest.TestCase): n=SCons.Node.Node() assert n.is_literal() + def test_sconscripts(self): + """Test the is_sconscript() function.""" + # check nodes are not sconscript unless added to the list + n=SCons.Node.Node() + n2=SCons.Node.Node() + assert not n.is_sconscript() + assert not n2.is_sconscript() + + # add node to sconscript list and verify + SCons.Node.SConscriptNodes.add(n2) + assert not n.is_sconscript() + assert n2.is_sconscript() + def test_Annotate(self): """Test using an interface-specific Annotate function.""" def my_annotate(node, self=self): diff --git a/SCons/Node/__init__.py b/SCons/Node/__init__.py index e084610..82bb715 100644 --- a/SCons/Node/__init__.py +++ b/SCons/Node/__init__.py @@ -111,6 +111,9 @@ def do_nothing_node(node): pass Annotate = do_nothing_node +# global set for recording all processed SContruct/SConscript nodes +SConscriptNodes = set() + # Gets set to 'True' if we're running in interactive mode. Is # currently used to release parts of a target's info during # clean builds and update runs (see release_target_info). @@ -946,6 +949,10 @@ class Node(object, metaclass=NoSlotsPyPy): """ return _is_derived_map[self._func_is_derived](self) + def is_sconscript(self): + """ Returns true if this node is an sconscript """ + return self in SConscriptNodes + def alter_targets(self): """Return a list of alternate targets for this Node. """ diff --git a/SCons/Script/SConscript.py b/SCons/Script/SConscript.py index b380dca..309bed3 100644 --- a/SCons/Script/SConscript.py +++ b/SCons/Script/SConscript.py @@ -43,7 +43,7 @@ import SCons.SConf import SCons.Script.Main import SCons.Tool from SCons.Util import is_List, is_String, is_Dict, flatten - +from SCons.Node import SConscriptNodes from . import Main import collections @@ -202,6 +202,7 @@ def _SConscript(fs, *files, **kw): else: f = fs.File(str(fn)) _file_ = None + SConscriptNodes.add(f) # Change directory to the top of the source # tree to make sure the os's cwd and the cwd of -- cgit v0.12