From f25af9f491547e07a65152dabc72fd8e7f90efe4 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Fri, 24 Feb 2023 09:25:16 -0800 Subject: [PATCH] [Macros] Update executable plugin test to use the python running 'lit' Also, update 'mock_plugin.py' to support python2 rdar://105870339 --- test/Macros/macro_plugin_basic.swift | 9 ++++----- utils/mock_plugin.py | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/test/Macros/macro_plugin_basic.swift b/test/Macros/macro_plugin_basic.swift index cc0f1f80bfdcc..0784535a8dcb0 100644 --- a/test/Macros/macro_plugin_basic.swift +++ b/test/Macros/macro_plugin_basic.swift @@ -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 @@ -21,9 +20,9 @@ func test() { } //--- plugin -#!/usr/bin/env python3 +#!PYTHON_EXEC_PATH import sys -sys.path.append('UTILS_DIR') +sys.path.append('UTILS_DIR_PATH') import mock_plugin diff --git a/utils/mock_plugin.py b/utils/mock_plugin.py index 3ec634637ddef..976a7c6a3ab71 100644 --- a/utils/mock_plugin.py +++ b/utils/mock_plugin.py @@ -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('