| #!/usr/bin/env python |
| |
| # Copyright 2020 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| """ |
| This script patches goma related python scripts in-place to avoid |
| resetting the file permissions. |
| """ |
| |
| import argparse |
| import sys |
| |
| DEFAULT_GOMA_BACKEND_INTERNAL = "clients5.google.com" |
| DEFAULT_GOMA_BACKEND = "goma.chromium.org" |
| DEFAULT_GOMA_PORT = "8088" |
| DEFAULT_GOMA_IPC = "goma.ipc" |
| |
| |
| def main(): |
| parser = argparse.ArgumentParser() |
| parser.add_argument("--file") |
| parser.add_argument("--backend") |
| parser.add_argument("--ipc_socket") |
| parser.add_argument("--port") |
| args = parser.parse_args() |
| |
| with open(args.file, "r+") as f: |
| content = f.readlines() |
| newcontent = [] |
| for line in content: |
| # TODO(haowei@): Rewrite this with astor. |
| if "COMPILER_PROXY_PORT" in line: |
| line = line.replace(DEFAULT_GOMA_PORT, args.port) |
| if "COMPILER_PROXY_SOCKET_NAME" in line: |
| line = line.replace(DEFAULT_GOMA_IPC, args.ipc_socket) |
| if "GOMA_SERVER_HOST" in line: |
| line = line.replace(DEFAULT_GOMA_BACKEND_INTERNAL, args.backend) |
| line = line.replace(DEFAULT_GOMA_BACKEND, args.backend) |
| newcontent.append(line) |
| f.seek(0, 0) |
| f.truncate() |
| f.writelines(newcontent) |
| |
| |
| if __name__ == "__main__": |
| sys.exit(main()) |