Skip to content

Commit 5f93166

Browse files
authored
Merge pull request #63888 from rintaro/test-execplugin-rdar105870339
[Macros] Update executable plugin test to use the python running 'lit'
2 parents 9d9e015 + f25af9f commit 5f93166

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

test/Macros/macro_plugin_basic.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// REQUIRES: rdar105870339
21
// REQUIRES: OS=macosx
32

43
// RUN: %empty-directory(%t)
54
// RUN: split-file %s %t
65

7-
// RUN: sed -i '' -e 's#UTILS_DIR#%utils#' %t/plugin
8-
// RUN: sed -i '' -e 's#TEMP_DIR#%t#' %t/plugin
6+
// RUN: sed -i '' -e 's#PYTHON_EXEC_PATH#%{python}#' %t/plugin
7+
// RUN: sed -i '' -e 's#UTILS_DIR_PATH#%utils#' %t/plugin
98
// RUN: chmod +x %t/plugin
109

1110
// RUN: %swift-target-frontend -typecheck -verify -swift-version 5 -enable-experimental-feature Macros -load-plugin-executable %t/plugin#TestPlugin %t/test.swift
@@ -21,9 +20,9 @@ func test() {
2120
}
2221

2322
//--- plugin
24-
#!/usr/bin/env python3
23+
#!PYTHON_EXEC_PATH
2524
import sys
26-
sys.path.append('UTILS_DIR')
25+
sys.path.append('UTILS_DIR_PATH')
2726

2827
import mock_plugin
2928

utils/mock_plugin.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,21 @@ def handle_request(req):
9898

9999

100100
def main():
101+
if sys.version_info >= (3, 0):
102+
stdin = sys.stdin.buffer
103+
stdout = sys.stdout.buffer
104+
else:
105+
stdin = sys.stdin
106+
stdout = sys.stdout
107+
101108
# Message handling loop.
102109
while True:
103110
# Read request
104-
request_header = sys.stdin.buffer.read(8)
111+
request_header = stdin.read(8)
105112
if len(request_header) < 8:
106113
break
107114
request_size = struct.unpack('<Q', request_header)[0]
108-
request_data = sys.stdin.buffer.read(request_size)
115+
request_data = stdin.read(request_size)
109116
if len(request_data) != request_size:
110117
break
111118
request_object = json.loads(request_data)
@@ -118,9 +125,9 @@ def main():
118125
response_data = response_json.encode('utf-8')
119126
response_size = len(response_data)
120127
response_header = struct.pack('<Q', response_size)
121-
sys.stdout.buffer.write(response_header)
122-
sys.stdout.buffer.write(response_data)
123-
sys.stdout.buffer.flush()
128+
stdout.write(response_header)
129+
stdout.write(response_data)
130+
stdout.flush()
124131

125132

126133
if __name__ == '__main__':

0 commit comments

Comments
 (0)