bazel-contrib/rules_jsonnet

Issue with new bazel_skylib? Error: 'list' value has no field or method '_values'

Closed this issue · 10 comments

Hello,

I am trying to setup the jsonnet bazel rules in the following manner:
WORKSPACE:

http_archive(
    name = "bazel_skylib",
    sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
    urls = [
        "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
        "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
    ],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

http_archive(
    name = "io_bazel_rules_jsonnet",
    sha256 = "7f51f859035cd98bcf4f70dedaeaca47fe9fbae6b199882c516d67df416505da",
    strip_prefix = "rules_jsonnet-0.3.0",
    urls = ["https://github.com/bazelbuild/rules_jsonnet/archive/0.3.0.tar.gz"],
)

load("@io_bazel_rules_jsonnet//jsonnet:jsonnet.bzl", "jsonnet_repositories")

jsonnet_repositories()

load("@jsonnet_go//bazel:repositories.bzl", "jsonnet_go_repositories")

jsonnet_go_repositories()

load("@jsonnet_go//bazel:deps.bzl", "jsonnet_go_dependencies")

jsonnet_go_dependencies()

BUILD file:

load("@io_bazel_rules_jsonnet//jsonnet:jsonnet.bzl", "jsonnet_to_json")

jsonnet_to_json(
    name = "example1",
    src = "example1.jsonnet",
    outs = ["example1.json"],
)

And I get the following error:

ERROR: /home/flynow/.cache/bazel/_bazel_flynow/22c102f3a5fb9aa0fbbd6f2c12ffc9f6/external/io_bazel_rules_go/go/tools/coverdata/BUILD.bazel:3:16: in go_tool_library rule @io_bazel_rules_go//go/tools/coverdata:coverdata: 
Traceback (most recent call last):
        File "/home/flynow/.cache/bazel/_bazel_flynow/22c102f3a5fb9aa0fbbd6f2c12ffc9f6/external/io_bazel_rules_go/go/tools/coverdata/BUILD.bazel", line 3, column 16, in go_tool_library(name = 'coverdata')
                go_tool_library(
        File "/home/flynow/.cache/bazel/_bazel_flynow/22c102f3a5fb9aa0fbbd6f2c12ffc9f6/external/io_bazel_rules_go/go/private/rules/library.bzl", line 44, column 25, in _go_library_impl
                archive = go.archive(go, source)
        File "/home/flynow/.cache/bazel/_bazel_flynow/22c102f3a5fb9aa0fbbd6f2c12ffc9f6/external/io_bazel_rules_go/go/private/actions/archive.bzl", line 209, column 33, in emit_archive
                searchpaths = sets.union([searchpath], *[a.searchpaths for a in direct]),
        File "/home/flynow/.cache/bazel/_bazel_flynow/22c102f3a5fb9aa0fbbd6f2c12ffc9f6/external/bazel_skylib/lib/new_sets.bzl", line 190, column 42, in _union
                return struct(_values = dicts.add(*[s._values for s in args]))
Error: 'list' value has no field or method '_values'

I did some digging and found the following issue: bazel-contrib/rules_go#2157
Could it be that the jsonnet rules are not yet compatible with the new version of skylib?

Thanks for your help!

Just run into this now. Did you find a solution @JanJamaszyk-FlyNow ?

Unfortunately not. For now we reverted to the older skylib that comes with jsonnet.

This could be a problem for bazel 4.0.0 as I believe it requires a newer skylib.

It's just rules_go that seems to be outdated and quickly checking that repo, it looks like they resolved it. This could be a matter of updating this repository's dependency right?

Confirmed. If you update rules_go and bazel_gazelle yourself, it works! This is the part you'd be overriding:

https://github.com/google/go-jsonnet/blob/master/bazel/repositories.bzl

@finn-ball,
I have made these changes in the "WORKSPACE"

http_archive(
        name = "bazel_gazelle",
        sha256 = "222e49f034ca7a1d1231422cdb67066b885819885c356673cb1f72f748a3c9d4",
        urls = [
            "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.3/bazel-gazelle-v0.22.3.tar.gz",
            "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.3/bazel-gazelle-v0.22.3.tar.gz",
        ],
    )

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

gazelle_dependencies()

...
...
http_archive(
        name = "io_bazel_rules_go",
        sha256 = "7904dbecbaffd068651916dce77ff3437679f9d20e1a7956bff43826e7645fcc",
        urls = [
            "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.25.1/rules_go-v0.25.1.tar.gz",
            "https://github.com/bazelbuild/rules_go/releases/download/v0.25.1/rules_go-v0.25.1.tar.gz",
        ],
    )

Still, I am facing the Error:

ERROR: /home/ajithu/.cache/bazel/_bazel_ajithu/64f281071d7b4d7bf8c57a82ac06e780/external/io_bazel_rules_go/go/tools/coverdata/BUILD.bazel:3:16: in go_tool_library rule @io_bazel_rules_go//go/tools/coverdata:coverdata: 
Traceback (most recent call last):
	File "/home/ajithu/.cache/bazel/_bazel_ajithu/64f281071d7b4d7bf8c57a82ac06e780/external/io_bazel_rules_go/go/private/rules/library.bzl", line 42, column 25, in _go_library_impl
		archive = go.archive(go, source)
	File "/home/ajithu/.cache/bazel/_bazel_ajithu/64f281071d7b4d7bf8c57a82ac06e780/external/io_bazel_rules_go/go/private/actions/archive.bzl", line 219, column 29, in emit_archive
		cgo_exports = sets.union(cgo_exports, *[a.cgo_exports for a in direct])
	File "/home/ajithu/.cache/bazel/_bazel_ajithu/64f281071d7b4d7bf8c57a82ac06e780/external/bazel_skylib/lib/new_sets.bzl", line 189, column 42, in _union
		return struct(_values = dicts.add(*[s._values for s in args]))
Error: 'list' value has no field or method '_values'

I am using Bazel 4.0.0
I suspect the problem is here

Note:- I have used Skylib version 1.0.3 and 1.0.1. Both are having the same issue.

This works fine, Only thing we need to consider is the order in the WORKSPACE file.
those should be defined on top of io_bazel_rules_jsonnet

I'm not following the details but please send a PR if you have a fix

I have changed the sequence of the rules in my WORKSPACE file. PR won't be required I guess.
This is the sequence in the WORKSPACE file

  1. io_bazel_rules_go
  2. bazel_gazelle
  3. bazel_skylib.

When I mentioned bazel_skylib above the io_bazel_rules_go, I was getting the above-mentioned error.

 106 http_archive(
 107     name = "io_bazel_rules_go",
 108     sha256 = "8e968b5fcea1d2d64071872b12737bbb5514524ee5f0a4f54f5920266c261acb",
 109     urls = [
 110         "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
 111         "https://github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
 112     ],
 113 )
 114 load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
 115 
 116 go_rules_dependencies()
 117 
 118 go_register_toolchains("host")
 119 
 120 http_archive(
 121     name = "bazel_gazelle",
 122     sha256 = "bfd86b3cbe855d6c16c6fce60d76bd51f5c8dbc9cfcaef7a2bb5c1aafd0710e8",
 123     urls = [
 124         "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.21.0/bazel-gazelle-v0.21.0.tar.gz",
 125         "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.21.0/bazel-gazelle-v0.21.0.tar.gz",
 126     ],
 127 )
 128 # Another Gazelle repository hint.
 129 # gazelle:repository go_repository name=bazel_gazelle importpath=github.com/bazelbuild/bazel-gazelle/testtools
 130 
 131 load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
 132 
 133 gazelle_dependencies()
 134 #load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
 135 http_archive(
 136     name = "bazel_skylib",
 137     url = "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
 138     sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
 139 )
 140 
 141 load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
 142 bazel_skylib_workspace()
 143 
 144 

Closing this, as the issue at hand has been resolved. Furthermore, this should be less of an issue going forward due to bzlmod. The order in which dependencies are listed is no longer relevant.