You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MSVS: revise the vcxproj embedded python script contents
Changes:
* Revert setting SCONS_HOME in the testenv in runtest.py.
* Simplify the generated embedded python script.
* Simplified evaluation order:
1. If scons_home is defined:
* If SCons is not found using scons_home, display an error message and exit the embedded python script
2. If scons_abspath is defined:
* If SCons is not found using scons_abspath, display an error message and exit the embedded python script
3. Evaluate local library locations plus the python system path:
* If SCons is not found using the extended python system path, display an error message and exit the embedded python script
4. Add the found SCons path to the front of the python system path
5. Display the SCons path
6. Import and run SCons/Tool/msvs.py
from os.path import abspath, dirname, isdir, isfile, join, normcase, realpath
211
-
""",
212
-
# Initialize the generated paths:
213
-
# * convert scons_home to an absolute path,
214
-
# * clear scons_abspath when equal to the scons_home absolute path.
215
-
"""\
216
-
usrinit = lambda p: abspath(p) if p else p
217
-
geninit = lambda p, u: '' if (p and u and normcase(p) == normcase(u)) else p
218
-
usr_path = usrinit(r'{scons_home}')
219
-
gen_path = geninit(r'{scons_abspath}', usr_path)
220
-
""",
221
-
# Evaluate candidate lists:
222
-
# 1. If scons_home is defined:
223
-
# * Record scons_home as found iff the path contains SCons.
224
-
# * Stop evaluating remaining alternatives.
225
-
# 2. If scons_abspath is defined:
226
-
# * Record scons_abspath as found iff the path contains SCons.
227
-
# * Stop evaluating remaining alternatives.
228
-
# 3. Evaluate known library locations:
229
-
# * Record the first library path that contains SCons as found.
230
-
"""\
231
-
state = {{}}
232
-
isvalid = lambda p: p and isdir(p) and isfile(join(p, 'SCons', '__init__.py'))
233
-
store = lambda k, l, s: {{k: l[0], 'Found': l[0], 'Stop': True}} if l else {{k: '', 'Stop': s}}
234
-
check = lambda k, l, s: state.update(store(k, [p for p in l if isvalid(p)], s)) if not state.get('Stop') else None
235
-
_ = [check(k, l, s) for k, l, s in [('usr', [usr_path], bool(usr_path)), ('gen', [gen_path], bool(gen_path)), ('lib', [join(sys.prefix, *t) for t in [('Lib', 'site-packages', 'scons-{scons_version}'), ('scons-{scons_version}',), ('Lib', 'site-packages', 'scons'), ('scons',), ('Lib', 'site-packages')]], False)]]
236
-
""",
237
-
# If an SCons module path was found, add the path to the front of
238
-
# the sys.path list.
239
-
"""\
240
-
path = state.get('Found', '')
241
-
_ = sys.path.insert(0, path) if path else None
242
-
""",
243
-
# Use importlib to find the SCons module path prior to import.
244
-
# Add a valid module spec origin path to the front of the sys.path list if:
245
-
# * a module path was not found earlier, or
246
-
# * the module spec origin path is different than the module
247
-
# path found earlier.
248
-
"""\
203
+
from os.path import abspath, dirname, isdir, isfile, join, realpath
204
+
usr_path = r'{scons_home}'
205
+
gen_path = r'{scons_abspath}'
206
+
syspath = sys.path
207
+
search, path = ([usr_path], usr_path) if usr_path else ([gen_path], gen_path) if gen_path else ([join(sys.prefix, *t) for t in [('Lib', 'site-packages', 'scons-{scons_version}'), ('scons-{scons_version}',), ('Lib', 'site-packages', 'scons'), ('scons',), ('Lib', 'site-packages')]] + sys.path, None)
208
+
sys.path = search
249
209
spec = importlib.util.find_spec('SCons')
250
210
orig = dirname(dirname(abspath(spec.origin))) if (spec and spec.origin) else ''
251
-
syspath = orig and (not path or normcase(abspath(path)) != normcase(orig))
252
-
_ = sys.path.insert(0, orig) if syspath else None
253
-
""",
254
-
# Display diagnostic messages.
255
-
"""\
256
-
_ = print(f'proj: *** SCons not found at user path \\\'{{usr_path}}\\\'. ***') if (usr_path and state.get('usr') == '') else None
257
-
_ = print(f'proj: *** SCons not found at generated path \\\'{{gen_path}}\\\' ***.') if (gen_path and state.get('gen') == '') else None
258
-
_ = print( 'proj: *** SCons not found. ***') if (not orig) else None
259
-
""",
260
-
# Display SCons module path (if found).
261
-
"""\
262
-
_ = print(f'proj: Using SCons path \\\'{{orig}}\\\' (realpath=\\\'{{realpath(orig)}}\\\', syspath={{syspath}}).') if (orig) else None
263
-
""",
264
-
# Import SCons and run main script.
265
-
"""\
211
+
sys.path = [orig] + syspath if orig else syspath
212
+
_ = print(f'proj: Using SCons path \\\'{{orig}}\\\' (realpath=\\\'{{realpath(orig)}}\\\').') if orig else (print(f'proj: Error: SCons not found (path=\\\'{{path if path else search}}\\\').'), sys.exit(1))
from os.path import abspath, dirname, isdir, isfile, join, normcase, realpath
880
-
usrinit = lambda p: abspath(p) if p else p
881
-
geninit = lambda p, u: '' if (p and u and normcase(p) == normcase(u)) else p
882
-
usr_path = usrinit(r'{scons_home}')
883
-
gen_path = geninit(r'{scons_abspath}', usr_path)
884
-
state = {{}}
885
-
isvalid = lambda p: p and isdir(p) and isfile(join(p, 'SCons', '__init__.py'))
886
-
store = lambda k, l, s: {{k: l[0], 'Found': l[0], 'Stop': True}} if l else {{k: '', 'Stop': s}}
887
-
check = lambda k, l, s: state.update(store(k, [p for p in l if isvalid(p)], s)) if not state.get('Stop') else None
888
-
_ = [check(k, l, s) for k, l, s in [('usr', [usr_path], bool(usr_path)), ('gen', [gen_path], bool(gen_path)), ('lib', [join(sys.prefix, *t) for t in [('Lib', 'site-packages', 'scons-{scons_version}'), ('scons-{scons_version}',), ('Lib', 'site-packages', 'scons'), ('scons',), ('Lib', 'site-packages')]], False)]]
889
-
path = state.get('Found', '')
890
-
_ = sys.path.insert(0, path) if path else None
877
+
from os.path import abspath, dirname, isdir, isfile, join, realpath
878
+
usr_path = r'{scons_home}'
879
+
gen_path = r'{scons_abspath}'
880
+
syspath = sys.path
881
+
search, path = ([usr_path], usr_path) if usr_path else ([gen_path], gen_path) if gen_path else ([join(sys.prefix, *t) for t in [('Lib', 'site-packages', 'scons-{scons_version}'), ('scons-{scons_version}',), ('Lib', 'site-packages', 'scons'), ('scons',), ('Lib', 'site-packages')]] + sys.path, None)
882
+
sys.path = search
891
883
spec = importlib.util.find_spec('SCons')
892
884
orig = dirname(dirname(abspath(spec.origin))) if (spec and spec.origin) else ''
893
-
syspath = orig and (not path or normcase(abspath(path)) != normcase(orig))
894
-
_ = sys.path.insert(0, orig) if syspath else None
895
-
_ = print(f'proj: *** SCons not found at user path \\\'{{usr_path}}\\\'. ***') if (usr_path and state.get('usr') == '') else None
896
-
_ = print(f'proj: *** SCons not found at generated path \\\'{{gen_path}}\\\' ***.') if (gen_path and state.get('gen') == '') else None
897
-
_ = print( 'proj: *** SCons not found. ***') if (not orig) else None
898
-
_ = print(f'proj: Using SCons path \\\'{{orig}}\\\' (realpath=\\\'{{realpath(orig)}}\\\', syspath={{syspath}}).') if (orig) else None
885
+
sys.path = [orig] + syspath if orig else syspath
886
+
_ = print(f'proj: Using SCons path \\\'{{orig}}\\\' (realpath=\\\'{{realpath(orig)}}\\\').') if orig else (print(f'proj: Error: SCons not found (path=\\\'{{path if path else search}}\\\').'), sys.exit(1))
0 commit comments