summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMats Wichmann <mats@linux.com>2021-03-22 11:23:27 (GMT)
committerMats Wichmann <mats@linux.com>2021-03-25 17:32:40 (GMT)
commitc64d54997bd6c5806acf7dba080328307dd54b83 (patch)
tree3bcd888f6cbdce4ae76ca4e08e0cc0b3166352a8
parent3b76802eacddcaff4bff02d07cf9def05741a3d4 (diff)
downloadSCons-c64d54997bd6c5806acf7dba080328307dd54b83.zip
SCons-c64d54997bd6c5806acf7dba080328307dd54b83.tar.gz
SCons-c64d54997bd6c5806acf7dba080328307dd54b83.tar.bz2
Change site-dir arg handling
chat discussion: this should work to not use a site_dir: $ export SCONSFLAGS=--site-dir=foo $ scons --no-site-dir Commit changes the two options to write to the same variable, so "last one on command line wins" works out. Added a test for this to test/site_scons/site-dir.py. Manpage updated to clarify the order of considering SCONSFLAGS, since order does matter. Signed-off-by: Mats Wichmann <mats@linux.com>
-rw-r--r--SCons/Script/Main.py10
-rw-r--r--SCons/Script/SConsOptions.py4
-rw-r--r--doc/man/scons.xml14
-rw-r--r--test/site_scons/basic.py7
-rw-r--r--test/site_scons/no-site-dir.py7
-rw-r--r--test/site_scons/nonexistent.py7
-rw-r--r--test/site_scons/override.py7
-rw-r--r--test/site_scons/site-dir.py66
-rw-r--r--test/site_scons/site_init.py9
-rw-r--r--test/site_scons/sys-path.py7
-rw-r--r--test/site_scons/sysdirs.py4
11 files changed, 87 insertions, 55 deletions
diff --git a/SCons/Script/Main.py b/SCons/Script/Main.py
index c1bb016..6285d4a 100644
--- a/SCons/Script/Main.py
+++ b/SCons/Script/Main.py
@@ -775,7 +775,7 @@ def _load_site_scons_dir(topdir, site_dir_name=None):
raise
-def _load_all_site_scons_dirs(topdir, verbose=None):
+def _load_all_site_scons_dirs(topdir, verbose=False):
"""Load all of the predefined site_scons dir.
Order is significant; we load them in order from most generic
(machine-wide) to most specific (topdir).
@@ -968,10 +968,12 @@ def _main(parser):
if options.no_progress or options.silent:
progress_display.set_mode(0)
- if options.site_dir:
- _load_site_scons_dir(d.get_internal_path(), options.site_dir)
- elif not options.no_site_dir:
+ # if site_dir unchanged from default None, neither --site-dir
+ # nor --no-site-dir was seen, use SCons default
+ if options.site_dir is None:
_load_all_site_scons_dirs(d.get_internal_path())
+ elif options.site_dir: # if a dir was set, use it
+ _load_site_scons_dir(d.get_internal_path(), options.site_dir)
if options.include_dir:
sys.path = options.include_dir + sys.path
diff --git a/SCons/Script/SConsOptions.py b/SCons/Script/SConsOptions.py
index e7e4777..cfc8ccb 100644
--- a/SCons/Script/SConsOptions.py
+++ b/SCons/Script/SConsOptions.py
@@ -801,8 +801,8 @@ def Parser(version):
help="Don't build; just print commands.")
op.add_option('--no-site-dir',
- dest='no_site_dir', default=False,
- action="store_true",
+ dest='site_dir',
+ action="store_false",
help="Don't search or use the usual site_scons dir.")
op.add_option('--profile',
diff --git a/doc/man/scons.xml b/doc/man/scons.xml
index 4ec1ecc..bc3f9a5 100644
--- a/doc/man/scons.xml
+++ b/doc/man/scons.xml
@@ -7750,8 +7750,14 @@ release, it may be necessary to specify
<varlistentry id="v-SCONSFLAGS">
<term><envar>SCONSFLAGS</envar></term>
<listitem>
-<para>A string of options that will be used by &scons;
-in addition to those passed on the command line.</para>
+<para>A string containing options that will be used by &scons;
+in addition to those passed on the command line.
+Can be used to reduce frequent retyping of common options.
+The contents of <envar>SCONSFLAGS</envar> are considered
+before any passed command line options,
+so the command line can be used to override
+<envar>SCONSFLAGS</envar> options if necessary.
+</para>
</listitem>
</varlistentry>
@@ -7760,8 +7766,8 @@ in addition to those passed on the command line.</para>
<listitem>
<para>(Windows only). If set, save the shell environment variables
generated when setting up the Microsoft Visual C++ compiler
-(and/or Build Tools) to a file to give these settings,
-which are expensive to generate, persistence
+(and/or Build Tools) to a cache file, to give these settings,
+which are relatively expensive to generate, persistence
across &scons; invocations.
Use of this option is primarily intended to aid performance
in tightly controlled Continuous Integration setups.</para>
diff --git a/test/site_scons/basic.py b/test/site_scons/basic.py
index b3ae9f2..ea6bca6 100644
--- a/test/site_scons/basic.py
+++ b/test/site_scons/basic.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
-# __COPYRIGHT__
+# MIT License
+#
+# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -20,9 +22,6 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-
-__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import TestSCons
diff --git a/test/site_scons/no-site-dir.py b/test/site_scons/no-site-dir.py
index c31ec94..a8477ee 100644
--- a/test/site_scons/no-site-dir.py
+++ b/test/site_scons/no-site-dir.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
-# __COPYRIGHT__
+# MIT License
+#
+# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -20,9 +22,6 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-
-__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
"""
Verify use of the --no-site-dir option:
diff --git a/test/site_scons/nonexistent.py b/test/site_scons/nonexistent.py
index 6617ff2..5ed14cb 100644
--- a/test/site_scons/nonexistent.py
+++ b/test/site_scons/nonexistent.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
-# __COPYRIGHT__
+# MIT License
+#
+# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -20,9 +22,6 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-
-__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
"""
Verify that specifying --site-dir= with a nonexistent directory
diff --git a/test/site_scons/override.py b/test/site_scons/override.py
index d65c09e..e564547 100644
--- a/test/site_scons/override.py
+++ b/test/site_scons/override.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
-# __COPYRIGHT__
+# MIT License
+#
+# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -20,9 +22,6 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-
-__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
"""
diff --git a/test/site_scons/site-dir.py b/test/site_scons/site-dir.py
index d60e7d9..97a3efe 100644
--- a/test/site_scons/site-dir.py
+++ b/test/site_scons/site-dir.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
-# __COPYRIGHT__
+# MIT License
+#
+# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -20,52 +22,78 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-
-__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
"""
-Verify that --site-dir=otherdir loads the site_init.py script
-from the other dir;
+Verify that --site-dir=otherdir loads the site_init.py script from otherdir;
the usual site_scons/site_init.py should NOT be loaded.
+Check that a later --no-site-dir turns off site-dir processing
+even if a --site-dir option was seen earlier.
"""
+import os
+
import TestSCons
test = TestSCons.TestSCons()
test.subdir('site_scons', ['site_scons', 'site_tools'])
-test.write(['site_scons', 'site_init.py'], """
+test.write(
+ ['site_scons', 'site_init.py'],
+ """
from SCons.Script import *
print("Hi there, I am in site_scons/site_init.py!")
-""")
+""",
+)
-test.write(['site_scons', 'site_tools', 'mytool.py'], """
+test.write(
+ ['site_scons', 'site_tools', 'mytool.py'],
+ """
import SCons.Tool
def generate(env):
env['MYTOOL']='mytool'
def exists(env):
return 1
-""")
-
-
+""",
+)
test.subdir('alt_site', ['alt_site', 'site_tools'])
-test.write(['alt_site', 'site_init.py'], """
+test.write(
+ ['alt_site', 'site_init.py'],
+ """
from SCons.Script import *
print("Hi there, I am in alt_site/site_init.py!")
-""")
+""",
+)
-test.write('SConstruct', """
+test.write(
+ 'SConstruct',
+ """
e=Environment()
-""")
+""",
+)
+
+test.run(
+ arguments='-Q --site-dir=alt_site .',
+ stdout="""Hi there, I am in alt_site/site_init.py!
+scons: `.' is up to date.\n""",
+)
+
+
+# --site-dir followed by --no-site-dir turns processing off:
+test.run(
+ arguments="-Q --site-dir=alt_site --no-site-dir .",
+ stdout="""scons: `.' is up to date.\n""",
+)
-test.run(arguments = '-Q --site-dir=alt_site .',
- stdout = """Hi there, I am in alt_site/site_init.py!
-scons: `.' is up to date.\n""")
+# same test, but using SCONSFLAGS
+os.environ["SCONSFLAGS"] = "-Q --site-dir=alt_site"
+test.run(
+ arguments="--no-site-dir .",
+ stdout="""scons: `.' is up to date.\n""",
+)
test.pass_test()
diff --git a/test/site_scons/site_init.py b/test/site_scons/site_init.py
index e21b5f2..743efa7 100644
--- a/test/site_scons/site_init.py
+++ b/test/site_scons/site_init.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
-# __COPYRIGHT__
+# MIT License
+#
+# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -20,9 +22,6 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-
-__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
"""
Verify various aspects of the handling of site_init.py.
@@ -41,7 +40,7 @@ test.subdir('site_scons')
def _test_metadata():
"""Test site_init's module metadata.
-
+
The following special variables should be predefined: __doc__,
__file__ and __name__. No special variables should be transferred from
SCons.Script.
diff --git a/test/site_scons/sys-path.py b/test/site_scons/sys-path.py
index 40783ff..68473ca 100644
--- a/test/site_scons/sys-path.py
+++ b/test/site_scons/sys-path.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
-# __COPYRIGHT__
+# MIT License
+#
+# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -20,9 +22,6 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-
-__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
"""
Verify that the site_scons dir is added to sys.path as an
diff --git a/test/site_scons/sysdirs.py b/test/site_scons/sysdirs.py
index 61f9c02..d623ab2 100644
--- a/test/site_scons/sysdirs.py
+++ b/test/site_scons/sysdirs.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
-# __COPYRIGHT__
+# MIT License
+#
+# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the