diff options
author | William Deegan <bill@baddogconsulting.com> | 2021-03-25 22:16:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-25 22:16:36 (GMT) |
commit | c8741ddac56f76944ee25e1b8bc54e0559db852b (patch) | |
tree | 94a408b4afa0b70a5bf1b3e86b71cacb8f8b98e3 | |
parent | 9b28bb2dffad91b73b33637515f4d8defebc6679 (diff) | |
parent | 0be25011f71743605192d58737c961ff634a8e4c (diff) | |
download | SCons-c8741ddac56f76944ee25e1b8bc54e0559db852b.zip SCons-c8741ddac56f76944ee25e1b8bc54e0559db852b.tar.gz SCons-c8741ddac56f76944ee25e1b8bc54e0559db852b.tar.bz2 |
Merge pull request #3910 from mwichmann/site-dir
Change site-dir arg handling
-rwxr-xr-x | CHANGES.txt | 2 | ||||
-rw-r--r-- | SCons/Script/Main.py | 10 | ||||
-rw-r--r-- | SCons/Script/SConsOptions.py | 4 | ||||
-rw-r--r-- | doc/man/scons.xml | 14 | ||||
-rw-r--r-- | test/site_scons/basic.py | 7 | ||||
-rw-r--r-- | test/site_scons/no-site-dir.py | 7 | ||||
-rw-r--r-- | test/site_scons/nonexistent.py | 7 | ||||
-rw-r--r-- | test/site_scons/override.py | 7 | ||||
-rw-r--r-- | test/site_scons/site-dir.py | 66 | ||||
-rw-r--r-- | test/site_scons/site_init.py | 9 | ||||
-rw-r--r-- | test/site_scons/sys-path.py | 7 | ||||
-rw-r--r-- | test/site_scons/sysdirs.py | 4 |
12 files changed, 89 insertions, 55 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index eeaeaba..6c5feea 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -39,6 +39,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER which is the Python recommended way for timing short durations. - Drop remaining definitions of dict-like has_key methods, since Python 3 doesn't have a dictionary has_key (maintenance) + - Do not treat --site-dir=DIR and --no-site-dir as distinct options. + Allows a later instance to override an earlier one. - Ignore empty cmdline arguments when computing targets (issue 2986) diff --git a/SCons/Script/Main.py b/SCons/Script/Main.py index 80124be..59ffbb7 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 |