Skip to content

[Macros] Update executable plugin test to use the python running 'lit' #63888

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

Merged
merged 1 commit into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions test/Macros/macro_plugin_basic.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// REQUIRES: rdar105870339
// REQUIRES: OS=macosx

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

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

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

//--- plugin
#!/usr/bin/env python3
#!PYTHON_EXEC_PATH
Comment on lines -24 to +23
Copy link
Contributor

@bnbarham bnbarham Feb 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I didn't think of this earlier, but using hashbang means that the mock tests will never work on Windows. The only way around that would be to create an actual executable though I think. At least this gets the test working for now, but would be nice if we could come up with something else here.

Ie. we could have a tools/mock-plugin swift library + build that in this test instead.

import sys
sys.path.append('UTILS_DIR')
sys.path.append('UTILS_DIR_PATH')

import mock_plugin

Expand Down
17 changes: 12 additions & 5 deletions utils/mock_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,21 @@ def handle_request(req):


def main():
if sys.version_info >= (3, 0):
stdin = sys.stdin.buffer
stdout = sys.stdout.buffer
else:
stdin = sys.stdin
stdout = sys.stdout

# Message handling loop.
while True:
# Read request
request_header = sys.stdin.buffer.read(8)
request_header = stdin.read(8)
if len(request_header) < 8:
break
request_size = struct.unpack('<Q', request_header)[0]
request_data = sys.stdin.buffer.read(request_size)
request_data = stdin.read(request_size)
if len(request_data) != request_size:
break
request_object = json.loads(request_data)
Expand All @@ -118,9 +125,9 @@ def main():
response_data = response_json.encode('utf-8')
response_size = len(response_data)
response_header = struct.pack('<Q', response_size)
sys.stdout.buffer.write(response_header)
sys.stdout.buffer.write(response_data)
sys.stdout.buffer.flush()
stdout.write(response_header)
stdout.write(response_data)
stdout.flush()


if __name__ == '__main__':
Expand Down