| 53 | |
| 54 | |
| 55 | def main(): |
| 56 | parser = argparse.ArgumentParser(description=__doc__) |
| 57 | parser.add_argument("--temp-dir", help="Existing parent for temporary compiler output") |
| 58 | args = parser.parse_args() |
| 59 | root = Path(__file__).resolve().parent |
| 60 | files = sorted(p.relative_to(root).as_posix() for p in (root / "atomic").rglob("*.proto")) |
| 61 | failures = [] |
| 62 | |
| 63 | def check(condition, description): |
| 64 | if not condition: |
| 65 | failures.append(description) |
| 66 | |
| 67 | with tempfile.TemporaryDirectory(prefix="atomic-proto-", dir=args.temp_dir) as output: |
| 68 | descriptor_path = Path(output) / "atomic.pb" |
| 69 | result = protoc.main([ |
| 70 | "protoc", f"-I{root}", |
| 71 | f"-I{Path(grpc_tools.__file__).parent / '_proto'}", |
| 72 | f"--descriptor_set_out={descriptor_path}", "--include_imports", |
| 73 | f"--python_out={output}", *files, |
| 74 | ]) |
| 75 | if result: |
| 76 | return result |
| 77 | sys.path.insert(0, output) |
| 78 | options = importlib.import_module("atomic.common.options_pb2") |
| 79 | common = importlib.import_module("atomic.common.common_pb2") |
| 80 | check(common.CONTRACT_VERSION_2 == 2, "Contract revision 2 constant changed") |
| 81 | descriptors = descriptor_pb2.FileDescriptorSet.FromString(descriptor_path.read_bytes()) |
| 82 | messages = { |
| 83 | f".atomic.{message.name}": message |
| 84 | for file in descriptors.file if file.package == "atomic" |
| 85 | for message in file.message_type |
| 86 | } |
| 87 | methods = { |
| 88 | (service.name, method.name): method |
| 89 | for file in descriptors.file if file.package == "atomic" |
| 90 | for service in file.service for method in service.method |
| 91 | } |
| 92 | writes = { |
| 93 | options.RPC_EFFECT_REPOSITORY_WRITE, |
| 94 | options.RPC_EFFECT_WORKSPACE_WRITE, |
| 95 | options.RPC_EFFECT_DAEMON_WRITE, |
| 96 | } |
| 97 | workspace = {options.RPC_EFFECT_WORKSPACE_READ, options.RPC_EFFECT_WORKSPACE_WRITE} |
| 98 | event_publish = {("ReactorService", "Publish"), ("ReactorService", "PublishStream")} |
| 99 | negotiation = {("DaemonService", "Health"), ("DaemonService", "GetCapabilities")} |
| 100 | mutation_permissions = { |
| 101 | "sandbox.submit", "agent.checkpoint", "view.create", "view.switch", |
| 102 | "view.delete", "view.promote", "reactor.publish", "reactor.checkpoint", |
| 103 | } |
| 104 | observed_sandbox = {} |
| 105 | for key, method in methods.items(): |
| 106 | label = ".".join(key) |
| 107 | opt = method.options |
| 108 | callers = set(opt.Extensions[options.allowed_caller]) |
| 109 | effects = set(opt.Extensions[options.effect]) |
| 110 | capabilities = set(opt.Extensions[options.required_capability]) |
| 111 | scope = opt.Extensions[options.execution_scope] |
| 112 | check(scope != options.EXECUTION_SCOPE_UNSPECIFIED, f"{label}: missing scope") |