# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).


from pants.core.util_rules.external_tool import TemplatedExternalTool
from pants.engine.platform import Platform
from pants.option.option_types import BoolOption


class Protoc(TemplatedExternalTool):
    options_scope = "protoc"
    help = "The protocol buffer compiler (https://developers.google.com/protocol-buffers)."

    default_version = "3.11.4"
    default_known_versions = [
        "3.11.4|linux_arm64 |f24c9fa1fc4a7770b8a5da66e515cb8a638d086ad2afa633abb97137c5f029a8|1481946",
        "3.11.4|linux_x86_64|6d0f18cd84b918c7b3edd0203e75569e0c8caecb1367bbbe409b45e28514f5be|1591191",
        "3.11.4|macos_arm64 |8c6af11e1058efe953830ecb38324c0e0fd2fb67df3891896d138c535932e7db|2482119",
        "3.11.4|macos_x86_64|8c6af11e1058efe953830ecb38324c0e0fd2fb67df3891896d138c535932e7db|2482119",
    ]
    default_url_template = (
        "https://github.com/protocolbuffers/protobuf/releases/download/"
        "v{version}/protoc-{version}-{platform}.zip"
    )
    default_url_platform_mapping = {
        "linux_arm64": "linux-aarch_64",
        "linux_x86_64": "linux-x86_64",
        "macos_arm64": "osx-x86_64",  # May require rosetta, but output is arch-independent
        "macos_x86_64": "osx-x86_64",
    }

    dependency_inference = BoolOption(
        "--dependency-inference",
        default=True,
        help="Infer Protobuf dependencies on other Protobuf files by analyzing import statements.",
    )
    tailor = BoolOption(
        "--tailor",
        default=True,
        help="If true, add `protobuf_sources` targets with the `tailor` goal.",
        advanced=True,
    )

    def generate_exe(self, plat: Platform) -> str:
        return "./bin/protoc"

@@ -474,20 +474,20 @@
 on = %223.
-11.4
+20.1
 %22%0A    de
@@ -518,28 +518,28 @@
 %0A        %223.
-11.4
+20.1
 %7Clinux_arm64
@@ -544,80 +544,80 @@
 64 %7C
-f24c9fa1fc4a7770b8a5da66e515cb8a638d086ad2afa633abb97137c5f029a8%7C1481946
+8a5a51876259f934cd2acc2bc59dba0e9a51bd631a5c37a4b9081d6e4dbc7591%7C1804837
 %22,%0A 
@@ -626,20 +626,20 @@
      %223.
-11.4
+20.1
 %7Clinux_x
@@ -648,79 +648,79 @@
 _64%7C
-6d0f18cd84b918c7b3edd0203e75569e0c8caecb1367bbbe409b45e28514f5be%7C159119
+3a0e900f9556fbcac4c3a913a00d07680f0fdf6b990a341462d822247b265562%7C171473
 1%22,%0A
@@ -726,28 +726,28 @@
 %0A        %223.
-11.4
+20.1
 %7Cmacos_arm64
@@ -752,79 +752,79 @@
 64 %7C
-8c6af11e1058efe953830ecb38324c0e0fd2fb67df3891896d138c535932e7db%7C248211
+b362acae78542872bb6aac8dba73aaf0dc6e94991b8b0a065d6c3e703fec2a8b%7C270824
 9%22,%0A
@@ -838,12 +838,12 @@
  %223.
-11.4
+20.1
 %7Cmac
@@ -856,79 +856,79 @@
 _64%7C
-8c6af11e1058efe953830ecb38324c0e0fd2fb67df3891896d138c535932e7db%7C248211
+b4f36b18202d54d343a66eebc9f8ae60809a2a96cc2d1b378137550bbe4cf33c%7C270824
 9%22,%0A
@@ -1244,71 +1244,18 @@
 osx-
-x86_64%22,  # May require rosetta, but output is arch-independent
+aarch_64%22,
 %0A   

Upgrade default Protoc version to 3.20.1 (native Apple Silicon support) (#15424)