Skip to content

Commit 4152e16

Browse files
committed
Fixes SCons#2801. Undefined variable value yields '.' as node and may cause rermoving all files in tree.
1 parent a25f3ec commit 4152e16

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

CHANGES.txt

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
1717
"Multiple ways to build the same target were specified for:". Now mingw will disable
1818
creating the symlinks (and adding version string to ) dlls. It sets SHLIBNOVERSIONSYMLINKS,
1919
IMPLIBNOVERSIONSYMLINKS and LDMODULENOVERSIONSYMLINKS to True.
20+
- Fix Issue #2801 - Handle calling Clean('$XYZ','$ABC') when either env['XYZ'] or env['ABC']
21+
is undefined as that would yield either argument as '.'. This will lead to cleaning the wrong
22+
(or all) files potentially when you request the wrong (or any target).
23+
2024

2125
From Daniel Moody:
2226
- Update CacheDir to use uuid for tmpfile uniqueness instead of pid.

SCons/Environment.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@
3232

3333
import copy
3434
import os
35-
import sys
3635
import re
3736
import shlex
37+
import sys
3838
from collections import UserDict
3939

4040
import SCons.Action
4141
import SCons.Builder
4242
import SCons.Debug
43-
from SCons.Debug import logInstanceCreation
4443
import SCons.Defaults
45-
from SCons.Errors import UserError, BuildError
4644
import SCons.Memoize
4745
import SCons.Node
4846
import SCons.Node.Alias
@@ -54,6 +52,8 @@
5452
import SCons.Subst
5553
import SCons.Tool
5654
import SCons.Warnings
55+
from SCons.Debug import logInstanceCreation
56+
from SCons.Errors import UserError, BuildError
5757
from SCons.Util import (
5858
AppendPath,
5959
CLVar,
@@ -74,6 +74,7 @@
7474
uniquer_hashables,
7575
)
7676

77+
7778
class _Null:
7879
pass
7980

@@ -2000,6 +2001,17 @@ def CacheDir(self, path):
20002001

20012002
def Clean(self, targets, files):
20022003
global CleanTargets
2004+
2005+
# Check for anything which evaluates to empty string, which would yield cleaning '.'
2006+
targets_strings = [(t, self.subst(t)) for t in flatten(targets) if is_String(t) and ('$' in t or t == '')]
2007+
files_strings = [(t, self.subst(t)) for t in flatten(files) if is_String(t) and ('$' in t or t == '')]
2008+
if any([s=='' for t,s in targets_strings]):
2009+
raise UserError("Targets specified to Clean() include on which evaluates to an empty string: [%s]" % ",".join(
2010+
["%s='%s'"%(str(t),s) for (t, s) in targets_strings]))
2011+
if any([s=='' for t,s in files_strings]):
2012+
raise UserError("Targets specified to Clean() include on which evaluates to an empty string: [%s]" % ",".join(
2013+
["%s='%s'"%(str(t),s) for (t, s) in files_strings]))
2014+
20032015
tlist = self.arg2nodes(targets, self.fs.Entry)
20042016
flist = self.arg2nodes(files, self.fs.Entry)
20052017
for t in tlist:

0 commit comments

Comments
 (0)