Skip to content

Commit 1f73a94

Browse files
Make sure -E is used and fix scripts on unix
Signed-off-by: Jean-Christophe Morin <[email protected]>
1 parent 09bcf25 commit 1f73a94

File tree

5 files changed

+63
-31
lines changed

5 files changed

+63
-31
lines changed

.github/workflows/wheel.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
cp distlib/PC/launcher.c launcher/
3030
3131
cd launcher
32-
patch -Np1 -i remote-appended.patch --binary
32+
patch -Np1 -i rez.patch --binary
3333
3434
mkdir build
3535
cd build
@@ -85,6 +85,8 @@ jobs:
8585
set -ex
8686
cat .venv/Scripts/rez/rez-script.py
8787
cat .venv/Scripts/rez/jctest-script.py
88+
89+
echo 'Running jctest with REZ_LAUNCHER_DEBUG=1'
8890
export REZ_LAUNCHER_DEBUG=1
8991
9092
jctest

launcher/remote-appended.patch

Lines changed: 0 additions & 27 deletions
This file was deleted.

launcher/rez.patch

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
diff --git a/launcher.c b/launcher.c
2+
index 727f7916..a1a8768c 100644
3+
--- a/launcher.c
4+
+++ b/launcher.c
5+
@@ -35,8 +35,6 @@
6+
7+
#pragma comment (lib, "Shlwapi.lib")
8+
9+
-#define APPENDED_ARCHIVE
10+
-#define USE_ENVIRONMENT
11+
#define SUPPORT_RELATIVE_PATH
12+
13+
#define MSGSIZE 1024
14+
@@ -822,6 +820,13 @@ run_child(wchar_t * cmdline)
15+
#endif
16+
si.dwFlags |= STARTF_USESTDHANDLES;
17+
}
18+
+
19+
+ size_t rez_envvar_size = 0;
20+
+ getenv_s(&rez_envvar_size, NULL, 0, "REZ_LAUNCHER_DEBUG");
21+
+ if (rez_envvar_size > 0) {
22+
+ printf("Launching: %ls\n", cmdline);
23+
+ }
24+
+
25+
ok = CreateProcessW(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &child_process_info);
26+
if (!ok) {
27+
// Failed to create process. See if we can find out why.
28+
@@ -1027,11 +1032,12 @@ process(int argc, char * argv[])
29+
wcp = pbuffer;
30+
}
31+
#endif
32+
- /* 3 spaces + 4 quotes + NUL */
33+
- len = wcslen(wcp) + wcslen(wp) + 8 + wcslen(psp) + wcslen(cmdline);
34+
+ /* 4 spaces + 4 quotes + -E + NUL */
35+
+ len = wcslen(wcp) + wcslen(wp) + 11 + wcslen(psp) + wcslen(cmdline);
36+
cmdp = (wchar_t *) calloc(len, sizeof(wchar_t));
37+
assert(cmdp != NULL, "Expected to be able to allocate command line memory");
38+
- _snwprintf_s(cmdp, len, len, L"\"%ls\" %ls \"%ls\" %ls", wcp, wp, psp, cmdline);
39+
+ // Note that we inject -E to make sure PYTHON* variables are not picked up.
40+
+ _snwprintf_s(cmdp, len, len, L"\"%ls\" -E %ls \"%ls\" %ls", wcp, wp, psp, cmdline);
41+
run_child(cmdp); /* never actually returns */
42+
free(cmdp);
43+
return 0;

setup.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,22 @@ def find_files(pattern, path=None, root="rez"):
5555
long_description = f.read()
5656

5757

58-
SCRIPT_TEMPLATE = """#!/usr/bin/python -E
58+
SCRIPT_TEMPLATE = """#!/usr/bin/python
5959
# -*- coding: utf-8 -*-
60+
import os
6061
import re
6162
import sys
63+
import platform
64+
# If -E is not passed, then inject it and re-execute outself.
65+
# Note that this is not done on Windows because the Windows launcher
66+
# already does this.
67+
if not sys.flags.ignore_environment and platform.system() != 'Windows':
68+
args = sys.orig_argv[:]
69+
args[0] = sys.executable
70+
args.insert(1, '-E')
71+
if os.getenv('REZ_LAUNCHER_DEBUG'):
72+
print('Launching:', ' '.join(args))
73+
os.execvp(sys.executable, args)
6274
from rez.cli._entry_points import {0}
6375
if __name__ == '__main__':
6476
sys.argv[0] = re.sub(r'(-script\\.pyw|\\.exe)?$', '', sys.argv[0])
@@ -76,12 +88,12 @@ def run(self):
7688
scripts = []
7789
tmpdir = tempfile.mkdtemp("rez-scripts")
7890

79-
os.makedirs(self.build_dir)
91+
os.makedirs(self.build_dir, exist_ok=True)
8092

8193
for command in self.scripts:
8294
spec = get_specifications()[command]
8395

84-
filename = "{0}.py".format(command)
96+
filename = command
8597
if platform.system() == "Windows":
8698
filename = "{0}-script.py".format(command)
8799

src/rez/cli/_entry_points.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def check_production_install():
6565
@register("jctest")
6666
def run_jctest():
6767
print("argv:", sys.argv)
68+
print("orig_argv", sys.orig_argv)
6869
print("executable:", sys.executable)
70+
print("sys.flags:", sys.flags)
6971
return 0
7072

7173

0 commit comments

Comments
 (0)