From 6ff3d56864592c6785c2cf4c45fc0c168d5eca3f Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Mon, 7 Nov 2022 13:36:46 -0700 Subject: [PATCH 01/13] Refactored the loading of markdown deps --- BUILD.bazel | 13 ++ WORKSPACE | 31 +++-- deps.bzl | 99 +++------------ markdown/deps.bzl | 22 +++- .../github_markdown_toc_go_repositories.bzl | 23 ++++ .../github_markdown_toc_go_repositories.bzl | 120 ------------------ markdown/tools/BUILD.bazel | 2 +- tests/markdown_tests/tools_tests/BUILD.bazel | 24 ++-- 8 files changed, 107 insertions(+), 227 deletions(-) create mode 100644 markdown/github_markdown_toc_go_repositories.bzl delete mode 100644 markdown/private/github_markdown_toc_go_repositories.bzl diff --git a/BUILD.bazel b/BUILD.bazel index 3f5f627e..c02ad837 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_gazelle//:def.bzl", "gazelle") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load( "//bzlformat:defs.bzl", @@ -7,6 +8,18 @@ load( load("//tests:integration_test_common.bzl", "INTEGRATION_TEST_TAGS") load("//updatesrc:defs.bzl", "updatesrc_update_all") +# gazelle:prefix github.com/cgrindel/bazel-starlib +gazelle(name = "gazelle") + +# gazelle( +# name = "gazelle_update_repos_for_github_markdown_toc", +# args = [ +# "github.com/ekalinin/github-markdown-toc.go", +# "-to_macro=markdown/deps.bzl%bazel_starlib_markdown_go_dependencies", +# ], +# command = "update-repos", +# ) + # MARK: - Bazel Starlark Lint and Formatting bzlformat_pkg(name = "bzlformat") diff --git a/WORKSPACE b/WORKSPACE index 2711b6f8..a47925da 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -4,6 +4,23 @@ load("//:deps.bzl", "bazel_starlib_dependencies") bazel_starlib_dependencies() +# gazelle:repo bazel_gazelle +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") +load("//markdown:deps.bzl", "bazel_starlib_markdown_dependencies") + +bazel_starlib_markdown_dependencies() + +# load("//:markdown/github_markdown_toc_go_repositories.bzl", "github_markdown_toc_go_repositories") +# # gazelle:repository_macro markdown/github_markdown_toc_go_repositories.bzl%github_markdown_toc_go_repositories +# github_markdown_toc_go_repositories() + +go_rules_dependencies() + +go_register_toolchains(version = "1.19.1") + +gazelle_dependencies() + load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") bazel_skylib_workspace() @@ -35,20 +52,6 @@ buildifier_prebuilt_register_toolchains() # markdown_register_node_deps() -# MARK: - Golang Deps (gh-md-toc) - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") -load("//markdown:deps.bzl", "bazel_starlib_markdown_dependencies") - -bazel_starlib_markdown_dependencies() - -go_rules_dependencies() - -go_register_toolchains(version = "1.17.6") - -gazelle_dependencies() - # MARK: - Integration Testing load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/deps.bzl b/deps.bzl index 84601648..8daefc60 100644 --- a/deps.bzl +++ b/deps.bzl @@ -15,57 +15,6 @@ def _bazeldoc_dependencies(): ], ) -def _markdown_dependencies(): - # GH140: Temporarily disable markdown while adding support for - # --incompatible_disallow_empty_glob. - - # maybe( - # http_archive, - # name = "build_bazel_rules_nodejs", - # sha256 = "e328cb2c9401be495fa7d79c306f5ee3040e8a03b2ebb79b022e15ca03770096", - # urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.4.2/rules_nodejs-5.4.2.tar.gz"], - # ) - - maybe( - http_archive, - name = "io_bazel_rules_go", - sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", - ], - ) - - maybe( - http_archive, - name = "bazel_gazelle", - sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", - ], - ) - - maybe( - http_archive, - name = "ekalinin_github_markdown_toc", - sha256 = "6bfeab2b28e5c7ad1d5bee9aa6923882a01f56a7f2d0f260f01acde2111f65af", - strip_prefix = "github-markdown-toc.go-1.2.0", - urls = ["https://github.com/ekalinin/github-markdown-toc.go/archive/refs/tags/1.2.0.tar.gz"], - build_file_content = """\ -load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") - -go_binary( - name = "gh_md_toc", - srcs = glob(["*.go"], exclude = ["*_test.go"]), - deps = [ - "@in_gopkg_alecthomas_kingpin_v2//:go_default_library", - ], - visibility = ["//visibility:public"], -) -""", - ) - def _prebuilt_buildtools_dependencies(): maybe( http_archive, @@ -86,26 +35,6 @@ def _prebuilt_buildtools_dependencies(): ) def _compile_from_source_buildtools_dependencies(): - maybe( - http_archive, - name = "io_bazel_rules_go", - sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", - ], - ) - - maybe( - http_archive, - name = "bazel_gazelle", - sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", - ], - ) - maybe( http_archive, name = "com_google_protobuf", @@ -136,8 +65,7 @@ def _compile_from_source_buildtools_dependencies(): def bazel_starlib_dependencies( use_prebuilt_buildtools = True, - use_bazeldoc = True, - use_markdown = True): + use_bazeldoc = True): """Declares the dependencies for bazel-starlib. Args: @@ -145,8 +73,6 @@ def bazel_starlib_dependencies( version of `bazelbuild/buildtools`. use_bazeldoc: A `bool` specifying whether the `bazeldoc` dependencies should be loaded. - use_markdown: A `bool` specifying whether the `markdown` depdendencies - should be loaded. """ maybe( http_archive, @@ -158,12 +84,29 @@ def bazel_starlib_dependencies( sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", ) + maybe( + http_archive, + name = "io_bazel_rules_go", + sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", + ], + ) + + maybe( + http_archive, + name = "bazel_gazelle", + sha256 = "efbbba6ac1a4fd342d5122cbdfdb82aeb2cf2862e35022c752eaddffada7c3f3", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz", + ], + ) + if use_bazeldoc: _bazeldoc_dependencies() - if use_markdown: - _markdown_dependencies() - if use_prebuilt_buildtools: _prebuilt_buildtools_dependencies() else: diff --git a/markdown/deps.bzl b/markdown/deps.bzl index 3d0b8ee8..21d5aa40 100644 --- a/markdown/deps.bzl +++ b/markdown/deps.bzl @@ -1,7 +1,27 @@ """Dependency Functions for markdown""" -load("//markdown/private:github_markdown_toc_go_repositories.bzl", "github_markdown_toc_go_repositories") +load("@bazel_gazelle//:deps.bzl", "go_repository") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("//markdown:github_markdown_toc_go_repositories.bzl", "github_markdown_toc_go_repositories") def bazel_starlib_markdown_dependencies(): + # GH140: Temporarily disable markdown while adding support for + # --incompatible_disallow_empty_glob. + + # maybe( + # http_archive, + # name = "build_bazel_rules_nodejs", + # sha256 = "e328cb2c9401be495fa7d79c306f5ee3040e8a03b2ebb79b022e15ca03770096", + # urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.4.2/rules_nodejs-5.4.2.tar.gz"], + # ) + + maybe( + go_repository, + name = "com_github_ekalinin_github_markdown_toc_go", + importpath = "github.com/ekalinin/github-markdown-toc.go", + sum = "h1:Y3V7JoKbxDnWKpHV7KIektVSNA7CScWc1ECBgAsyMco=", + version = "v0.0.0-20201214095852-3ab0fa2ca613", + ) + # Deps for github-markdown-toc.go github_markdown_toc_go_repositories() diff --git a/markdown/github_markdown_toc_go_repositories.bzl b/markdown/github_markdown_toc_go_repositories.bzl new file mode 100644 index 00000000..d024530c --- /dev/null +++ b/markdown/github_markdown_toc_go_repositories.bzl @@ -0,0 +1,23 @@ +"""Go repository dependencies for github-markdown-toc-go.""" + +load("@bazel_gazelle//:deps.bzl", "go_repository") + +def github_markdown_toc_go_repositories(): + go_repository( + name = "com_github_alecthomas_template", + importpath = "github.com/alecthomas/template", + sum = "h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=", + version = "v0.0.0-20160405071501-a0175ee3bccc", + ) + go_repository( + name = "com_github_alecthomas_units", + importpath = "github.com/alecthomas/units", + sum = "h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=", + version = "v0.0.0-20151022065526-2efee857e7cf", + ) + go_repository( + name = "in_gopkg_alecthomas_kingpin_v2", + importpath = "gopkg.in/alecthomas/kingpin.v2", + sum = "h1:CC8tJ/xljioKrK6ii3IeWVXU4Tw7VB+LbjZBJaBxN50=", + version = "v2.2.4", + ) diff --git a/markdown/private/github_markdown_toc_go_repositories.bzl b/markdown/private/github_markdown_toc_go_repositories.bzl deleted file mode 100644 index 378c045f..00000000 --- a/markdown/private/github_markdown_toc_go_repositories.bzl +++ /dev/null @@ -1,120 +0,0 @@ -"""Go repository dependencies for github-markdown-toc-go.""" - -load("@bazel_gazelle//:deps.bzl", "go_repository") - -def github_markdown_toc_go_repositories(): - """Declares the Golang repository dependencies for github-markdown-toc-go.""" - go_repository( - name = "com_github_alecthomas_assert", - importpath = "github.com/alecthomas/assert", - sum = "h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U=", - version = "v0.0.0-20170929043011-405dbfeb8e38", - ) - go_repository( - name = "com_github_alecthomas_colour", - importpath = "github.com/alecthomas/colour", - sum = "h1:nOE9rJm6dsZ66RGWYSFrXw461ZIt9A6+nHgL7FRrDUk=", - version = "v0.1.0", - ) - go_repository( - name = "com_github_alecthomas_repr", - importpath = "github.com/alecthomas/repr", - sum = "h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48=", - version = "v0.0.0-20210801044451-80ca428c5142", - ) - go_repository( - name = "com_github_alecthomas_template", - importpath = "github.com/alecthomas/template", - sum = "h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=", - version = "v0.0.0-20160405071501-a0175ee3bccc", - ) - go_repository( - name = "com_github_alecthomas_units", - importpath = "github.com/alecthomas/units", - sum = "h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=", - version = "v0.0.0-20151022065526-2efee857e7cf", - ) - go_repository( - name = "com_github_davecgh_go_spew", - importpath = "github.com/davecgh/go-spew", - sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=", - version = "v1.1.1", - ) - go_repository( - name = "com_github_kr_pretty", - importpath = "github.com/kr/pretty", - sum = "h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=", - version = "v0.1.0", - ) - go_repository( - name = "com_github_kr_pty", - importpath = "github.com/kr/pty", - sum = "h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=", - version = "v1.1.1", - ) - go_repository( - name = "com_github_kr_text", - importpath = "github.com/kr/text", - sum = "h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=", - version = "v0.1.0", - ) - go_repository( - name = "com_github_mattn_go_isatty", - importpath = "github.com/mattn/go-isatty", - sum = "h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=", - version = "v0.0.14", - ) - go_repository( - name = "com_github_pmezard_go_difflib", - importpath = "github.com/pmezard/go-difflib", - sum = "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=", - version = "v1.0.0", - ) - go_repository( - name = "com_github_sergi_go_diff", - importpath = "github.com/sergi/go-diff", - sum = "h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=", - version = "v1.2.0", - ) - go_repository( - name = "com_github_stretchr_objx", - importpath = "github.com/stretchr/objx", - sum = "h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=", - version = "v0.1.0", - ) - go_repository( - name = "com_github_stretchr_testify", - importpath = "github.com/stretchr/testify", - sum = "h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=", - version = "v1.7.0", - ) - go_repository( - name = "in_gopkg_alecthomas_kingpin_v2", - importpath = "gopkg.in/alecthomas/kingpin.v2", - sum = "h1:CC8tJ/xljioKrK6ii3IeWVXU4Tw7VB+LbjZBJaBxN50=", - version = "v2.2.4", - ) - go_repository( - name = "in_gopkg_check_v1", - importpath = "gopkg.in/check.v1", - sum = "h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=", - version = "v1.0.0-20190902080502-41f04d3bba15", - ) - go_repository( - name = "in_gopkg_yaml_v2", - importpath = "gopkg.in/yaml.v2", - sum = "h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=", - version = "v2.2.4", - ) - go_repository( - name = "in_gopkg_yaml_v3", - importpath = "gopkg.in/yaml.v3", - sum = "h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=", - version = "v3.0.0-20200313102051-9f266ea9e77c", - ) - go_repository( - name = "org_golang_x_sys", - importpath = "golang.org/x/sys", - sum = "h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=", - version = "v0.0.0-20210630005230-0f9fa26af87c", - ) diff --git a/markdown/tools/BUILD.bazel b/markdown/tools/BUILD.bazel index c3c1fccd..6f480646 100644 --- a/markdown/tools/BUILD.bazel +++ b/markdown/tools/BUILD.bazel @@ -39,7 +39,7 @@ sh_binary( srcs = ["update_markdown_toc.sh"], data = [ ":update_markdown_doc", - "@ekalinin_github_markdown_toc//:gh_md_toc", + "@com_github_ekalinin_github_markdown_toc_go//:github-markdown-toc.go", ], visibility = ["//visibility:public"], deps = [ diff --git a/tests/markdown_tests/tools_tests/BUILD.bazel b/tests/markdown_tests/tools_tests/BUILD.bazel index d214b957..44717083 100644 --- a/tests/markdown_tests/tools_tests/BUILD.bazel +++ b/tests/markdown_tests/tools_tests/BUILD.bazel @@ -30,16 +30,14 @@ sh_test( ], ) -# GH160: Temporarily disable. Need to investigate and fix. - -# sh_test( -# name = "update_markdown_toc_test", -# srcs = ["update_markdown_toc_test.sh"], -# data = [ -# "//markdown/tools:update_markdown_toc", -# ], -# deps = [ -# "@bazel_tools//tools/bash/runfiles", -# "@cgrindel_bazel_starlib//shlib/lib:assertions", -# ], -# ) +sh_test( + name = "update_markdown_toc_test", + srcs = ["update_markdown_toc_test.sh"], + data = [ + "//markdown/tools:update_markdown_toc", + ], + deps = [ + "@bazel_tools//tools/bash/runfiles", + "@cgrindel_bazel_starlib//shlib/lib:assertions", + ], +) From 8af73765b0fb6af5f2c260fdaa728d1fbb2e1b77 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 08:34:17 -0700 Subject: [PATCH 02/13] Save work before trying to use go.mod again --- markdown/deps.bzl | 50 ++++++-- .../github_markdown_toc_go_repositories.bzl | 114 ++++++++++++++++++ markdown/tools/BUILD.bazel | 2 +- markdown/tools/update_markdown_toc.sh | 6 +- 4 files changed, 161 insertions(+), 11 deletions(-) diff --git a/markdown/deps.bzl b/markdown/deps.bzl index 21d5aa40..62367a58 100644 --- a/markdown/deps.bzl +++ b/markdown/deps.bzl @@ -1,10 +1,13 @@ """Dependency Functions for markdown""" -load("@bazel_gazelle//:deps.bzl", "go_repository") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +# load("@bazel_gazelle//:deps.bzl", "go_repository") +# load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("//markdown:github_markdown_toc_go_repositories.bzl", "github_markdown_toc_go_repositories") def bazel_starlib_markdown_dependencies(): + """Defines the dependencies for the markdown functionality. + """ + # GH140: Temporarily disable markdown while adding support for # --incompatible_disallow_empty_glob. @@ -15,13 +18,42 @@ def bazel_starlib_markdown_dependencies(): # urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.4.2/rules_nodejs-5.4.2.tar.gz"], # ) - maybe( - go_repository, - name = "com_github_ekalinin_github_markdown_toc_go", - importpath = "github.com/ekalinin/github-markdown-toc.go", - sum = "h1:Y3V7JoKbxDnWKpHV7KIektVSNA7CScWc1ECBgAsyMco=", - version = "v0.0.0-20201214095852-3ab0fa2ca613", - ) + # maybe( + # go_repository, + # name = "com_github_ekalinin_github_markdown_toc_go", + # importpath = "github.com/ekalinin/github-markdown-toc.go", + # sum = "h1:Y3V7JoKbxDnWKpHV7KIektVSNA7CScWc1ECBgAsyMco=", + # version = "v0.0.0-20201214095852-3ab0fa2ca613", + # ) + + # maybe( + # go_repository, + # name = "com_github_ekalinin_github_markdown_toc_go", + # importpath = "github.com/ekalinin/github-markdown-toc.go", + # commit = "563f2322eacc2fc3ea5be26d14c6f4d12076f87c", + # remote = "https://github.com/cgrindel/github-markdown-toc.go.git", + # build_external = "external", + # vcs = "git", + # ) + + # maybe( + # http_archive, + # name = "ekalinin_github_markdown_toc", + # sha256 = "", + # strip_prefix = "github-markdown-toc.go-b75d2a6d1f6518a287cf24f162ec14d4c82e7739", + # urls = ["https://github.com/ekalinin/github-markdown-toc.go/archive/refs/tags/1.2.0.tar.gz"], + # build_file_content = """\ + # load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + # go_binary( + # name = "gh_md_toc", + # srcs = glob(["*.go"], exclude = ["*_test.go"]), + # deps = [ + # "@in_gopkg_alecthomas_kingpin_v2//:go_default_library", + # ], + # visibility = ["//visibility:public"], + # ) + # """, + # ) # Deps for github-markdown-toc.go github_markdown_toc_go_repositories() diff --git a/markdown/github_markdown_toc_go_repositories.bzl b/markdown/github_markdown_toc_go_repositories.bzl index d024530c..312e11a3 100644 --- a/markdown/github_markdown_toc_go_repositories.bzl +++ b/markdown/github_markdown_toc_go_repositories.bzl @@ -3,6 +3,24 @@ load("@bazel_gazelle//:deps.bzl", "go_repository") def github_markdown_toc_go_repositories(): + go_repository( + name = "com_github_alecthomas_assert", + importpath = "github.com/alecthomas/assert", + sum = "h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U=", + version = "v0.0.0-20170929043011-405dbfeb8e38", + ) + go_repository( + name = "com_github_alecthomas_colour", + importpath = "github.com/alecthomas/colour", + sum = "h1:nOE9rJm6dsZ66RGWYSFrXw461ZIt9A6+nHgL7FRrDUk=", + version = "v0.1.0", + ) + go_repository( + name = "com_github_alecthomas_repr", + importpath = "github.com/alecthomas/repr", + sum = "h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48=", + version = "v0.0.0-20210801044451-80ca428c5142", + ) go_repository( name = "com_github_alecthomas_template", importpath = "github.com/alecthomas/template", @@ -15,9 +33,105 @@ def github_markdown_toc_go_repositories(): sum = "h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=", version = "v0.0.0-20151022065526-2efee857e7cf", ) + go_repository( + name = "com_github_davecgh_go_spew", + importpath = "github.com/davecgh/go-spew", + sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=", + version = "v1.1.1", + ) + go_repository( + name = "com_github_kr_pretty", + importpath = "github.com/kr/pretty", + sum = "h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=", + version = "v0.1.0", + ) + go_repository( + name = "com_github_kr_pty", + importpath = "github.com/kr/pty", + sum = "h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=", + version = "v1.1.1", + ) + go_repository( + name = "com_github_kr_text", + importpath = "github.com/kr/text", + sum = "h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=", + version = "v0.1.0", + ) + go_repository( + name = "com_github_mattn_go_isatty", + importpath = "github.com/mattn/go-isatty", + sum = "h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=", + version = "v0.0.14", + ) + go_repository( + name = "com_github_pmezard_go_difflib", + importpath = "github.com/pmezard/go-difflib", + sum = "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=", + version = "v1.0.0", + ) + go_repository( + name = "com_github_sergi_go_diff", + importpath = "github.com/sergi/go-diff", + sum = "h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=", + version = "v1.2.0", + ) + go_repository( + name = "com_github_stretchr_objx", + importpath = "github.com/stretchr/objx", + sum = "h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=", + version = "v0.1.0", + ) + go_repository( + name = "com_github_stretchr_testify", + importpath = "github.com/stretchr/testify", + sum = "h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=", + version = "v1.7.0", + ) go_repository( name = "in_gopkg_alecthomas_kingpin_v2", importpath = "gopkg.in/alecthomas/kingpin.v2", sum = "h1:CC8tJ/xljioKrK6ii3IeWVXU4Tw7VB+LbjZBJaBxN50=", version = "v2.2.4", ) + go_repository( + name = "in_gopkg_check_v1", + importpath = "gopkg.in/check.v1", + sum = "h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=", + version = "v1.0.0-20190902080502-41f04d3bba15", + ) + go_repository( + name = "in_gopkg_yaml_v2", + importpath = "gopkg.in/yaml.v2", + sum = "h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=", + version = "v2.2.4", + ) + go_repository( + name = "in_gopkg_yaml_v3", + importpath = "gopkg.in/yaml.v3", + sum = "h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=", + version = "v3.0.0-20200313102051-9f266ea9e77c", + ) + go_repository( + name = "org_golang_x_net", + importpath = "golang.org/x/net", + sum = "h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=", + version = "v0.1.0", + ) + go_repository( + name = "org_golang_x_sys", + importpath = "golang.org/x/sys", + sum = "h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=", + version = "v0.1.0", + ) + go_repository( + name = "org_golang_x_term", + importpath = "golang.org/x/term", + sum = "h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw=", + version = "v0.1.0", + ) + go_repository( + name = "org_golang_x_text", + importpath = "golang.org/x/text", + sum = "h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=", + version = "v0.4.0", + ) diff --git a/markdown/tools/BUILD.bazel b/markdown/tools/BUILD.bazel index 6f480646..e26b3fdd 100644 --- a/markdown/tools/BUILD.bazel +++ b/markdown/tools/BUILD.bazel @@ -39,7 +39,7 @@ sh_binary( srcs = ["update_markdown_toc.sh"], data = [ ":update_markdown_doc", - "@com_github_ekalinin_github_markdown_toc_go//:github-markdown-toc.go", + "@com_github_ekalinin_github_markdown_toc_go//cmd/gh-md-toc", ], visibility = ["//visibility:public"], deps = [ diff --git a/markdown/tools/update_markdown_toc.sh b/markdown/tools/update_markdown_toc.sh index 98147865..349ce702 100755 --- a/markdown/tools/update_markdown_toc.sh +++ b/markdown/tools/update_markdown_toc.sh @@ -22,7 +22,11 @@ update_markdown_doc_sh_location=cgrindel_bazel_starlib/markdown/tools/update_mar update_markdown_doc_sh="$(rlocation "${update_markdown_doc_sh_location}")" || \ (echo >&2 "Failed to locate ${update_markdown_doc_sh_location}" && exit 1) -gh_md_toc_location=ekalinin_github_markdown_toc/gh_md_toc_/gh_md_toc +# DEBUG BEGIN +tree >&2 +# DEBUG END + +gh_md_toc_location=com_github_ekalinin_github_markdown_toc_go/gh_md_toc_/gh_md_toc gh_md_toc="$(rlocation "${gh_md_toc_location}")" || \ (echo >&2 "Failed to locate ${gh_md_toc_location}" && exit 1) From 2bb0907c2dc2d48014ed7008cee315d99040970e Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 09:16:00 -0700 Subject: [PATCH 03/13] About to tidy with replace --- cmd/go_deps/main.go | 33 +++++++++++++++++++++++++++++++++ go.mod | 10 ++++++++++ go.sum | 2 ++ 3 files changed, 45 insertions(+) create mode 100644 cmd/go_deps/main.go create mode 100644 go.mod create mode 100644 go.sum diff --git a/cmd/go_deps/main.go b/cmd/go_deps/main.go new file mode 100644 index 00000000..304a01bd --- /dev/null +++ b/cmd/go_deps/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "strings" + + gmt "github.com/ekalinin/github-markdown-toc.go" +) + +func main() { + fmt.Println("Hello, world.") + + ghtoc := generateToc() + fmt.Printf("TOC:\n%s", ghtoc) +} + +func generateToc() string { + doc := &gmt.GHDoc{ + html: ` +

+ + README in another language +

+ `, AbsPaths: false, + Depth: 0, + Escape: true, + Indent: 2, + } + toc := *doc.GrabToc() + return strings.Join(toc, "\n") +} diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..ea33991c --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/cgrindel/bazel-starlib + +go 1.19 + +require github.com/ekalinin/github-markdown-toc.go v0.0.0-20220910061337-2d4fdaaf52fa + +// replace github.com/ekalinin/github-markdown-toc.go v0.0.0-20220910061337-2d4fdaaf52fa => github.com/cgrindel/github-markdown-toc.go upgrade_to_go_1_19_1 + +// 563f2322eacc2fc3ea5be26d14c6f4d12076f87c +replace github.com/ekalinin/github-markdown-toc.go => github.com/cgrindel/github-markdown-toc.go v0.0.0-20221107201151-563f2322eacc diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..2786d558 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/ekalinin/github-markdown-toc.go v0.0.0-20220910061337-2d4fdaaf52fa h1:6hyaNOiG3N96rY/qMw/guvehNFeR5kHYzNZgSlV9MOU= +github.com/ekalinin/github-markdown-toc.go v0.0.0-20220910061337-2d4fdaaf52fa/go.mod h1:jo6dTN2y9WC5B1JUlJxjFQdK/YknT186Q1qeFc38pW8= From f61221442cd5eb0aa03c437a69f5f7e52961bcf4 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 09:20:56 -0700 Subject: [PATCH 04/13] Tidy after replace --- go.mod | 6 +++--- go.sum | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index ea33991c..1ea5dcea 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require github.com/ekalinin/github-markdown-toc.go v0.0.0-20220910061337-2d4fdaaf52fa -// replace github.com/ekalinin/github-markdown-toc.go v0.0.0-20220910061337-2d4fdaaf52fa => github.com/cgrindel/github-markdown-toc.go upgrade_to_go_1_19_1 +require golang.org/x/net v0.1.0 // indirect -// 563f2322eacc2fc3ea5be26d14c6f4d12076f87c -replace github.com/ekalinin/github-markdown-toc.go => github.com/cgrindel/github-markdown-toc.go v0.0.0-20221107201151-563f2322eacc +// The replace version is v0.0.0-- +replace github.com/ekalinin/github-markdown-toc.go => github.com/cgrindel/github-markdown-toc.go v0.0.0-20221108150410-563f2322eacc diff --git a/go.sum b/go.sum index 2786d558..028dd0a6 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,8 @@ -github.com/ekalinin/github-markdown-toc.go v0.0.0-20220910061337-2d4fdaaf52fa h1:6hyaNOiG3N96rY/qMw/guvehNFeR5kHYzNZgSlV9MOU= -github.com/ekalinin/github-markdown-toc.go v0.0.0-20220910061337-2d4fdaaf52fa/go.mod h1:jo6dTN2y9WC5B1JUlJxjFQdK/YknT186Q1qeFc38pW8= +github.com/cgrindel/github-markdown-toc.go v0.0.0-20221108150410-563f2322eacc h1:rcvDLDuGAd6QT59liW//eYli+PyhyPlrqc+jt2qdezQ= +github.com/cgrindel/github-markdown-toc.go v0.0.0-20221108150410-563f2322eacc/go.mod h1:27aWizpGXJ9pIZgnGY5NBH7S7y4Qri3dUcPRA9nAD8g= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= +golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= From ce93d4fe6d710105d329f0e68dae3c84aba80840 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 09:25:57 -0700 Subject: [PATCH 05/13] The go_deps works with go run --- cmd/go_deps/main.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/cmd/go_deps/main.go b/cmd/go_deps/main.go index 304a01bd..614c559f 100644 --- a/cmd/go_deps/main.go +++ b/cmd/go_deps/main.go @@ -14,20 +14,9 @@ func main() { fmt.Printf("TOC:\n%s", ghtoc) } +// Use the markdown package so that it is a dependency. func generateToc() string { - doc := &gmt.GHDoc{ - html: ` -

- - README in another language -

- `, AbsPaths: false, - Depth: 0, - Escape: true, - Indent: 2, - } + doc := gmt.NewGHDoc("", false, 0, 0, true, "", 2, false) toc := *doc.GrabToc() return strings.Join(toc, "\n") } From 4f5bf433918fa3661408b1cd51b78b57ca3302dc Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 09:58:20 -0700 Subject: [PATCH 06/13] Lint issues and clean up --- BUILD.bazel | 16 ++++---- WORKSPACE | 8 +++- cmd/go_deps/BUILD.bazel | 15 ++++++++ ...own_toc_go_repositories.bzl => go_deps.bzl | 38 ++++++------------- 4 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 cmd/go_deps/BUILD.bazel rename markdown/github_markdown_toc_go_repositories.bzl => go_deps.bzl (82%) diff --git a/BUILD.bazel b/BUILD.bazel index c02ad837..7b6ff7b5 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -11,14 +11,14 @@ load("//updatesrc:defs.bzl", "updatesrc_update_all") # gazelle:prefix github.com/cgrindel/bazel-starlib gazelle(name = "gazelle") -# gazelle( -# name = "gazelle_update_repos_for_github_markdown_toc", -# args = [ -# "github.com/ekalinin/github-markdown-toc.go", -# "-to_macro=markdown/deps.bzl%bazel_starlib_markdown_go_dependencies", -# ], -# command = "update-repos", -# ) +gazelle( + name = "gazelle_update_repos", + args = [ + "-from_file=go.mod", + "-to_macro=go_deps.bzl%bazel_starlib_go_dependencies", + ], + command = "update-repos", +) # MARK: - Bazel Starlark Lint and Formatting diff --git a/WORKSPACE b/WORKSPACE index a47925da..890b999d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -7,9 +7,13 @@ bazel_starlib_dependencies() # gazelle:repo bazel_gazelle load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") -load("//markdown:deps.bzl", "bazel_starlib_markdown_dependencies") +load("//:go_deps.bzl", "bazel_starlib_go_dependencies") -bazel_starlib_markdown_dependencies() +# gazelle:repository_macro go_deps.bzl%bazel_starlib_go_dependencies +bazel_starlib_go_dependencies() + +# load("//markdown:deps.bzl", "bazel_starlib_markdown_dependencies") +# bazel_starlib_markdown_dependencies() # load("//:markdown/github_markdown_toc_go_repositories.bzl", "github_markdown_toc_go_repositories") # # gazelle:repository_macro markdown/github_markdown_toc_go_repositories.bzl%github_markdown_toc_go_repositories diff --git a/cmd/go_deps/BUILD.bazel b/cmd/go_deps/BUILD.bazel new file mode 100644 index 00000000..22c907a6 --- /dev/null +++ b/cmd/go_deps/BUILD.bazel @@ -0,0 +1,15 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +go_library( + name = "go_deps_lib", + srcs = ["main.go"], + importpath = "github.com/cgrindel/bazel-starlib/cmd/go_deps", + visibility = ["//visibility:private"], + deps = ["@com_github_ekalinin_github_markdown_toc_go//:github-markdown-toc_go"], +) + +go_binary( + name = "go_deps", + embed = [":go_deps_lib"], + visibility = ["//visibility:public"], +) diff --git a/markdown/github_markdown_toc_go_repositories.bzl b/go_deps.bzl similarity index 82% rename from markdown/github_markdown_toc_go_repositories.bzl rename to go_deps.bzl index 312e11a3..2b50940e 100644 --- a/markdown/github_markdown_toc_go_repositories.bzl +++ b/go_deps.bzl @@ -1,8 +1,11 @@ -"""Go repository dependencies for github-markdown-toc-go.""" +"""Module that contains functions specifying the Golang dependencies for the \ +bazel-starlib repository. +""" load("@bazel_gazelle//:deps.bzl", "go_repository") -def github_markdown_toc_go_repositories(): +def bazel_starlib_go_dependencies(): + """Specifies the Golang dependencies for the bazel-starlib repository.""" go_repository( name = "com_github_alecthomas_assert", importpath = "github.com/alecthomas/assert", @@ -39,24 +42,19 @@ def github_markdown_toc_go_repositories(): sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=", version = "v1.1.1", ) + go_repository( + name = "com_github_ekalinin_github_markdown_toc_go", + importpath = "github.com/ekalinin/github-markdown-toc.go", + replace = "github.com/cgrindel/github-markdown-toc.go", + sum = "h1:rcvDLDuGAd6QT59liW//eYli+PyhyPlrqc+jt2qdezQ=", + version = "v0.0.0-20221108150410-563f2322eacc", + ) go_repository( name = "com_github_kr_pretty", importpath = "github.com/kr/pretty", sum = "h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=", version = "v0.1.0", ) - go_repository( - name = "com_github_kr_pty", - importpath = "github.com/kr/pty", - sum = "h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=", - version = "v1.1.1", - ) - go_repository( - name = "com_github_kr_text", - importpath = "github.com/kr/text", - sum = "h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=", - version = "v0.1.0", - ) go_repository( name = "com_github_mattn_go_isatty", importpath = "github.com/mattn/go-isatty", @@ -75,12 +73,6 @@ def github_markdown_toc_go_repositories(): sum = "h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=", version = "v1.2.0", ) - go_repository( - name = "com_github_stretchr_objx", - importpath = "github.com/stretchr/objx", - sum = "h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=", - version = "v0.1.0", - ) go_repository( name = "com_github_stretchr_testify", importpath = "github.com/stretchr/testify", @@ -99,12 +91,6 @@ def github_markdown_toc_go_repositories(): sum = "h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=", version = "v1.0.0-20190902080502-41f04d3bba15", ) - go_repository( - name = "in_gopkg_yaml_v2", - importpath = "gopkg.in/yaml.v2", - sum = "h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=", - version = "v2.2.4", - ) go_repository( name = "in_gopkg_yaml_v3", importpath = "gopkg.in/yaml.v3", From d11cfc43ba6ba93d68c145ba55ce8da375045400 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 10:00:39 -0700 Subject: [PATCH 07/13] Remove obsolete files --- markdown/BUILD.bazel | 5 ---- markdown/deps.bzl | 59 -------------------------------------------- 2 files changed, 64 deletions(-) delete mode 100644 markdown/deps.bzl diff --git a/markdown/BUILD.bazel b/markdown/BUILD.bazel index d0ff51e9..b2c1879b 100644 --- a/markdown/BUILD.bazel +++ b/markdown/BUILD.bazel @@ -42,8 +42,3 @@ bzl_library( "//markdown/private:markdown_pkg", ], ) - -bzl_library( - name = "deps", - srcs = ["deps.bzl"], -) diff --git a/markdown/deps.bzl b/markdown/deps.bzl deleted file mode 100644 index 62367a58..00000000 --- a/markdown/deps.bzl +++ /dev/null @@ -1,59 +0,0 @@ -"""Dependency Functions for markdown""" - -# load("@bazel_gazelle//:deps.bzl", "go_repository") -# load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load("//markdown:github_markdown_toc_go_repositories.bzl", "github_markdown_toc_go_repositories") - -def bazel_starlib_markdown_dependencies(): - """Defines the dependencies for the markdown functionality. - """ - - # GH140: Temporarily disable markdown while adding support for - # --incompatible_disallow_empty_glob. - - # maybe( - # http_archive, - # name = "build_bazel_rules_nodejs", - # sha256 = "e328cb2c9401be495fa7d79c306f5ee3040e8a03b2ebb79b022e15ca03770096", - # urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.4.2/rules_nodejs-5.4.2.tar.gz"], - # ) - - # maybe( - # go_repository, - # name = "com_github_ekalinin_github_markdown_toc_go", - # importpath = "github.com/ekalinin/github-markdown-toc.go", - # sum = "h1:Y3V7JoKbxDnWKpHV7KIektVSNA7CScWc1ECBgAsyMco=", - # version = "v0.0.0-20201214095852-3ab0fa2ca613", - # ) - - # maybe( - # go_repository, - # name = "com_github_ekalinin_github_markdown_toc_go", - # importpath = "github.com/ekalinin/github-markdown-toc.go", - # commit = "563f2322eacc2fc3ea5be26d14c6f4d12076f87c", - # remote = "https://github.com/cgrindel/github-markdown-toc.go.git", - # build_external = "external", - # vcs = "git", - # ) - - # maybe( - # http_archive, - # name = "ekalinin_github_markdown_toc", - # sha256 = "", - # strip_prefix = "github-markdown-toc.go-b75d2a6d1f6518a287cf24f162ec14d4c82e7739", - # urls = ["https://github.com/ekalinin/github-markdown-toc.go/archive/refs/tags/1.2.0.tar.gz"], - # build_file_content = """\ - # load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") - # go_binary( - # name = "gh_md_toc", - # srcs = glob(["*.go"], exclude = ["*_test.go"]), - # deps = [ - # "@in_gopkg_alecthomas_kingpin_v2//:go_default_library", - # ], - # visibility = ["//visibility:public"], - # ) - # """, - # ) - - # Deps for github-markdown-toc.go - github_markdown_toc_go_repositories() From 9ad2dc869cd7c43a43cb5a36f6014e549d4d5496 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 10:02:47 -0700 Subject: [PATCH 08/13] Tests are green --- markdown/tools/update_markdown_toc.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/markdown/tools/update_markdown_toc.sh b/markdown/tools/update_markdown_toc.sh index 349ce702..4ea5ae90 100755 --- a/markdown/tools/update_markdown_toc.sh +++ b/markdown/tools/update_markdown_toc.sh @@ -22,11 +22,7 @@ update_markdown_doc_sh_location=cgrindel_bazel_starlib/markdown/tools/update_mar update_markdown_doc_sh="$(rlocation "${update_markdown_doc_sh_location}")" || \ (echo >&2 "Failed to locate ${update_markdown_doc_sh_location}" && exit 1) -# DEBUG BEGIN -tree >&2 -# DEBUG END - -gh_md_toc_location=com_github_ekalinin_github_markdown_toc_go/gh_md_toc_/gh_md_toc +gh_md_toc_location=com_github_ekalinin_github_markdown_toc_go/cmd/gh-md-toc/gh-md-toc_/gh-md-toc gh_md_toc="$(rlocation "${gh_md_toc_location}")" || \ (echo >&2 "Failed to locate ${gh_md_toc_location}" && exit 1) From a571693439cc816fed4ec2b553dfdf0ac275b05e Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 10:23:20 -0700 Subject: [PATCH 09/13] Add gazelle_update_repos and gazelle to update_all. Add tidy alias --- BUILD.bazel | 7 +++++++ cmd/go_deps/BUILD.bazel | 3 +++ cmd/go_deps/README.md | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 cmd/go_deps/README.md diff --git a/BUILD.bazel b/BUILD.bazel index 7b6ff7b5..f6f914dc 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -35,9 +35,16 @@ updatesrc_update_all( targets_to_run = [ "@contrib_rules_bazel_integration_test//tools:update_deleted_packages", ":bzlformat_missing_pkgs_fix", + ":gazelle_update_repos", + ":gazelle", ], ) +alias( + name = "tidy", + actual = ":update_all", +) + # MARK: - Markdown Files package_group( diff --git a/cmd/go_deps/BUILD.bazel b/cmd/go_deps/BUILD.bazel index 22c907a6..e14c6956 100644 --- a/cmd/go_deps/BUILD.bazel +++ b/cmd/go_deps/BUILD.bazel @@ -1,3 +1,4 @@ +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") go_library( @@ -13,3 +14,5 @@ go_binary( embed = [":go_deps_lib"], visibility = ["//visibility:public"], ) + +bzlformat_pkg(name = "bzlformat") diff --git a/cmd/go_deps/README.md b/cmd/go_deps/README.md new file mode 100644 index 00000000..ebad62b7 --- /dev/null +++ b/cmd/go_deps/README.md @@ -0,0 +1,21 @@ +# Golang Dependencies + +The `bazel-starlib` repository uses Golang modules that contain exeutable packages (e.g., binaries). +To ensure that these binary targets are downloaded and built properly, a simple Golang program +exists to reference the required packages. [Gazelle](https://github.com/bazelbuild/bazel-gazelle) is +then used to identify the transitive dependencies and saves them to `go_deps.bzl`. + +## To Add a Golang Dependency + +Update the `main.go` in this directory to depend upon the desired Golang package. Be sure to use the +package in some way. Otherwise, `go mod tidy` will remove it. + +Execute `//:tidy` to update the `go_deps.bzl` and ensure that the build files are updated properly. + +```sh +$ go mod tidy +$ bazel run //:gazelle_update_repos +$ bazel run //:gazelle +``` + +Reference the Golang binary target. From 92c8b9813726eb5bdc980958ca53072c0a4ac683 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 10:26:39 -0700 Subject: [PATCH 10/13] Clean up --- WORKSPACE | 7 ------- 1 file changed, 7 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 890b999d..d816e23f 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -12,13 +12,6 @@ load("//:go_deps.bzl", "bazel_starlib_go_dependencies") # gazelle:repository_macro go_deps.bzl%bazel_starlib_go_dependencies bazel_starlib_go_dependencies() -# load("//markdown:deps.bzl", "bazel_starlib_markdown_dependencies") -# bazel_starlib_markdown_dependencies() - -# load("//:markdown/github_markdown_toc_go_repositories.bzl", "github_markdown_toc_go_repositories") -# # gazelle:repository_macro markdown/github_markdown_toc_go_repositories.bzl%github_markdown_toc_go_repositories -# github_markdown_toc_go_repositories() - go_rules_dependencies() go_register_toolchains(version = "1.19.1") From 9c724030cf897c3f0a6bca2eef834433c7cda00f Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 10:31:48 -0700 Subject: [PATCH 11/13] Fix README --- cmd/go_deps/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/go_deps/README.md b/cmd/go_deps/README.md index ebad62b7..a1f5c2c4 100644 --- a/cmd/go_deps/README.md +++ b/cmd/go_deps/README.md @@ -10,10 +10,11 @@ then used to identify the transitive dependencies and saves them to `go_deps.bzl Update the `main.go` in this directory to depend upon the desired Golang package. Be sure to use the package in some way. Otherwise, `go mod tidy` will remove it. -Execute `//:tidy` to update the `go_deps.bzl` and ensure that the build files are updated properly. +Execute the following to update the go module files, resolve the Golang dependencies and update the +Bazel build files. ```sh -$ go mod tidy +# bazel run @go_sdk//:bin/go -- mod tidy $ bazel run //:gazelle_update_repos $ bazel run //:gazelle ``` From 6f88542a52abc8987cddab1792d9880a942fc5b0 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 12:18:24 -0700 Subject: [PATCH 12/13] Remove use_markdown usage --- examples/bzlformat/build_buildtools/WORKSPACE | 1 - examples/bzlformat/simple/WORKSPACE | 5 +---- examples/markdown/simple/WORKSPACE | 5 +---- examples/updatesrc/simple/WORKSPACE | 5 +---- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/examples/bzlformat/build_buildtools/WORKSPACE b/examples/bzlformat/build_buildtools/WORKSPACE index ed581b17..9358a4e0 100644 --- a/examples/bzlformat/build_buildtools/WORKSPACE +++ b/examples/bzlformat/build_buildtools/WORKSPACE @@ -10,7 +10,6 @@ load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") # Be sure to specify that you do not want to use the prebuilt tools bazel_starlib_dependencies( use_bazeldoc = False, - use_markdown = False, use_prebuilt_buildtools = False, ) diff --git a/examples/bzlformat/simple/WORKSPACE b/examples/bzlformat/simple/WORKSPACE index 1cc75a44..f8bc57e2 100644 --- a/examples/bzlformat/simple/WORKSPACE +++ b/examples/bzlformat/simple/WORKSPACE @@ -7,10 +7,7 @@ local_repository( load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") -bazel_starlib_dependencies( - use_bazeldoc = False, - use_markdown = False, -) +bazel_starlib_dependencies(use_bazeldoc = False) load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") diff --git a/examples/markdown/simple/WORKSPACE b/examples/markdown/simple/WORKSPACE index d21cde62..d4c31e8f 100644 --- a/examples/markdown/simple/WORKSPACE +++ b/examples/markdown/simple/WORKSPACE @@ -7,10 +7,7 @@ local_repository( load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") -bazel_starlib_dependencies( - use_bazeldoc = False, - use_markdown = True, -) +bazel_starlib_dependencies(use_bazeldoc = False) load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") diff --git a/examples/updatesrc/simple/WORKSPACE b/examples/updatesrc/simple/WORKSPACE index 40fafc1f..b6866d1e 100644 --- a/examples/updatesrc/simple/WORKSPACE +++ b/examples/updatesrc/simple/WORKSPACE @@ -7,10 +7,7 @@ local_repository( load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") -bazel_starlib_dependencies( - use_bazeldoc = False, - use_markdown = False, -) +bazel_starlib_dependencies(use_bazeldoc = False) load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") From d36578ad42bed8049cc6149c898fa76c6a4361e1 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Tue, 8 Nov 2022 12:21:07 -0700 Subject: [PATCH 13/13] Point current Bazel version at //:.bazelversion --- bazel_versions.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazel_versions.bzl b/bazel_versions.bzl index 8d94f3af..34aad52f 100644 --- a/bazel_versions.bzl +++ b/bazel_versions.bzl @@ -1,6 +1,6 @@ """Bazel Version Declarations""" -CURRENT_BAZEL_VERSION = "5.1.1" +CURRENT_BAZEL_VERSION = "//:.bazelversion" OTHER_BAZEL_VERSIONS = [ "4.2.2",