From 156aa1d156dff872b02bd524c773bcdd51770b58 Mon Sep 17 00:00:00 2001 From: John Bartholomew Date: Sun, 19 Jan 2025 11:07:01 +0000 Subject: [PATCH 1/6] remove outdated .tool-versions config It was added in Jan 2020 and apparently has never been updated since then. It refers to Bazel 1.2.1 which is long out of date (Bazel 5 is the oldest still maintained version, and Bazel 8 is the current active version). --- .tool-versions | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index 41f7186d8..000000000 --- a/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -bazel 1.2.1 From 86cd73aec92837c7dd1fba15ffc2c025cb1f067a Mon Sep 17 00:00:00 2001 From: John Bartholomew Date: Sun, 19 Jan 2025 11:16:00 +0000 Subject: [PATCH 2/6] remove unmaintained travis config As far as I'm aware we use GitHub Actions for our CI needs now. --- .travis.yml | 57 -------------------------------------------------- travisBazel.sh | 15 ------------- travisBuild.sh | 10 --------- 3 files changed, 82 deletions(-) delete mode 100644 .travis.yml delete mode 100755 travisBazel.sh delete mode 100755 travisBuild.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e10ce0869..000000000 --- a/.travis.yml +++ /dev/null @@ -1,57 +0,0 @@ -language: go -sudo: false -matrix: - include: - - go: 1.x - - go: 1.13.x - - go: 1.x - arch: amd64 - - name: "arch: arm64" - go: 1.x - arch: arm64 - env: - - PYTHON_COMMAND=python3 - - name: "arch: i686" - go: 1.x - arch: amd64 - env: - - PYTHON_COMMAND=python3 - - GOARCH=386 - - CGO_ENABLED=1 - - SKIP_PYTHON_BINDINGS_TESTS=1 - - name: "arch: ppc64le" - go: 1.x - arch: ppc64le - env: - - PYTHON_COMMAND=python3 - - name: "Bazel Check" - go: 1.x - script: ./travisBazel.sh - before_install: - - echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list - - curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - - - sudo apt-get update && sudo apt-get install bazel - - name: "Make Check go 1.x" - go: 1.x - before_install: - - echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list - - curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - - - sudo apt-get update && sudo apt-get install bazel make - - sudo apt install python3-dev - - pip install -U pytest --user - script: make all - -before_install: - - sudo apt install python3-dev - - pip install -U pytest --user - - go get github.com/axw/gocov/gocov - - go get github.com/mattn/goveralls - - go get github.com/fatih/color - - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0 - - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi - - go get github.com/sergi/go-diff/diffmatchpatch - -script: ./travisBuild.sh - -env: - - PYTHON_COMMAND=python diff --git a/travisBazel.sh b/travisBazel.sh deleted file mode 100755 index bd3b42aa2..000000000 --- a/travisBazel.sh +++ /dev/null @@ -1,15 +0,0 @@ -set -e -set -x - -# See: https://github.com/bazelbuild/rules_go#how-do-i-run-bazel-on-travis-ci -bazel --host_jvm_args=-Xmx500m \ - --host_jvm_args=-Xms500m \ - test \ - --spawn_strategy=standalone \ - --genrule_strategy=standalone \ - --test_strategy=standalone \ - --local_ram_resources=1536 \ - --noshow_progress \ - --verbose_failures \ - --test_output=errors \ - //:go_default_test diff --git a/travisBuild.sh b/travisBuild.sh deleted file mode 100755 index a27c8a547..000000000 --- a/travisBuild.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -e - -run_tests() { - golangci-lint run ./... - SKIP_GO_TESTS=1 ./tests.sh -} - -run_tests From 64c3804248806a134b9b5d4f1f209644734470e0 Mon Sep 17 00:00:00 2001 From: John Bartholomew Date: Sun, 19 Jan 2025 12:14:43 +0000 Subject: [PATCH 3/6] update Bazel rules with gazelle and manually --- BUILD.bazel | 4 +++- MODULE.bazel | 3 ++- bazel/deps.bzl | 32 +++++++++++++++----------------- formatter/BUILD.bazel | 12 ++++++++++-- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 2575a00e5..1e3279403 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,8 +1,8 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") load( "@bazel_gazelle//:def.bzl", "gazelle", ) +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") # gazelle:prefix github.com/google/go-jsonnet gazelle( @@ -13,6 +13,7 @@ go_library( name = "go_default_library", srcs = [ "builtins.go", + "debugger.go", "doc.go", "error_formatter.go", "imports.go", @@ -32,6 +33,7 @@ go_library( "//internal/errors:go_default_library", "//internal/parser:go_default_library", "//internal/program:go_default_library", + "//toolutils:go_default_library", "@io_k8s_sigs_yaml//:go_default_library", "@org_golang_x_crypto//sha3:go_default_library", ], diff --git a/MODULE.bazel b/MODULE.bazel index 05b2e5c2e..b4477a4c8 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module(name = "jsonnet_go", version = "0.0.0") -bazel_dep(name = "gazelle", version = "0.37.0", repo_name = "bazel_gazelle") +bazel_dep(name = "gazelle", version = "0.41.0", repo_name = "bazel_gazelle") bazel_dep(name = "jsonnet", version = "0.20.0", repo_name = "cpp_jsonnet") bazel_dep(name = "rules_go", version = "0.48.0", repo_name = "io_bazel_rules_go") @@ -11,4 +11,5 @@ use_repo( "com_github_fatih_color", "com_github_sergi_go_diff", "io_k8s_sigs_yaml", + "org_golang_x_crypto", ) diff --git a/bazel/deps.bzl b/bazel/deps.bzl index 571dedf7e..c31ce6eb8 100644 --- a/bazel/deps.bzl +++ b/bazel/deps.bzl @@ -1,18 +1,17 @@ -load( - "@io_bazel_rules_go//go:deps.bzl", - "go_register_toolchains", - "go_rules_dependencies", -) load( "@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository", ) +load( + "@io_bazel_rules_go//go:deps.bzl", + "go_register_toolchains", + "go_rules_dependencies", +) def jsonnet_go_dependencies(go_sdk_version = "host"): - go_rules_dependencies() - go_register_toolchains(version = go_sdk_version) gazelle_dependencies() + go_register_toolchains(version = go_sdk_version) go_repository( name = "com_github_davecgh_go_spew", importpath = "github.com/davecgh/go-spew", @@ -26,7 +25,6 @@ def jsonnet_go_dependencies(go_sdk_version = "host"): sum = "h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=", version = "v1.12.0", ) - go_repository( name = "com_github_kr_pretty", importpath = "github.com/kr/pretty", @@ -104,8 +102,8 @@ def jsonnet_go_dependencies(go_sdk_version = "host"): go_repository( name = "org_golang_x_crypto", importpath = "golang.org/x/crypto", - sum = "h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=", - version = "v0.9.0", + sum = "h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=", + version = "v0.17.0", ) go_repository( name = "org_golang_x_net", @@ -113,22 +111,22 @@ def jsonnet_go_dependencies(go_sdk_version = "host"): sum = "h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=", version = "v0.10.0", ) - go_repository( name = "org_golang_x_sys", importpath = "golang.org/x/sys", - sum = "h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=", - version = "v0.8.0", + sum = "h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=", + version = "v0.15.0", ) go_repository( name = "org_golang_x_term", importpath = "golang.org/x/term", - sum = "h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=", - version = "v0.8.0", + sum = "h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=", + version = "v0.15.0", ) go_repository( name = "org_golang_x_text", importpath = "golang.org/x/text", - sum = "h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=", - version = "v0.9.0", + sum = "h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=", + version = "v0.14.0", ) + go_rules_dependencies() diff --git a/formatter/BUILD.bazel b/formatter/BUILD.bazel index fab28169e..26a74629b 100644 --- a/formatter/BUILD.bazel +++ b/formatter/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", @@ -7,7 +7,15 @@ go_library( visibility = ["//visibility:public"], deps = [ "//ast:go_default_library", - "//internal/parser:go_default_library", "//internal/formatter:go_default_library", + "//internal/parser:go_default_library", ], ) + +go_test( + name = "go_default_test", + srcs = ["formatter_test.go"], + data = glob(["testdata/**"]), + embed = [":go_default_library"], + deps = ["//internal/testutils:go_default_library"], +) From e1304d1698fb94fbc3dc163c6b8e051d1da8e9cd Mon Sep 17 00:00:00 2001 From: John Bartholomew Date: Mon, 20 Jan 2025 19:41:37 +0000 Subject: [PATCH 4/6] update cppjsonnet and depend on a specific commit of jsonnet This changes the bazel module dependencies so that the C++ jsonnet repo dependency (which is actually used as the source for the standard library and nothing else in the Bazel build) comes from a specific commit of the jsonnet repo, rather than depending on the 'published' jsonnet 0.20.0. The two repos are tightly coupled anyway so I think this more accurately reflects the situation. Particularly since the C++ repo is also linked (at a specific commit) as a git submodule, which is used for non-Bazel build and testing. --- MODULE.bazel | 17 ++++++++++++++++- bazel/repositories.bzl | 4 ++-- cpp-jsonnet | 2 +- update_cpp_jsonnet.sh | 3 ++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index b4477a4c8..00e9aeddf 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,7 +1,22 @@ module(name = "jsonnet_go", version = "0.0.0") +http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +# NB: update_cpp_jsonnet.sh looks for these. +CPP_JSONNET_SHA256 = "e7d14d8ad65dc334b9a9f3bd1c542a82b3b80029860a8d78fd829b23d0e9845b" +CPP_JSONNET_GITHASH = "5a4e8e34cc1fe841bdebb983646b9b9ae8fa8ca4" + +# We don't use a normal bazel_dep reference for the cpp_jsonnet module, +# because we want to pin to the specific jsonnet commit (which might not +# even exactly match a released version). +http_archive( + name = "cpp_jsonnet", + sha256 = CPP_JSONNET_SHA256, + strip_prefix = "jsonnet-%s" % CPP_JSONNET_GITHASH, + urls = ["https://github.com/google/jsonnet/archive/%s.tar.gz" % CPP_JSONNET_GITHASH], +) + bazel_dep(name = "gazelle", version = "0.41.0", repo_name = "bazel_gazelle") -bazel_dep(name = "jsonnet", version = "0.20.0", repo_name = "cpp_jsonnet") bazel_dep(name = "rules_go", version = "0.48.0", repo_name = "io_bazel_rules_go") go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 48630e3bd..63300fb2b 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -4,8 +4,8 @@ load( ) # NB: update_cpp_jsonnet.sh looks for these. -CPP_JSONNET_SHA256 = "9e545f17b614c89d40d1f58d7f8fceded4cc93d1d29edfd8a93833b61201fd20" -CPP_JSONNET_GITHASH = "4487bfb8ba7ed7a3d91d79d4a1aa2205e7839558" +CPP_JSONNET_SHA256 = "e7d14d8ad65dc334b9a9f3bd1c542a82b3b80029860a8d78fd829b23d0e9845b" +CPP_JSONNET_GITHASH = "5a4e8e34cc1fe841bdebb983646b9b9ae8fa8ca4" def jsonnet_go_repositories(): http_archive( diff --git a/cpp-jsonnet b/cpp-jsonnet index 4487bfb8b..5a4e8e34c 160000 --- a/cpp-jsonnet +++ b/cpp-jsonnet @@ -1 +1 @@ -Subproject commit 4487bfb8ba7ed7a3d91d79d4a1aa2205e7839558 +Subproject commit 5a4e8e34cc1fe841bdebb983646b9b9ae8fa8ca4 diff --git a/update_cpp_jsonnet.sh b/update_cpp_jsonnet.sh index 777e22eac..76c4d2206 100755 --- a/update_cpp_jsonnet.sh +++ b/update_cpp_jsonnet.sh @@ -17,10 +17,11 @@ sha256=$(curl -fL https://github.com/google/jsonnet/archive/$hash.tar.gz | shasu sed -i.bak \ -e "s/CPP_JSONNET_SHA256 = .*/CPP_JSONNET_SHA256 = \"$sha256\"/;" \ -e "s/CPP_JSONNET_GITHASH = .*/CPP_JSONNET_GITHASH = \"$hash\"/;" \ - bazel/repositories.bzl + bazel/repositories.bzl MODULE.bazel # NB: macOS sed doesn't support -i without arg. This is the easy workaround. rm bazel/repositories.bzl.bak +rm MODULE.bazel.bak set +x echo From 9e1e952016fb0d7823a6f5a68929e9d7d1abdbce Mon Sep 17 00:00:00 2001 From: John Bartholomew Date: Mon, 20 Jan 2025 20:56:51 +0000 Subject: [PATCH 5/6] port some Python wrapper code fixes from C++ jsonnet See commits on the C++ repo: - https://github.com/google/jsonnet/commit/913281d203578bb394995bacc792f2576371e06c - https://github.com/google/jsonnet/commit/842d31eefdb5f7890432d24cf8f47f6fb5c6f663 --- python/_jsonnet.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/_jsonnet.c b/python/_jsonnet.c index f60669d43..1069a7bf1 100644 --- a/python/_jsonnet.c +++ b/python/_jsonnet.c @@ -186,7 +186,7 @@ static struct JsonnetJsonValue *cpython_native_callback( } // Call python function. - result = PyEval_CallObject(ctx->callback, arglist); + result = PyObject_CallObject(ctx->callback, arglist); Py_DECREF(arglist); if (result == NULL) { @@ -226,7 +226,7 @@ static int cpython_import_callback(void *ctx_, const char *base, const char *rel PyEval_RestoreThread(*ctx->py_thread); arglist = Py_BuildValue("(s, s)", base, rel); - result = PyEval_CallObject(ctx->callback, arglist); + result = PyObject_CallObject(ctx->callback, arglist); Py_DECREF(arglist); if (result == NULL) { @@ -255,7 +255,7 @@ static int cpython_import_callback(void *ctx_, const char *base, const char *rel success = 0; } else { char *content_buf; - ssize_t content_len; + Py_ssize_t content_len; #if PY_MAJOR_VERSION >= 3 const char *found_here_cstr = PyUnicode_AsUTF8(file_name); #else @@ -665,7 +665,7 @@ static struct PyModuleDef _module = PyMODINIT_FUNC PyInit__gojsonnet(void) { - PyObject *module = PyModule_Create(&_module); + PyObject *module = PyModule_Create(&_module); PyObject *version_str = PyUnicode_FromString(LIB_JSONNET_VERSION); if (PyModule_AddObject(module, "version", PyUnicode_FromString(LIB_JSONNET_VERSION)) < 0) { Py_XDECREF(version_str); From 923f51b8e3ba3fd49dd8b9e859e1c0304f7cdbd4 Mon Sep 17 00:00:00 2001 From: John Bartholomew Date: Mon, 20 Jan 2025 21:09:49 +0000 Subject: [PATCH 6/6] switch to go mod based goveralls in CI --- .github/workflows/ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index efd9e4e90..00dee0410 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,15 +78,14 @@ jobs: # version: v1.30.0 - run: make all - name: Install goveralls - env: - GO111MODULE: off run: | export GOPATH=$GITHUB_WORKSPACE - go get github.com/mattn/goveralls + go install github.com/mattn/goveralls@v0.0.12 - name: Send coverage env: COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./bin/goveralls -coverprofile=coverage.out -service=github + run: | + ./bin/goveralls -coverprofile=coverage.out -service=github goreleaser: name: Goreleaser