diff --git a/MODULE.bazel b/MODULE.bazel index 2dcb1c40..8ccf6bb8 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,3 +1,7 @@ +module( + name="monorepo", + version="" +) bazel_dep(name = "events", version = "") local_path_override( module_name = "events", @@ -15,10 +19,12 @@ local_path_override( ) bazel_dep(name = "platforms", version = "0.0.7") -bazel_dep(name = "rules_pact", version = "") -local_path_override( +bazel_dep(name = "rules_pact", version = "1.0.0") +archive_override( module_name = "rules_pact", - path = "rules_pact", + urls = ["https://github.com/opicaud/rules_pact/archive/refs/tags/v1.0.0.tar.gz"], + strip_prefix = "rules_pact-1.0.0", + integrity = "sha256-GqWy8GzwY7RHhmt2lVRSQ2absC3Z5rnP698foezdfY8=", ) bazel_dep(name = "hack", version = "") local_path_override( @@ -112,7 +118,7 @@ use_repo(oci, "distroless_go") go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") go_deps.module_override( patches = [ - "//rules_pact/lib:pact_ffi.patch", + "//pact-helper:pact_ffi.patch", ], path = "github.com/pact-foundation/pact-go/v2", ) diff --git a/pact-helper/BUILD.bazel b/pact-helper/BUILD.bazel new file mode 100644 index 00000000..81e753dc --- /dev/null +++ b/pact-helper/BUILD.bazel @@ -0,0 +1,24 @@ +alias( + name = "pact_ffi", + actual = select({ + ":macos": "@pact_reference_osx_x86_64_toolchain//:pact_ffi_darwin_amd64", + ":linux": "@pact_reference_linux_x86_64_toolchain//:pact_ffi_linux_amd64", + }), + visibility = ["//visibility:public"], +) + +config_setting( + name = "macos", + constraint_values = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ] +) + +config_setting( + name = "linux", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ] +) \ No newline at end of file diff --git a/rules_pact/lib/pact_ffi.patch b/pact-helper/pact_ffi.patch similarity index 92% rename from rules_pact/lib/pact_ffi.patch rename to pact-helper/pact_ffi.patch index 5d1c4f86..8f318122 100644 --- a/rules_pact/lib/pact_ffi.patch +++ b/pact-helper/pact_ffi.patch @@ -15,7 +15,7 @@ + +cc_import( + name = "pact_ffi_cc_import", -+ shared_library = "@@//rules_pact:pact_ffi", ++ shared_library= "@@//pact-helper:pact_ffi", + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/rules_pact/.gitignore b/rules_pact/.gitignore deleted file mode 100644 index 7a1537ba..00000000 --- a/rules_pact/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.idea -node_modules diff --git a/rules_pact/BUILD.bazel b/rules_pact/BUILD.bazel deleted file mode 100644 index 0e13060b..00000000 --- a/rules_pact/BUILD.bazel +++ /dev/null @@ -1,72 +0,0 @@ -load("@rules_pact//:defs.bzl", "pact_protobuf_plugin_toolchain", "pact_reference_toolchain") -load("@bazel_skylib//rules:diff_test.bzl", "diff_test") -load("@hack//:release.bzl", "release_me") - -release_me() - -toolchain_type( - name = "pact_protobuf_plugin_toolchain_type", - visibility = ["//visibility:public"], -) - -alias( - name = "pact_ffi", - actual = select({ - ":macos": "@pact_reference_osx_x86_64_toolchain//:pact_ffi_darwin_amd64", - ":linux": "@pact_reference_linux_x86_64_toolchain//:pact_ffi_linux_amd64", - }), - visibility = ["//visibility:public"], -) - -config_setting( - name = "macos", - constraint_values = [ - "@platforms//os:macos", - "@platforms//cpu:x86_64", - ] -) - -config_setting( - name = "linux", - constraint_values = [ - "@platforms//os:linux", - "@platforms//cpu:x86_64", - ] -) -toolchain_type( - name = "pact_reference_toolchain_type", - visibility = ["//visibility:public"], -) - -load("@stardoc//stardoc:stardoc.bzl", "stardoc") - -stardoc( - name = "docs", - input = "@rules_pact//:defs.bzl", - out = "docs.md", - deps = [":bzl_lib"] -) -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -bzl_library( - name = "bzl_lib", - srcs = [ - "@rules_pact//private:toolchains.bzl", - "@rules_pact//private:consumer.bzl", - "@rules_pact//private:provider.bzl", - ], - visibility = ["//visibility:public"], -) - - -diff_test( - name = "docs_diff_test", - file1 = ":docs", - file2 = ":README.md", -) - -exports_files( - glob(["defs.bzl"]), - visibility = ["//visibility:public"], -) - diff --git a/rules_pact/MODULE.bazel b/rules_pact/MODULE.bazel deleted file mode 100644 index 025ff722..00000000 --- a/rules_pact/MODULE.bazel +++ /dev/null @@ -1,29 +0,0 @@ -module( - name="rules_pact", - version="" -) - -bazel_dep(name = "platforms", version = "0.0.7") -bazel_dep(name = "stardoc", version = "0.6.2") -bazel_dep(name = "bazel_skylib", version = "1.4.2") -bazel_dep(name = "hack", version = "") -local_path_override( - module_name = "hack", - path = "../hack", -) -rules_pact = use_extension("@rules_pact//:extensions.bzl", "rules_pact") -rules_pact.options() -use_repo( - rules_pact, - "pact_protobuf_plugin_archive_darwin_amd64", - "pact_protobuf_plugin_archive_linux_amd64", - "pact_plugin_json_archive", - "pact_verifier_cli_archive_darwin_amd64", - "pact_verifier_cli_archive_linux_amd64", - "pact_ffi_archive_darwin_amd64", - "pact_ffi_archive_linux_amd64", - "pact_protobuf_plugin_osx_x86_64_toolchain", - "pact_protobuf_plugin_linux_x86_64_toolchain", - "pact_reference_osx_x86_64_toolchain", - "pact_reference_linux_x86_64_toolchain" -) diff --git a/rules_pact/README.md b/rules_pact/README.md deleted file mode 100644 index c45a2a00..00000000 --- a/rules_pact/README.md +++ /dev/null @@ -1,140 +0,0 @@ - - -# rules_pact -Bazel rules to test services interactions with [pacts][pactsws] - -[pactsws]: https://docs.pact.io/ - -- [consumer](#consumer) -- [provider](#provider) -- [side_car](#side_car) -- [pact_test](#pact_test) -- [pact_reference_toolchain](#pact_reference_toolchain) -- [pact_protobuf_plugin_toolchain](#pact_protobuf_plugin_toolchain) - - - -## consumer - -
-consumer(name, srcs, data)
-
- -Rule that wrap consumer interaction. -It executes the test provided in srcs attribute through the toolchain. -This rule will be executed from the pact_test rule. - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| srcs | a test target | Label | optional | `None` | -| data | data useful to provide with test target | List of labels | optional | `[]` | - - - - -## pact_protobuf_plugin_toolchain - -
-pact_protobuf_plugin_toolchain(name, manifest, protobuf_plugin)
-
- -A pact protobuf plugin toolchain - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| manifest | A json manifest | Label | required | | -| protobuf_plugin | A pact protobuf plugin binary | Label | required | | - - - - -## pact_reference_toolchain - -
-pact_reference_toolchain(name, libpact_ffi, pact_verifier_cli)
-
- -A pact reference toolchain - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| libpact_ffi | A pact ffi library | Label | required | | -| pact_verifier_cli | A pact reference binary | Label | required | | - - - - -## pact_test - -
-pact_test(name, consumer, provider)
-
- - - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| consumer | - | Label | optional | `None` | -| provider | - | Label | optional | `None` | - - - - -## provider - -
-provider(name, deps, srcs, opts)
-
- -Rule that describe provider interaction - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| deps | any useful dep to run with the provider like a state-manager, a proxy or a side-car | List of labels | optional | `[]` | -| srcs | the provider to run | Label | optional | `None` | -| opts | options to provide to pact_verifier_cli | Dictionary: String -> String | optional | `{}` | - - - - -## side_car - -
-side_car(name, srcs, data, env, health_check, opts)
-
- - - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| srcs | the side-car to run | Label | optional | `None` | -| data | any data useful to run with the side-car, like a configuration file for instance | List of labels | optional | `[]` | -| env | any environment variable to provide with the side_car | Dictionary: String -> String | optional | `{}` | -| health_check | uri to curl before launching provider test | String | optional | `"nop"` | -| opts | the option specific to the side-car | Dictionary: String -> String | optional | `{}` | - - diff --git a/rules_pact/WORKSPACE b/rules_pact/WORKSPACE deleted file mode 100644 index e69de29b..00000000 diff --git a/rules_pact/defs.bzl b/rules_pact/defs.bzl deleted file mode 100644 index e6411116..00000000 --- a/rules_pact/defs.bzl +++ /dev/null @@ -1,21 +0,0 @@ -"""# rules_pact -Bazel rules to test services interactions with [pacts][pactsws] - -[pactsws]: https://docs.pact.io/ - -- [consumer](#consumer) -- [provider](#provider) -- [side_car](#side_car) -- [pact_test](#pact_test) -- [pact_reference_toolchain](#pact_reference_toolchain) -- [pact_protobuf_plugin_toolchain](#pact_protobuf_plugin_toolchain) -""" -load("@rules_pact//private:toolchains.bzl", _pact_reference_toolchain = "pact_reference_toolchain", _pact_protobuf_plugin_toolchain = "pact_protobuf_plugin_toolchain") -load("@rules_pact//private:consumer.bzl", _pact_test = "pact_test", _consumer = "consumer", _provider = "provider", _side_car = "side_car") - -pact_reference_toolchain = _pact_reference_toolchain -pact_protobuf_plugin_toolchain = _pact_protobuf_plugin_toolchain -pact_test = _pact_test -consumer = _consumer -provider = _provider -side_car = _side_car \ No newline at end of file diff --git a/rules_pact/extensions.bzl b/rules_pact/extensions.bzl deleted file mode 100644 index 908f23fc..00000000 --- a/rules_pact/extensions.bzl +++ /dev/null @@ -1,10 +0,0 @@ -load("@rules_pact//private:repositories.bzl", "repos") - -def _impl(ctx): - repos() - -options = tag_class(attrs={}) -rules_pact = module_extension( - implementation = _impl, - tag_classes = {"options": options}, -) \ No newline at end of file diff --git a/rules_pact/lib/BUILD.bazel b/rules_pact/lib/BUILD.bazel deleted file mode 100644 index e69de29b..00000000 diff --git a/rules_pact/package.json b/rules_pact/package.json deleted file mode 100644 index d2b50165..00000000 --- a/rules_pact/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "rules_pact" -} diff --git a/rules_pact/private/BUILD.bazel b/rules_pact/private/BUILD.bazel deleted file mode 100644 index baa7905c..00000000 --- a/rules_pact/private/BUILD.bazel +++ /dev/null @@ -1,4 +0,0 @@ -exports_files( - glob(["toolchains.bzl", "consumer.bzl", "provider.bzl"]), - visibility = ["//visibility:public"], -) \ No newline at end of file diff --git a/rules_pact/private/consumer.bzl b/rules_pact/private/consumer.bzl deleted file mode 100644 index 1c8e1281..00000000 --- a/rules_pact/private/consumer.bzl +++ /dev/null @@ -1,192 +0,0 @@ -load("@rules_pact//private:provider.bzl", "ExampleInfo", "ContractInfo") - -script_template="""\ -#!/bin/bash -_healthCheck () {{ - echo "starting health check of $2" - healthy="503" - if [ $1 == "nop" ]; then healthy="200" && echo "health check ignored"; fi - attempt=0 - until [ $healthy = "200" ] - do - healthy=$(curl -s -o /dev/null -w "%{{http_code}}" $1) - echo "health check of $2 not ok, will recheck in 1 sec.." - sleep 1 - done -}} -pwd -cp {libpact_ffi} $(dirname $(dirname {run_consumer_test})) -cp {libpact_ffi} . -ls . -echo "### Running Consumers Tests ###" -mkdir -p protobuf-0.3.5 -cp {manifest} protobuf-0.3.5 -cp {plugin} pact-protobuf-plugin -mv pact-protobuf-plugin protobuf-0.3.5 -export PACT_PLUGIN_DIR=$(pwd) -./{run_consumer_test} -ls shape-app/api/pacts/ -echo "### Running Providers Tests ###" -contract=$(dirname $(dirname {run_consumer_test}))/pacts/{contract}.json -pact_verifier_cli_args=$(cat {pact_verifier_cli_opts} || echo "--help") -side_car_cli_args=$(cat {side_car_opts} || echo "") -cli_args="$side_car_cli_args -f $contract $pact_verifier_cli_args" -echo $cli_args -while read first_line; read second_line -do - export "$first_line"="$second_line" -done < {env_side_car} -nohup {provider_bin} & -echo "Provider started.." -nohup {side_car_bin} & -echo "State manager started.." -_healthCheck $(cat {health_check_side_car}) "side_car" -echo "Now running provider on $contract" -./{pact_verifier_cli} $cli_args -""" - - -def _pact_test_impl(ctx): - pact_plugins = ctx.toolchains["@rules_pact//:pact_protobuf_plugin_toolchain_type"] - pact_reference = ctx.toolchains["@rules_pact//:pact_reference_toolchain_type"] - consumer = ctx.attr.consumer[DefaultInfo].default_runfiles.files.to_list() - provider = ctx.attr.provider[DefaultInfo].default_runfiles.files.to_list() - dict = {} - for p in provider: - dict.update({p.basename: p.short_path}) - if ctx.attr.provider[ExampleInfo].file == p.basename: - dict.update({ctx.attr.provider[ExampleInfo].file: p.short_path}) - dict.update({"contract": ctx.attr.consumer[ContractInfo].name + "-" + ctx.attr.provider[ContractInfo].name}) - script_content = script_template.format( - manifest = pact_plugins.manifest.short_path, - plugin = pact_plugins.protobuf_plugin.short_path, - run_consumer_test = consumer[0].short_path, - libpact_ffi = pact_reference.libpact_ffi.short_path, - pact_verifier_cli = pact_reference.pact_verifier_cli.short_path, - pact_verifier_cli_opts = dict.setdefault("cli_args", "nop"), - side_car_opts = dict.setdefault("side_car_cli_args", "nop"), - provider_bin = dict.setdefault("cmd", "nop"), - side_car_bin = dict.setdefault(ctx.attr.provider[ExampleInfo].file, "nop"), - env_side_car = dict.setdefault("env_side_car","nop"), - health_check_side_car = dict.setdefault("health_check_side_car", "nop"), - contract = dict.setdefault("contract", "nop") - ) - ctx.actions.write(ctx.outputs.executable, script_content) - runfiles = ctx.runfiles(files = consumer + [pact_plugins.manifest, pact_plugins.protobuf_plugin, pact_reference.pact_verifier_cli, pact_reference.libpact_ffi, consumer[1]] + provider) - - return [DefaultInfo(runfiles = runfiles)] - -pact_test = rule( - implementation = _pact_test_impl, - attrs = { - "consumer": attr.label(), - "provider": attr.label() - }, - toolchains = ["@rules_pact//:pact_reference_toolchain_type", "@rules_pact//:pact_protobuf_plugin_toolchain_type"], - test = True, -) - -def _consumer_impl(ctx): - srcs = ctx.attr.srcs[DefaultInfo].files_to_run.executable - runfiles = ctx.runfiles(files = [srcs]) - runfiles = runfiles.merge(ctx.attr.data[0].data_runfiles) - return [DefaultInfo(runfiles = runfiles), - ContractInfo(name = ctx.attr.name)] - -consumer = rule( - implementation = _consumer_impl, - doc = """Rule that wrap consumer interaction. - It executes the test provided in srcs attribute through the toolchain. - This rule will be executed from the pact_test rule. - """, - attrs = { - "srcs": attr.label( - allow_files = True, - providers = [DefaultInfo], - doc = "a test target" - ), - "data": attr.label_list( - allow_files = True, - doc = "data useful to provide with test target" - ), - }, -) - -def _provider_impl(ctx): - - args = ctx.actions.args() - cli_args = ctx.actions.declare_file("cli_args") - for k, v in ctx.attr.opts.items(): - args.add("--"+k, v) - ctx.actions.write(cli_args, args) - - runfiles = ctx.runfiles(files = [cli_args] + - ctx.attr.srcs[DefaultInfo].default_runfiles.files.to_list() - ) - - for dep in ctx.attr.deps: - runfiles = runfiles.merge(dep[DefaultInfo].default_runfiles) - - return [DefaultInfo(runfiles = runfiles), - ExampleInfo(file = dep[ExampleInfo].file), - ContractInfo(name = ctx.attr.name)] -provider = rule( - implementation = _provider_impl, - doc = "Rule that describe provider interaction", - attrs = { - "srcs": attr.label(allow_files = True, - providers = [DefaultInfo], - doc = "the provider to run" - ), - "opts": attr.string_dict( - doc = "options to provide to pact_verifier_cli" - ), - "deps": attr.label_list( - allow_files = True, - providers = [ExampleInfo], - doc="any useful dep to run with the provider like a state-manager, a proxy or a side-car" - ), - }, -) - -def _side_car_impl(ctx): - args = ctx.actions.args() - cli_args = ctx.actions.declare_file("side_car_cli_args") - for k, v in ctx.attr.opts.items(): - args.add("--"+k, v) if k != "state-change-teardown" else args.add("--"+k) - - ctx.actions.write(cli_args, args) - bin = ctx.attr.srcs[DefaultInfo].files_to_run.executable - - env_args_file = ctx.actions.declare_file("env_side_car") - env_args = ctx.actions.args() - for k, v in ctx.attr.env.items(): - path = ctx.expand_location(v, ctx.attr.data) - env_args.add(k, path) - ctx.actions.write(env_args_file, env_args) - - health_check_file = ctx.actions.declare_file("health_check_side_car") - ctx.actions.write(health_check_file, ctx.attr.health_check) - - runfiles = ctx.runfiles(files = [bin, cli_args, env_args_file, health_check_file] + ctx.files.data) - return [DefaultInfo(runfiles = runfiles), - ExampleInfo(file = bin.basename) -] - -side_car = rule( - implementation = _side_car_impl, - attrs = { - "srcs": attr.label(allow_files = True, providers = [DefaultInfo], doc = "the side-car to run"), - "opts": attr.string_dict( - doc = "the option specific to the side-car" - ), - "env": attr.string_dict( - doc = "any environment variable to provide with the side_car" - ), - "data": attr.label_list( - allow_files = True, - doc = "any data useful to run with the side-car, like a configuration file for instance" - ), - "health_check": attr.string(default = "nop", doc = "uri to curl before launching provider test") - }, -) \ No newline at end of file diff --git a/rules_pact/private/provider.bzl b/rules_pact/private/provider.bzl deleted file mode 100644 index 8bb72367..00000000 --- a/rules_pact/private/provider.bzl +++ /dev/null @@ -1,2 +0,0 @@ -ExampleInfo = provider("file") -ContractInfo = provider("name") diff --git a/rules_pact/private/repositories.bzl b/rules_pact/private/repositories.bzl deleted file mode 100644 index 66256599..00000000 --- a/rules_pact/private/repositories.bzl +++ /dev/null @@ -1,5 +0,0 @@ -load("@rules_pact//private/repositories:pact_protobuf_plugin.bzl", _repos_pact_protobuf_plugin = "repos") -load("@rules_pact//private/repositories:pact_reference.bzl", _repos_pact_reference = "repos",) -def repos(): - _repos_pact_protobuf_plugin() - _repos_pact_reference() \ No newline at end of file diff --git a/rules_pact/private/repositories/BUILD.bazel b/rules_pact/private/repositories/BUILD.bazel deleted file mode 100644 index e69de29b..00000000 diff --git a/rules_pact/private/repositories/pact_protobuf_plugin.bzl b/rules_pact/private/repositories/pact_protobuf_plugin.bzl deleted file mode 100644 index 9cbfe735..00000000 --- a/rules_pact/private/repositories/pact_protobuf_plugin.bzl +++ /dev/null @@ -1,98 +0,0 @@ -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load("@bazel_tools//tools/build_defs/repo:git.bzl","git_repository") -load("@rules_pact//private:versions.bzl", "CONSTRAINTS", "PLATFORMS", "PACT_PROTOBUF_PLUGINS_VERSIONS", "PACT_PROTOBUF_PLUGIN_JSON_VERSIONS", "DEFAULT_PACT_PROTOBUF_PLUGIN_VERSISON") - -_PACT_TOOLCHAIN_BUILD_CONTENT = """\ -load("@rules_pact//:defs.bzl", "pact_protobuf_plugin_toolchain") - -pact_protobuf_plugin_toolchain( - name = "toolchain_impl", - protobuf_plugin = ":pact_protobuf_plugin_toolchain_bin_{platform}", - manifest = ":pact_plugin_json_archive" -) - -genrule( - name = "pact_plugin_json_archive", - outs = ["pact-plugin.json"], - srcs = ["@pact_plugin_json_archive//file"], - cmd = "cp $< $@", -) - -genrule( - name = "pact_protobuf_plugin_toolchain_bin_{platform}", - outs = ["pact-protobuf-plugin_{platform}"], - srcs = ["@pact_protobuf_plugin_archive_{platform}//file"], - cmd = "gzip -d - < $< > $@", -) - -toolchain( - name = "toolchain", - toolchain = ":toolchain_impl", - toolchain_type = "@rules_pact//:pact_protobuf_plugin_toolchain_type", - exec_compatible_with = {exec_compatible_with}, - target_compatible_with = {target_compatible_with} -) - -""" - -_PACT_WORKSPACE_CONTENT = """\ -workspace(name = {}) -""" - -def repos(default_version = DEFAULT_PACT_PROTOBUF_PLUGIN_VERSISON): - - - for platform in PACT_PROTOBUF_PLUGINS_VERSIONS[default_version].keys(): - value = PACT_PROTOBUF_PLUGINS_VERSIONS[default_version][platform] - maybe( - http_file, - name = "pact_protobuf_plugin_archive_{platform}".format(platform = platform), - sha256 = "{sha256}".format(sha256 = value.sha256), - urls = ["https://github.com/pactflow/pact-protobuf-plugin/releases/download/v-{version}/pact-protobuf-plugin-{os}-{cpu}.gz".format( - os = PLATFORMS[platform].os, - cpu = PLATFORMS[platform].cpu, - version = default_version - )], - ) - - pact_plugins_toolchain_repository( - name = "pact_protobuf_plugin_{os}_{cpu}_toolchain".format( - os = PLATFORMS[platform].os, - cpu = PLATFORMS[platform].cpu.replace("-", "_"), - ), - platform = platform, - exec_compatible_with = CONSTRAINTS[platform], - target_compatible_with = CONSTRAINTS[platform] - ) - - maybe( - http_file, - name = "pact_plugin_json_archive", - sha256 = PACT_PROTOBUF_PLUGIN_JSON_VERSIONS[default_version].sha256, - urls = ["https://github.com/pactflow/pact-protobuf-plugin/releases/download/v-{version}/pact-plugin.json".format( - - version = default_version - )], - ) - - -def _pact_plugins_toolchain_repository_impl(repository_ctx): - repository_ctx.file("BUILD.bazel", _PACT_TOOLCHAIN_BUILD_CONTENT.format( - platform = repository_ctx.attr.platform, - exec_compatible_with = repository_ctx.attr.exec_compatible_with, - target_compatible_with = repository_ctx.attr.target_compatible_with - )); - repository_ctx.file("WORKSPACE.bazel", _PACT_WORKSPACE_CONTENT.format(repository_ctx.name)); - -pact_plugins_toolchain_repository = repository_rule( - implementation = _pact_plugins_toolchain_repository_impl, - attrs = { - "platform": attr.string( - doc = "Platform the pact-protobuf-plugin executable was built for.", - mandatory = True, - ), - "exec_compatible_with": attr.string_list(mandatory = True), - "target_compatible_with": attr.string_list(mandatory = True) - }, -) diff --git a/rules_pact/private/repositories/pact_reference.bzl b/rules_pact/private/repositories/pact_reference.bzl deleted file mode 100644 index b8693cb5..00000000 --- a/rules_pact/private/repositories/pact_reference.bzl +++ /dev/null @@ -1,103 +0,0 @@ -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load("@bazel_tools//tools/build_defs/repo:git.bzl","git_repository") -load("@rules_pact//private:versions.bzl", "CONSTRAINTS", "PLATFORMS", "PACT_VERIFIER_CLI_VERSIONS", "PACT_VERIFIER_LIB_PACTFFI_VERSIONS") - -_PACT_REFERENCE_BUILD_CONTENT = """\ -load("@rules_pact//:defs.bzl", "pact_reference_toolchain") - -pact_reference_toolchain( - name = "pact_reference_toolchain_impl", - pact_verifier_cli = ":pact_verifier_cli_toolchain_{platform}", - libpact_ffi = ":pact_ffi_{platform}" -) - -genrule( - name = "pact_verifier_cli_toolchain_{platform}", - outs = ["pact_verifier_cli_bin_{platform}"], - srcs = ["@pact_verifier_cli_archive_{platform}//file"], - cmd = "gzip -d - < $< > $@", -) - -genrule( - name = "pact_ffi_{platform}", - outs = ["libpact_ffi.{ext}"], - srcs = ["@pact_ffi_archive_{platform}//file"], - cmd = "gzip -d - < $< > $@", - visibility = ["//visibility:public"], -) - -toolchain( - name = "toolchain", - toolchain = ":pact_reference_toolchain_impl", - toolchain_type = "@rules_pact//:pact_reference_toolchain_type", - exec_compatible_with = {exec_compatible_with}, - target_compatible_with = {target_compatible_with} -) -""" -_PACT_WORKSPACE_CONTENT = """\ -workspace(name = {}) -""" -DEFAULT_PACT_VERIFIER_CLI_VERSION = "1.0.1" -DEFAULT_PACTFFI_LIB_VERSION = "0.4.9" -def repos(pact_verifier_cli_version = DEFAULT_PACT_VERIFIER_CLI_VERSION, pactffi_lib_version = DEFAULT_PACTFFI_LIB_VERSION): - - for platform in PACT_VERIFIER_CLI_VERSIONS[pact_verifier_cli_version].keys(): - value = PACT_VERIFIER_CLI_VERSIONS[pact_verifier_cli_version][platform] - maybe( - http_file, - name = "pact_verifier_cli_archive_{platform}".format(platform = platform), - sha256 = "{sha256}".format(sha256 = value.sha256), - urls = ["https://github.com/pact-foundation/pact-reference/releases/download/pact_verifier_cli-v{version}/pact_verifier_cli-{os}-{cpu}.gz".format( - os = PLATFORMS[platform].os, - cpu = PLATFORMS[platform].cpu, - version = pact_verifier_cli_version)], - ) - - for platform in PACT_VERIFIER_LIB_PACTFFI_VERSIONS[pactffi_lib_version].keys(): - value = PACT_VERIFIER_LIB_PACTFFI_VERSIONS[pactffi_lib_version][platform] - maybe( - http_file, - name = "pact_ffi_archive_{platform}".format(platform = platform), - sha256 ="{sha256}".format(sha256 = value.sha256), - urls = ["https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v{version}/libpact_ffi-{os}-{cpu}.{ext}.gz".format( - os = PLATFORMS[platform].os, - cpu = PLATFORMS[platform].cpu, - ext = value.ext, - version = pactffi_lib_version)], - ) - if platform.startswith("darwin"): - ext = "dylib" - - pact_reference_toolchain_repository( - name = "pact_reference_{os}_{cpu}_toolchain".format( - os = PLATFORMS[platform].os, - cpu = PLATFORMS[platform].cpu.replace("-", "_"), - ), - ext = value.ext, - platform = platform, - exec_compatible_with = CONSTRAINTS[platform], - target_compatible_with = CONSTRAINTS[platform] - ); - -def _pact_reference_toolchain_repository_impl(repository_ctx): - repository_ctx.file("BUILD.bazel", _PACT_REFERENCE_BUILD_CONTENT.format( - platform = repository_ctx.attr.platform, - ext = repository_ctx.attr.ext, - exec_compatible_with = repository_ctx.attr.exec_compatible_with, - target_compatible_with = repository_ctx.attr.target_compatible_with - )); - repository_ctx.file("WORKSPACE.bazel", _PACT_WORKSPACE_CONTENT.format(repository_ctx.name)); - -pact_reference_toolchain_repository = repository_rule( - implementation = _pact_reference_toolchain_repository_impl, - attrs = { - "platform": attr.string( - doc = "Platform the pact-reference executable was built for.", - mandatory = False, - ), - "ext": attr.string(mandatory = True, default = "so"), - "exec_compatible_with": attr.string_list(mandatory = True), - "target_compatible_with": attr.string_list(mandatory = True) - }, -) diff --git a/rules_pact/private/toolchains.bzl b/rules_pact/private/toolchains.bzl deleted file mode 100644 index 6e4ef8c8..00000000 --- a/rules_pact/private/toolchains.bzl +++ /dev/null @@ -1,47 +0,0 @@ -"""pact_protobuf_plugin toolchain implementation""" - -def _pact_protobuf_plugin_toolchain_impl(ctx): - return platform_common.ToolchainInfo( - protobuf_plugin = ctx.file.protobuf_plugin, - manifest = ctx.file.manifest - ) - -pact_protobuf_plugin_toolchain = rule( - implementation = _pact_protobuf_plugin_toolchain_impl, - doc = "A pact protobuf plugin toolchain", - attrs = { - "protobuf_plugin": attr.label( - doc = "A pact protobuf plugin binary", - allow_single_file = True, - mandatory = True, - ), - "manifest": attr.label( - doc = "A json manifest", - allow_single_file = True, - mandatory = True, - ) - }, -) - -def _pact_reference_toolchain_impl(ctx): - return platform_common.ToolchainInfo( - pact_verifier_cli = ctx.file.pact_verifier_cli, - libpact_ffi = ctx.file.libpact_ffi - ) - -pact_reference_toolchain = rule( - implementation = _pact_reference_toolchain_impl, - doc = "A pact reference toolchain", - attrs = { - "pact_verifier_cli": attr.label( - doc = "A pact reference binary", - allow_single_file = True, - mandatory = True, - ), - "libpact_ffi": attr.label( - doc = "A pact ffi library", - allow_single_file = True, - mandatory = True, - ), - }, -) \ No newline at end of file diff --git a/rules_pact/private/versions.bzl b/rules_pact/private/versions.bzl deleted file mode 100644 index 339d9af2..00000000 --- a/rules_pact/private/versions.bzl +++ /dev/null @@ -1,33 +0,0 @@ -DEFAULT_PACT_PROTOBUF_PLUGIN_VERSISON="0.3.5" -PACT_PROTOBUF_PLUGINS_VERSIONS = { - "0.3.5": { - "darwin_amd64": struct(sha256 = "e3b09357c4ca793b7f0d78716ffe18916a7e72ed346ca549dfed79a4ff85cfc3"), - "linux_amd64": struct(sha256 = "9a0058f10e2eae9375c019453491897ac3eb87bb87b017c311d5d1ec3a4eb979"), - } -} -PACT_PROTOBUF_PLUGIN_JSON_VERSIONS = { - "0.3.5": struct(sha256 = "70fa091ec6728d0077470d7ab1125be02b9b8211b73a552ea37f14e0276b7a52"), -} - -PACT_VERIFIER_CLI_VERSIONS = { - "1.0.1": { - "darwin_amd64": struct(sha256 = "77ffc38f4564cfef42f64b9eb33bebfc4d787e65ef7ff7213640a3d63d2cf5a7"), - "linux_amd64": struct(sha256 = "57c8ae7c95f46e4a48d3d6a251853dd5dd58917e866266ced665fc48a3fdecdd"), - } -} -PACT_VERIFIER_LIB_PACTFFI_VERSIONS = { - "0.4.9": { - "darwin_amd64": struct(sha256 = "b8c87e2cc2f83ae9e79678d3288f2f9f7cea27d023576f565d8a203441600a59", ext = "dylib"), - "linux_amd64": struct(sha256 = "86d8b82ab0843909642bec8f3a1bea702bbe65f3665de18f024fdfdf62b8cf0c", ext = "so"), - } -} - -CONSTRAINTS = { - "darwin_amd64": ["@platforms//os:macos", "@platforms//cpu:x86_64"], - "linux_amd64": ["@platforms//os:linux", "@platforms//cpu:x86_64"], -} - -PLATFORMS = { - "darwin_amd64": struct(os = "osx", cpu = "x86_64"), - "linux_amd64": struct(os = "linux", cpu = "x86_64") -} \ No newline at end of file