| # Copyright 2023 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. |
| """A script for updating the Go API file for fuchsia. |
| """ |
| |
| import argparse |
| import os |
| import subprocess |
| import sys |
| |
| |
| def main(): |
| parser = argparse.ArgumentParser() |
| parser.add_argument( |
| '--api-file', |
| help='The API file to update', |
| type=argparse.FileType('r+'), |
| required=True, |
| ) |
| parser.add_argument( |
| '--go-root', |
| help='The GOROOT to use for checking the API ', |
| required=True, |
| ) |
| args = parser.parse_args() |
| |
| api = set(args.api_file.readlines()) |
| |
| result = subprocess.run( |
| [os.path.join(args.go_root, 'bin/go'), 'test', 'cmd/api', '-check'], |
| text=True, |
| stdout=subprocess.PIPE) |
| for line in result.stdout.splitlines(keepends=True): |
| if 'pkg syscall/zx' not in line: |
| continue |
| op = line[0] |
| if op == '+': |
| api.add(line[1:]) |
| continue |
| if op == '-': |
| api.remove(line[1:]) |
| continue |
| raise f"unexpected input: '${line}'" |
| |
| args.api_file.truncate(0) |
| args.api_file.seek(0) |
| args.api_file.writelines(sorted(api)) |
| |
| |
| if __name__ == '__main__': |
| sys.exit(main()) |