jmhodges / bazel_gomock

Code to create Go mocks for bazel targets using mockgen
MIT License
59 stars 29 forks source link

Extension file 'gomock.bzl' has errors and referenced by '//cmd:go_default_test' #60

Closed Ishmeet closed 2 years ago

Ishmeet commented 2 years ago

I am using Mac M1 and trying to build a code using bazel which generated mock files using bazel_gomock. Below is the error and my config.

ERROR: Traceback (most recent call last):
    File "/private/var/tmp/_bazel_ishmeets/3d1f406019b68d337eb002ec6ebdf699/external/com_github_bazel_gomock/gomock.bzl", line 61, column 25, in <toplevel>
        _gomock_source = go_rule(
    File "/private/var/tmp/_bazel_ishmeets/3d1f406019b68d337eb002ec6ebdf699/external/io_bazel_rules_go/go/def.bzl", line 170, column 5, in go_rule
        def go_rule(**kwargs):
Error: go_rule() does not accept positional arguments, but got 1
ERROR: /Users/ishmeets/go/src/<snip>/BUILD.bazel:28:8: error loading package '<snip>/mock': Extension file 'gomock.bzl' has errors and referenced by '//cmd:go_default_test'
ERROR: Analysis of target '//cmd:go_default_test' failed; build aborted: error loading package '<snip>/mock': Extension file 'gomock.bzl' has errors
INFO: Elapsed time: 0.128s

WORKSPACE

bazel_gomock_commit = "fde78c91cf1783cc1e33ba278922ba67a6ee2a84"
http_archive(
    name = "bazel_gomock",
    sha256 = "692421b0c5e04ae4bc0bfff42fb1ce8671fe68daee2b8d8ea94657bb1fcddc0a",
    strip_prefix = "bazel_gomock-{v}".format(v = bazel_gomock_commit),
    urls = [
        "https://github.com/jmhodges/bazel_gomock/archive/{v}.tar.gz".format(v = bazel_gomock_commit),
    ],
)

go_repository(
    name = "com_github_golang_mock",
    build_file_proto_mode = "disable",
    build_naming_convention = "import",
    importpath = "github.com/golang/mock",
    replace = "github.com/golang/mock",
    sum = "h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=",
    version = "v1.6.0",    
)

go_repository(
    name = "com_github_bazel_gomock",
    commit = "e927c3073fed883d7eb11d0f71ef0e92b57dd82d",
    importpath = "github.com/jmhodges/bazel_gomock",
)

BUILD.bazel

# gazelle:ignore
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@com_github_bazel_gomock//:gomock.bzl", "gomock")

gomock(
    name = "gen_mock",
    out = "<snip>.go",
    interfaces = [
        "<snip>",
    ],
    library = "<snip>:go_default_library",
    package = "mock",
    self_package = "<snip>/mock",
    source = "<snip>:<snip>.go"
)
jmhodges commented 2 years ago

Oh! This library is now distributed part of rules_go as v0.32.0. I'd recommend porting to that version and trying again! They're doing a much better job of maintaining it. I meant to archive this repo. My apologies!