[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang-tools-extra / clangd / test / remote-index / pipeline_helper.py
blobafdac985221a75f2cbac807cc553387ba5fe72c6
1 #!/usr/bin/env python
3 # ===- pipeline_helper.py - Remote Index pipeline Helper *- python -------*--===#
5 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 # See https://llvm.org/LICENSE.txt for license information.
7 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 # ===------------------------------------------------------------------------===#
11 import argparse
12 import os
13 import subprocess
14 from socket import socket
15 import sys
16 import time
17 import threading
20 def kill_process_after_delay(server_process):
21 time.sleep(10)
22 if server_process.poll() is None:
23 server_process.kill()
26 def main():
27 parser = argparse.ArgumentParser()
28 parser.add_argument("--input-file-name", required=True)
29 parser.add_argument("--project-root", required=True)
30 parser.add_argument("--index-file", required=True)
31 parser.add_argument("--server-arg", action="append", default=[])
32 parser.add_argument(
33 "--server-log", nargs="?", type=argparse.FileType("wb"), default=os.devnull
36 args = parser.parse_args()
38 # Grab an available port.
39 with socket() as s:
40 s.bind(("localhost", 0))
41 server_address = "localhost:" + str(s.getsockname()[1])
43 print("Initializing clangd-index-server...", file=sys.stderr)
44 index_server_process = subprocess.Popen(
46 "clangd-index-server",
47 "--server-address=" + server_address,
48 args.index_file,
49 args.project_root,
51 + args.server_arg,
52 stderr=subprocess.PIPE,
55 # This will kill index_server_process if it hangs without printing init
56 # message.
57 shutdown_thread = threading.Thread(
58 target=kill_process_after_delay, args=(index_server_process,)
60 shutdown_thread.daemon = True
61 shutdown_thread.start()
63 # Wait for the server to warm-up.
64 found_init_message = False
65 while index_server_process.poll() is None:
66 line = index_server_process.stderr.readline()
67 args.server_log.write(line)
68 args.server_log.flush()
69 if b"Server listening" in line:
70 print("Server initialization complete.", file=sys.stderr)
71 found_init_message = True
72 break
74 if not found_init_message:
75 print("Server initialization failed. Shutting down.", file=sys.stderr)
76 sys.exit(1)
78 print("Running clangd-index-server-monitor...", file=sys.stderr)
79 index_server_monitor_process = subprocess.Popen(
81 "clangd-index-server-monitor",
82 server_address,
84 stderr=subprocess.PIPE,
87 index_server_monitor_process.wait()
89 in_file = open(args.input_file_name)
91 print("Staring clangd...", file=sys.stderr)
92 clangd_process = subprocess.Popen(
94 "clangd",
95 "--remote-index-address=" + server_address,
96 "--project-root=" + args.project_root,
97 "--lit-test",
98 "--sync",
100 stdin=in_file,
102 clangd_process.wait()
103 print(
104 "Clangd executed successfully, shutting down child processes.", file=sys.stderr
106 index_server_process.kill()
107 for line in index_server_process.stderr:
108 args.server_log.write(line)
109 args.server_log.flush()
111 for line in index_server_monitor_process.stderr:
112 args.server_log.write(line)
113 args.server_log.flush()
116 if __name__ == "__main__":
117 main()