-
-
Notifications
You must be signed in to change notification settings - Fork 341
Use scons as the default MSVSSCONS variable #4810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| # invoke scons. | ||
| if 'MSVSSCONS' not in env: | ||
| env['MSVSSCONS'] = '"%s" -c "%s"' % (python_executable, getExecScriptMain(env)) | ||
| env['MSVSSCONS'] = 'scons' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not this as well. MSVSSCONS is meant to override the existing mechanism explicitly, and not by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The right way to do this is to find the path to the scons being executed and use that, instead of defaulting to site-scons...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I got email with a comment about using sys.executable, and it doesn't show here on the PR page. Weird.
Anyway, sys.exectuable can be unset, according to the docu (can be emtpy string or None). I'm not sure the circumstances - odd packaging is one known cause (like a pyinstaller bundle) but maybe there are others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure. but people doing really silly things aren't generally worthy adding bunches of code for.. ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The right way to do this is to find the path to the scons being executed and use that, instead of defaulting to site-scons...
It seems like this is the intent, anyway. From the manpage:
MSVSSCONS- The SCons used in generated Microsoft Visual C++ project files. The default is the version of SCons being used to generate the project file.
In any case, the stanza used to figure out the value isn't updated for how a pip-installed scons is invoked ("console script", which is a little .exe made during packaging), so it could use some work. But that wasn't the case in the issue report, with the scoop install. Anyway, here's the comment from the msvs tool:
# This is how we re-invoke SCons from inside MSVS Project files.
# The problem is that we might have been invoked as either scons.bat
# or scons.py. If we were invoked directly as scons.py, then we could
# use sys.argv[0] to find the SCons "executable," but that doesn't work
# if we were invoked as scons.bat, which uses "python -c" to execute
# things and ends up with "-c" as sys.argv[0]. Consequently, we have
# the MSVS Project file invoke SCons the same way that scons.bat does,
# which works regardless of how we were invoked.
|
Feel free to ignore. In The following appears to work for the Scoop issue as reported. Not tested outside of this issue so unsure if it breaks other environment configurations. # This is how we re-invoke SCons from inside MSVS Project files.
# The problem is that we might have been invoked as either scons.bat
# or scons.py. If we were invoked directly as scons.py, then we could
# use sys.argv[0] to find the SCons "executable," but that doesn't work
# if we were invoked as scons.bat, which uses "python -c" to execute
# things and ends up with "-c" as sys.argv[0]. Consequently, we have
# the MSVS Project file invoke SCons the same way that scons.bat does,
# which works regardless of how we were invoked.
def getExecScriptMain(env, xml=None):
if 'SCONS_HOME' not in env:
env['SCONS_HOME'] = os.environ.get('SCONS_HOME')
scons_home = env.get('SCONS_HOME')
if not scons_home and 'SCONS_LIB_DIR' in os.environ:
scons_home = os.environ['SCONS_LIB_DIR']
+ if not scons_home:
+ scons_parent = os.path.abspath(os.path.join(os.path.dirname(SCons.__file__), ".."))
+ if os.path.exists(scons_parent):
+ scons_home = scons_parent
if scons_home:
exec_script_main = "from os.path import join; import sys; sys.path = [ r'%s' ] + sys.path; import SCons.Script; SCons.Script.main()" % scons_home
else:
version = SCons.__version__
exec_script_main = "from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-%(version)s'), join(sys.prefix, 'scons-%(version)s'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons') ] + sys.path; import SCons.Script; SCons.Script.main()" % locals()
if xml:
exec_script_main = xmlify(exec_script_main)
return exec_script_main |
|
|
|
FYI. Scoop configuration and call chain with python and SCons installed via scoop. System path elements: Scoop SCons call chain (
Scoop SCons layout ( |
|
How about |
|
Sure. Although, can't |
The |
|
scons_home has to be the parent directory of
I'm not convinced that A possible candidate solution: # This is how we re-invoke SCons from inside MSVS Project files.
# The problem is that we might have been invoked as either scons.bat
# or scons.py. If we were invoked directly as scons.py, then we could
# use sys.argv[0] to find the SCons "executable," but that doesn't work
# if we were invoked as scons.bat, which uses "python -c" to execute
# things and ends up with "-c" as sys.argv[0]. Consequently, we have
# the MSVS Project file invoke SCons the same way that scons.bat does,
# which works regardless of how we were invoked.
def getExecScriptMain(env, xml=None):
- if 'SCONS_HOME' not in env:
- env['SCONS_HOME'] = os.environ.get('SCONS_HOME')
- scons_home = env.get('SCONS_HOME')
- if not scons_home and 'SCONS_LIB_DIR' in os.environ:
- scons_home = os.environ['SCONS_LIB_DIR']
- if scons_home:
- exec_script_main = "from os.path import join; import sys; sys.path = [ r'%s' ] + sys.path; --import SCons.Script; SCons.Script.main()" % scons_home
- else:
- version = SCons.__version__
- exec_script_main = "from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-%(version)s'), join(sys.prefix, 'scons-%(version)s'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons') ] + sys.path; import SCons.Script; SCons.Script.main()" % locals()
+ scons_home = os.path.abspath(os.path.join(SCons.__path__[0], ".."))
+ exec_script_main = "from os.path import join; import sys; sys.path = [ r'%s' ] + sys.path; import SCons.Script; SCons.Script.main()" % scons_home
if xml:
exec_script_main = xmlify(exec_script_main)
return exec_script_mainEdit 1: There is no need for + scons_home = os.path.abspath(os.path.join(SCons.__path__[0], ".."))
+ exec_script_main = "import sys; sys.path = [ r'%s' ] + sys.path; import SCons.Script; SCons.Script.main()" % scons_home |
|
@jcbrill those two env vars have been there historically and a user could specify them as a system env and they should be respected if they're set. |
|
@bdbaddog Fair enough. Given that, the original proposed implementation (#4810 (comment)) is likely the most robust. |
|
Revised strawman proposal for consideration and/or discussion: def getExecScriptMain(env, xml=None):
if 'SCONS_HOME' not in env:
env['SCONS_HOME'] = os.environ.get('SCONS_HOME')
scons_home = env.get('SCONS_HOME')
if not scons_home and 'SCONS_LIB_DIR' in os.environ:
scons_home = os.environ['SCONS_LIB_DIR']
if scons_home:
exec_script_main = f"import sys; sys.path = [ r'{scons_home}' ] + sys.path; import SCons.Script; SCons.Script.main()"
else:
version = SCons.__version__
# *** ADDED SCONS PARENT PATH ***
scons_parent = os.path.abspath(os.path.join(os.path.dirname(SCons.__file__), ".."))
# *** ADDED SCONS PARENT PATH TO END OF THE PREFIX LIST ***
exec_script_main = f"from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-{version}'), join(sys.prefix, 'scons-{version}'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons'), r'{scons_parent}' ] + sys.path; import SCons.Script; SCons.Script.main()"
if xml:
exec_script_main = xmlify(exec_script_main)
return exec_script_mainChanges to the current SCons
Example generated vcxproj file contents:
|
Fixes #4809
Currently, the default value for
MSVSSCONSused to populate thevcxprojfile'sNMake*CommandLinelines, uses a rounadabout way to launch SCons. It launches python with-cand a string for the following python script:If the script can't find the
sconsmodule in the modifiedsys.pathit fails.It should be safe to assume that
sconsis (or at least should be) in the user's path; as it's needed to run theSConstructthat is used to create thevcxprojfile. However, ifsconsis not in the user's path, the user is free to modifyMSVSSCONSvariable to include the full path to theirscons.Therefore, this PR sets the default
MSVSSCONSvariable toscons, and removes the scaffolding used to create the previous default value.Contributor Checklist:
CHANGES.txtandRELEASE.txt(and read theREADME.rst).