Skip to content

Commit

Permalink
Merge pull request #2265 from tweag/cb/remove-json-lib
Browse files Browse the repository at this point in the history
Use `json` module instead of bazel_json
  • Loading branch information
mergify[bot] authored Nov 26, 2024
2 parents 4cd4e28 + f69de40 commit a5e4216
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 2,341 deletions.
1 change: 0 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ filegroup(
"//protobuf:all_files",
"//rule_info:all_files",
"//tools:all_files",
"//vendor/bazel_json/lib:all_files",
],
visibility = ["//visibility:public"],
)
8 changes: 0 additions & 8 deletions haskell/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ exports_files(
visibility = ["//tests/shellcheck:__pkg__"],
)

bzl_library(
name = "bazel_json",
srcs = [
"//vendor/bazel_json/lib:json_parser.bzl",
],
)

# @bazel_tools//tools does not define a bzl_library itself, instead we are
# supposed to define our own using the @bazel_tools//tools:bzl_srcs filegroup.
# See https://github.com/bazelbuild/skydoc/issues/166
Expand All @@ -82,7 +75,6 @@ bzl_library(
srcs = glob(["**/*.bzl"]),
visibility = ["//visibility:public"],
deps = [
":bazel_json",
":bazel_tools",
":rules_cc",
"//haskell/asterius:asterius_bzl",
Expand Down
18 changes: 7 additions & 11 deletions haskell/cabal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ load("@bazel_skylib//lib:sets.bzl", "sets")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe", "read_netrc", "use_netrc")
load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value")
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain")
load("//vendor/bazel_json/lib:json_parser.bzl", "json_parse")
load(":cc.bzl", "cc_interop_info", "ghc_cc_program_args")
load(":haddock.bzl", "generate_unified_haddock_info")
load(":private/actions/info.bzl", "library_info_output_groups")
Expand Down Expand Up @@ -1339,7 +1338,7 @@ version: 0.0.0.0
repository_ctx,
stack + ["ls", "dependencies", "json", "--global-hints", "--external"],
)
package_specs = json_parse(exec_result.stdout)
package_specs = json.decode(exec_result.stdout)

resolved = {}
versioned_packages_names = {_chop_version(p): _version(p) for p in versioned_packages}
Expand Down Expand Up @@ -1386,7 +1385,7 @@ def _pin_packages(repository_ctx, resolved):
executable = False,
auth = auth,
)
hashes_json = json_parse(repository_ctx.read("all-cabal-hashes-hackage.json"))
hashes_json = json.decode(repository_ctx.read("all-cabal-hashes-hackage.json"))
hashes_object = _parse_json_field(
json = hashes_json,
field = "object",
Expand All @@ -1413,9 +1412,9 @@ def _pin_packages(repository_ctx, resolved):
output = "{name}-{version}.json".format(**spec),
executable = False,
)
json = json_parse(repository_ctx.read("{name}-{version}.json".format(**spec)))
name_version_json = json.decode(repository_ctx.read("{name}-{version}.json".format(**spec)))
hashes = _parse_json_field(
json = json,
json = name_version_json,
field = "package-hashes",
ty = "dict",
errmsg = errmsg.format(context = "all-cabal-hashes package description"),
Expand All @@ -1426,7 +1425,7 @@ def _pin_packages(repository_ctx, resolved):
cabal_url = "{url}/{name}/{version}/{name}.cabal".format(url = hashes_url, **spec)
spec["pinned"] = {
"url": _parse_json_field(
json = json,
json = name_version_json,
field = "package-locations",
ty = "list",
errmsg = errmsg.format(context = "all-cabal-hashes package description"),
Expand Down Expand Up @@ -1704,12 +1703,9 @@ Try to regenerate it by running the following command:
""".format(filename = filename, workspace = repository_ctx.name)

# Parse JSON
pinned = json_parse(
pinned = json.decode(
repository_ctx.read(repository_ctx.attr.stack_snapshot_json),
fail_on_invalid = False,
)
if pinned == None:
fail(errmsg.format(error = "Failed to parse JSON."))

# Read snapshot.json data and validate required fields.
expected_checksum = _parse_json_field(
Expand Down Expand Up @@ -1969,7 +1965,7 @@ def _stack_snapshot_impl(repository_ctx):
tools = [_label_to_string(label) for label in repository_ctx.attr.tools]

components_dependencies = {
comp: json_parse(deps)
comp: json.decode(deps)
for comp, deps in repository_ctx.attr.components_dependencies.items()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import Data.List (isInfixOf)
import IntegrationTesting
import Test.Hspec (hspec, it)
import Test.Hspec (describe, hspec, it)

main :: IO ()
main = hspec $ do
it "bazel run repl" $ do
bazel <- setupTestBazel
let p (_stdout, stderr) = "parsing JSON failed" `isInfixOf` stderr
in
failedOutputSatisfy p (bazel ["run", "//:hs-bin@repl", "--", "-ignore-dot-ghci", "-e", ":main"])
describe "bazel run repl" $ do
it "fails with a json decode error" $ do
-- this is evidence that it used the deficient `stack` script provided in hs_override_stack_test/
bazel <- setupTestBazel
let p (_stdout, stderr) = "Error in decode: at offset" `isInfixOf` stderr
in
failedOutputSatisfy p (bazel ["run", "//:hs-bin@repl", "--", "-ignore-dot-ghci", "-e", ":main"])
20 changes: 0 additions & 20 deletions vendor/bazel_json/LICENSE

This file was deleted.

9 changes: 0 additions & 9 deletions vendor/bazel_json/lib/BUILD

This file was deleted.

Loading

0 comments on commit a5e4216

Please sign in to comment.