Skip to content

Commit a5e4216

Browse files
authored
Merge pull request #2265 from tweag/cb/remove-json-lib
Use `json` module instead of bazel_json
2 parents 4cd4e28 + f69de40 commit a5e4216

File tree

11 files changed

+15
-2341
lines changed

11 files changed

+15
-2341
lines changed

BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ filegroup(
3737
"//protobuf:all_files",
3838
"//rule_info:all_files",
3939
"//tools:all_files",
40-
"//vendor/bazel_json/lib:all_files",
4140
],
4241
visibility = ["//visibility:public"],
4342
)

haskell/BUILD.bazel

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ exports_files(
5151
visibility = ["//tests/shellcheck:__pkg__"],
5252
)
5353

54-
bzl_library(
55-
name = "bazel_json",
56-
srcs = [
57-
"//vendor/bazel_json/lib:json_parser.bzl",
58-
],
59-
)
60-
6154
# @bazel_tools//tools does not define a bzl_library itself, instead we are
6255
# supposed to define our own using the @bazel_tools//tools:bzl_srcs filegroup.
6356
# See https://github.com/bazelbuild/skydoc/issues/166
@@ -82,7 +75,6 @@ bzl_library(
8275
srcs = glob(["**/*.bzl"]),
8376
visibility = ["//visibility:public"],
8477
deps = [
85-
":bazel_json",
8678
":bazel_tools",
8779
":rules_cc",
8880
"//haskell/asterius:asterius_bzl",

haskell/cabal.bzl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ load("@bazel_skylib//lib:sets.bzl", "sets")
66
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe", "read_netrc", "use_netrc")
77
load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value")
88
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain")
9-
load("//vendor/bazel_json/lib:json_parser.bzl", "json_parse")
109
load(":cc.bzl", "cc_interop_info", "ghc_cc_program_args")
1110
load(":haddock.bzl", "generate_unified_haddock_info")
1211
load(":private/actions/info.bzl", "library_info_output_groups")
@@ -1339,7 +1338,7 @@ version: 0.0.0.0
13391338
repository_ctx,
13401339
stack + ["ls", "dependencies", "json", "--global-hints", "--external"],
13411340
)
1342-
package_specs = json_parse(exec_result.stdout)
1341+
package_specs = json.decode(exec_result.stdout)
13431342

13441343
resolved = {}
13451344
versioned_packages_names = {_chop_version(p): _version(p) for p in versioned_packages}
@@ -1386,7 +1385,7 @@ def _pin_packages(repository_ctx, resolved):
13861385
executable = False,
13871386
auth = auth,
13881387
)
1389-
hashes_json = json_parse(repository_ctx.read("all-cabal-hashes-hackage.json"))
1388+
hashes_json = json.decode(repository_ctx.read("all-cabal-hashes-hackage.json"))
13901389
hashes_object = _parse_json_field(
13911390
json = hashes_json,
13921391
field = "object",
@@ -1413,9 +1412,9 @@ def _pin_packages(repository_ctx, resolved):
14131412
output = "{name}-{version}.json".format(**spec),
14141413
executable = False,
14151414
)
1416-
json = json_parse(repository_ctx.read("{name}-{version}.json".format(**spec)))
1415+
name_version_json = json.decode(repository_ctx.read("{name}-{version}.json".format(**spec)))
14171416
hashes = _parse_json_field(
1418-
json = json,
1417+
json = name_version_json,
14191418
field = "package-hashes",
14201419
ty = "dict",
14211420
errmsg = errmsg.format(context = "all-cabal-hashes package description"),
@@ -1426,7 +1425,7 @@ def _pin_packages(repository_ctx, resolved):
14261425
cabal_url = "{url}/{name}/{version}/{name}.cabal".format(url = hashes_url, **spec)
14271426
spec["pinned"] = {
14281427
"url": _parse_json_field(
1429-
json = json,
1428+
json = name_version_json,
14301429
field = "package-locations",
14311430
ty = "list",
14321431
errmsg = errmsg.format(context = "all-cabal-hashes package description"),
@@ -1704,12 +1703,9 @@ Try to regenerate it by running the following command:
17041703
""".format(filename = filename, workspace = repository_ctx.name)
17051704

17061705
# Parse JSON
1707-
pinned = json_parse(
1706+
pinned = json.decode(
17081707
repository_ctx.read(repository_ctx.attr.stack_snapshot_json),
1709-
fail_on_invalid = False,
17101708
)
1711-
if pinned == None:
1712-
fail(errmsg.format(error = "Failed to parse JSON."))
17131709

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

19711967
components_dependencies = {
1972-
comp: json_parse(deps)
1968+
comp: json.decode(deps)
19731969
for comp, deps in repository_ctx.attr.components_dependencies.items()
19741970
}
19751971

rules_haskell_tests/tests/stack-snapshot-deps/HsOverrideStackTest.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import Data.List (isInfixOf)
44
import IntegrationTesting
5-
import Test.Hspec (hspec, it)
5+
import Test.Hspec (describe, hspec, it)
66

77
main :: IO ()
88
main = hspec $ do
9-
it "bazel run repl" $ do
10-
bazel <- setupTestBazel
11-
let p (_stdout, stderr) = "parsing JSON failed" `isInfixOf` stderr
12-
in
13-
failedOutputSatisfy p (bazel ["run", "//:hs-bin@repl", "--", "-ignore-dot-ghci", "-e", ":main"])
9+
describe "bazel run repl" $ do
10+
it "fails with a json decode error" $ do
11+
-- this is evidence that it used the deficient `stack` script provided in hs_override_stack_test/
12+
bazel <- setupTestBazel
13+
let p (_stdout, stderr) = "Error in decode: at offset" `isInfixOf` stderr
14+
in
15+
failedOutputSatisfy p (bazel ["run", "//:hs-bin@repl", "--", "-ignore-dot-ghci", "-e", ":main"])

vendor/bazel_json/LICENSE

Lines changed: 0 additions & 20 deletions
This file was deleted.

vendor/bazel_json/lib/BUILD

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)