github.com/0xKiwi/rules_go@v0.24.3/tests/integration/popular_repos/popular_repos.py (about)

     1  #!/usr/bin/env python
     2  # Copyright 2017 The Bazel Authors. All rights reserved.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #    http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  from subprocess import check_output, call
    17  from sys import exit
    18  
    19  POPULAR_REPOS = [
    20      dict(
    21          name = "org_golang_x_crypto",
    22          importpath = "golang.org/x/crypto",
    23          urls = "https://codeload.github.com/golang/crypto/zip/de0752318171da717af4ce24d0a2e8626afaeb11",
    24          strip_prefix = "crypto-de0752318171da717af4ce24d0a2e8626afaeb11",
    25          type = "zip",
    26          excludes = [
    27              "ssh/agent:go_default_test",
    28              "ssh:go_default_test",
    29              "ssh/test:go_default_test",
    30          ],
    31      ),
    32  
    33      dict(
    34          name = "org_golang_x_net",
    35          importpath = "golang.org/x/net",
    36          commit = "57efc9c3d9f91fb3277f8da1cff370539c4d3dc5",
    37          excludes = [
    38              "bpf:go_default_test", # Needs testdata directory
    39              "html/charset:go_default_test", # Needs testdata directory
    40              "http2:go_default_test", # Needs testdata directory
    41              "icmp:go_default_test", # icmp requires adjusting kernel options.
    42              "nettest:go_default_test", #
    43              "lif:go_default_test",
    44          ],
    45          darwin_tests = [
    46              "route:go_default_test", # Not supported on linux
    47          ]
    48      ),
    49  
    50      dict(
    51          name = "org_golang_x_sys",
    52          importpath = "golang.org/x/sys",
    53          commit = "acbc56fc7007d2a01796d5bde54f39e3b3e95945",
    54          excludes = [
    55              "unix:go_default_test", # TODO(#413): External test depends on symbols defined in internal test.
    56          ],
    57      ),
    58  
    59      dict(
    60          name = "org_golang_x_text",
    61          importpath = "golang.org/x/text",
    62          commit = "a9a820217f98f7c8a207ec1e45a874e1fe12c478",
    63          excludes = [
    64              "encoding/japanese:go_default_test", # Needs testdata directory
    65              "encoding/korean:go_default_test", # Needs testdata directory
    66              "encoding/charmap:go_default_test", # Needs testdata directory
    67              "encoding/simplifiedchinese:go_default_test", # Needs testdata directory
    68              "encoding/traditionalchinese:go_default_test", # Needs testdata directory
    69              "encoding/unicode/utf32:go_default_test", # Needs testdata directory
    70              "encoding/unicode:go_default_test", # Needs testdata directory
    71          ],
    72      ),
    73  
    74      dict(
    75          name = "org_golang_x_tools",
    76          importpath = "golang.org/x/tools",
    77          commit = "11eff242d136374289f76e9313c76e9312391172",
    78          excludes = [
    79              "blog:blog_test", # Needs goldmark
    80              "cmd/bundle:bundle_test", # Needs testdata directory
    81              "cmd/callgraph/testdata/src/pkg:pkg_test", # is testdata
    82              "cmd/callgraph:callgraph_test", # Needs testdata directory
    83              "cmd/cover:cover_test", # Needs testdata directory
    84              "cmd/fiximports:fiximports_test", # requires working GOROOT, not present in CI.
    85              "cmd/godoc:godoc_test", # TODO(#417)
    86              "cmd/gorename:gorename_test", # TODO(#417)
    87              "cmd/guru/testdata/src/referrers:referrers_test", # Not a real test
    88              "cmd/guru:guru_test", # Needs testdata directory
    89              "cmd/stringer:stringer_test", # Needs testdata directory
    90              "container/intsets:intsets_test", # TODO(#413): External test depends on symbols defined in internal test.
    91              "go/analysis/analysistest:analysistest_test", # requires build cache
    92              "go/analysis/internal/checker:checker_test", # loads test package with go/packages, which probably needs go list
    93              "go/analysis/internal/facts:facts_test", # loads test package with go/packages, which probably needs go list
    94              "go/analysis/multichecker:multichecker_test", # requires go vet
    95              "go/analysis/passes/asmdecl:asmdecl_test", # Needs testdata directory
    96              "go/analysis/passes/assign:assign_test", # Needs testdata directory
    97              "go/analysis/passes/atomic:atomic_test", # Needs testdata directory
    98              "go/analysis/passes/atomicalign:atomicalign_test", # requires go list
    99              "go/analysis/passes/bools:bools_test", # Needs testdata directory
   100              "go/analysis/passes/buildssa:buildssa_test", # Needs testdata directory
   101              "go/analysis/passes/buildtag:buildtag_test", # Needs testdata directory
   102              "go/analysis/passes/cgocall:cgocall_test", # Needs testdata directory
   103              "go/analysis/passes/composite:composite_test", # Needs testdata directory
   104              "go/analysis/passes/copylock:copylock_test", # Needs testdata directory
   105              "go/analysis/passes/ctrlflow:ctrlflow_test", # Needs testdata directory
   106              "go/analysis/passes/deepequalerrors:deepequalerrors_test", # requires go list
   107              "go/analysis/passes/errorsas:errorsas_test", # requires go list and testdata
   108              "go/analysis/passes/findcall:findcall_test", # requires build cache
   109              "go/analysis/passes/httpresponse:httpresponse_test", # Needs testdata directory
   110              "go/analysis/passes/ifaceassert:ifaceassert_test", # Needs GOROOT
   111              "go/analysis/passes/loopclosure:loopclosure_test", # Needs testdata directory
   112              "go/analysis/passes/lostcancel:lostcancel_test", # Needs testdata directory
   113              "go/analysis/passes/nilfunc:nilfunc_test", # Needs testdata directory
   114              "go/analysis/passes/nilness:nilness_test", # Needs testdata directory
   115              "go/analysis/passes/pkgfact:pkgfact_test", # requires go list
   116              "go/analysis/passes/printf:printf_test", # Needs testdata directory
   117              "go/analysis/passes/shadow:shadow_test", # Needs testdata directory
   118              "go/analysis/passes/shift:shift_test", # Needs testdata directory
   119              "go/analysis/passes/sortslice:sortslice_test", # Needs 'go list'
   120              "go/analysis/passes/stdmethods:stdmethods_test", # Needs testdata directory
   121              "go/analysis/passes/stringintconv:stringintconv_test", # Needs 'go list'
   122              "go/analysis/passes/structtag:structtag_test", # Needs testdata directory
   123              "go/analysis/passes/testinggoroutine:testinggoroutine_test", # Need 'go env'
   124              "go/analysis/passes/tests/testdata/src/a:a_test", # Not a real test
   125              "go/analysis/passes/tests/testdata/src/b_x_test:b_x_test_test", # Not a real test
   126              "go/analysis/passes/tests/testdata/src/divergent:divergent_test", # Not a real test
   127              "go/analysis/passes/tests:tests_test", # Needs testdata directory
   128              "go/analysis/passes/unmarshal:unmarshal_test", # Needs go list
   129              "go/analysis/passes/unreachable:unreachable_test", # Needs testdata directory
   130              "go/analysis/passes/unsafeptr:unsafeptr_test", # Needs testdata directory
   131              "go/analysis/passes/unusedresult:unusedresult_test", # Needs testdata directory
   132              "go/analysis/unitchecker:unitchecker_test", # requires go vet
   133              "go/ast/inspector:inspector_test", # requires GOROOT and GOPATH
   134              "go/buildutil:buildutil_test", # Needs testdata directory
   135              "go/callgraph/cha:cha_test", # Needs testdata directory
   136              "go/callgraph/rta:rta_test", # Needs testdata directory
   137              "go/expect:expect_test", # Needs testdata directory
   138              "go/gccgoexportdata:gccgoexportdata_test", # Needs testdata directory
   139              "go/gcexportdata:gcexportdata_test", # Needs testdata directory
   140              "go/internal/gccgoimporter:gccgoimporter_test", # Needs testdata directory
   141              "go/internal/gcimporter:gcimporter_test", # Needs testdata directory
   142              "go/loader:loader_test", # Needs testdata directory
   143              "go/packages/packagestest/testdata/groups/two/primarymod/expect:expect_test", # Is testdata
   144              "go/packages/packagestest/testdata:testdata_test", # Is testdata
   145              "go/packages/packagestest:packagestest_test", # requires build cache
   146              "go/packages:packages_test", # Hah!
   147              "go/pointer:pointer_test", # Needs testdata directory
   148              "go/ssa/interp:interp_test", # Needs testdata directory
   149              "go/ssa/ssautil:ssautil_test", # Needs testdata directory
   150              "go/ssa:ssa_test", # Needs testdata directory
   151              "go/types/typeutil:typeutil_test", # requires GOROOT
   152              "godoc/static:static_test", # requires data files
   153              "godoc/vfs/zipfs:zipfs_test", # requires GOROOT
   154              "godoc:godoc_test", # requires GOROOT and GOPATH
   155              "internal/apidiff:apidiff_test", # Needs testdata directory
   156              "internal/gocommand:gocommand_test", # Needs go tool
   157              "internal/imports:imports_test", # Needs testdata directory
   158              "internal/lsp/analysis/fillreturns:fillreturns_test", # Needs go tool
   159              "internal/lsp/analysis/fillstruct:fillstruct_test", # Needs go tool
   160              "internal/lsp/analysis/nonewvars:nonewvars_test", # Needs GOROOT
   161              "internal/lsp/analysis/noresultvalues:noresultvalues_test", # Needs GOROOT
   162              "internal/lsp/analysis/simplifycompositelit:simplifycompositelit_test", # Needs go tool
   163              "internal/lsp/analysis/simplifyrange:simplifyrange_test", # Needs GOROOT
   164              "internal/lsp/analysis/simplifyslice:simplifyslice_test", # Needs GOROOT
   165              "internal/lsp/analysis/undeclaredname:undeclaredname_test", # Needs GOROOT
   166              "internal/lsp/analysis/unusedparams:unusedparams_test", # Needs go tool
   167              "internal/lsp/cache:cache_test", # has additional deps
   168              "internal/lsp/cmd:cmd_test", # panics?
   169              "internal/lsp/diff/difftest:difftest_test", # has additional deps
   170              "internal/lsp/diff/myers:myers_test", # has additional deps
   171              "internal/lsp/diff:diff_test", # has additional deps
   172              "internal/lsp/fake:fake_test", # has additional deps
   173              "internal/lsp/fuzzy:fuzzy_test", # has additional deps
   174              "internal/lsp/lsprpc:lsprpc_test", # has additional deps
   175              "internal/lsp/mod:mod_test", # has additional deps
   176              "internal/lsp/regtest:regtest_test", # has additional deps
   177              "internal/lsp/snippet:snippet_test", # has additional deps
   178              "internal/lsp/source:source_test", # Needs testdata directory
   179              "internal/lsp/testdata/lsp/primarymod/analyzer:analyzer_test", # not a real test
   180              "internal/lsp/testdata/lsp/primarymod/codelens:codelens_test", # Is testdata
   181              "internal/lsp/testdata/lsp/primarymod/godef/a:a_test", # not a real test
   182              "internal/lsp/testdata/lsp/primarymod/implementation/other:other_test", # not a real test
   183              "internal/lsp/testdata/lsp/primarymod/references:references_test", # not a real test
   184              "internal/lsp/testdata/lsp/primarymod/rename/testy:testy_test", # not a real test
   185              "internal/lsp/testdata/lsp/primarymod/signature:signature_test", # Is testdata
   186              "internal/lsp/testdata/lsp/primarymod/testy:testy_test", # not a real test
   187              "internal/lsp/testdata/lsp/primarymod/unimported:unimported_test", # not a real test
   188              "internal/lsp:lsp_test", # Needs testdata directory
   189              "present:present_test", # Needs goldmark
   190              "refactor/eg:eg_test", # Needs testdata directory
   191              "refactor/importgraph:importgraph_test", # TODO(#417)
   192              "refactor/rename:rename_test", # TODO(#417)
   193          ],
   194      ),
   195  
   196      dict(
   197          name = "com_github_golang_glog",
   198          importpath = "github.com/golang/glog",
   199          commit = "23def4e6c14b4da8ac2ed8007337bc5eb5007998",
   200      ),
   201  
   202      dict(
   203          name = "org_golang_x_sync",
   204          importpath = "golang.org/x/sync",
   205          commit = "112230192c580c3556b8cee6403af37a4fc5f28c",
   206      ),
   207  
   208      dict(
   209          name = "org_golang_x_mod",
   210          importpath = "golang.org/x/mod",
   211          commit = "c0d644d00ab849f4506f17a98a5740bf0feff020",
   212          excludes = [
   213              "sumdb/tlog:go_default_test", # Needs network, not available on RBE
   214              "zip:go_default_test", # Needs vcs tools, not available on RBE
   215          ],            
   216      ),
   217    ]
   218  
   219  COPYRIGHT_HEADER = """
   220  # Copyright 2017 The Bazel Authors. All rights reserved.
   221  #
   222  # Licensed under the Apache License, Version 2.0 (the "License");
   223  # you may not use this file except in compliance with the License.
   224  # You may obtain a copy of the License at
   225  #
   226  #    http://www.apache.org/licenses/LICENSE-2.0
   227  #
   228  # Unless required by applicable law or agreed to in writing, software
   229  # distributed under the License is distributed on an "AS IS" BASIS,
   230  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   231  # See the License for the specific language governing permissions and
   232  # limitations under the License.
   233  
   234  ##############################
   235  # Generated file, do not edit!
   236  ##############################
   237  """.strip()
   238  
   239  BZL_HEADER = COPYRIGHT_HEADER + """
   240  
   241  load("@bazel_gazelle//:def.bzl", "go_repository")
   242  
   243  def _maybe(repo_rule, name, **kwargs):
   244      if name not in native.existing_rules():
   245          repo_rule(name = name, **kwargs)
   246  
   247  def popular_repos():
   248  """
   249  
   250  BUILD_HEADER = COPYRIGHT_HEADER
   251  
   252  DOCUMENTATION_HEADER = """
   253  Popular repository tests
   254  ========================
   255  
   256  These tests are designed to check that gazelle and rules_go together can cope
   257  with a list of popluar repositories people depend on.
   258  
   259  It helps catch changes that might break a large number of users.
   260  
   261  .. contents::
   262  
   263  """.lstrip()
   264  
   265  def popular_repos_bzl():
   266    with open("popular_repos.bzl", "w") as f:
   267      f.write(BZL_HEADER)
   268      for repo in POPULAR_REPOS:
   269        f.write("    _maybe(\n        go_repository,\n")
   270        for k in ["name", "importpath", "commit", "strip_prefix", "type", "build_file_proto_mode"]:
   271          if k in repo: f.write('        {} = "{}",\n'.format(k, repo[k]))
   272        for k in ["urls"]:
   273          if k in repo: f.write('        {} = ["{}"],\n'.format(k, repo[k]))
   274        f.write("    )\n")
   275  
   276  def build_bazel():
   277    with open("BUILD.bazel", "w") as f:
   278      f.write(BUILD_HEADER)
   279      for repo in POPULAR_REPOS:
   280        name = repo["name"]
   281        tests = check_output(["bazel", "query", "kind(go_test, \"@{}//...\")".format(name)]).split("\n")
   282        excludes = ["@{}//{}".format(name, l) for l in repo.get("excludes", [])]
   283        for k in repo:
   284          if k.endswith("_excludes") or k.endswith("_tests"):
   285            excludes.extend(["@{}//{}".format(name, l) for l in repo[k]])
   286        invalid_excludes = [t for t in excludes if not t in tests]
   287        if invalid_excludes:
   288          exit("Invalid excludes found: {}".format(invalid_excludes))
   289        f.write('\ntest_suite(\n')
   290        f.write('    name = "{}",\n'.format(name))
   291        f.write('    tests = [\n')
   292        actual = []
   293        for test in sorted(tests, key=lambda test: test.replace(":", "!")):
   294          if test in excludes or not test: continue
   295          f.write('        "{}",\n'.format(test))
   296          actual.append(test)
   297        f.write('    ],\n')
   298        #TODO: add in the platform "select" tests
   299        f.write(')\n')
   300        repo["actual"] = actual
   301  
   302  def readme_rst():
   303    with open("README.rst", "w") as f:
   304      f.write(DOCUMENTATION_HEADER)
   305      for repo in POPULAR_REPOS:
   306        name = repo["name"]
   307        f.write("{}\n{}\n\n".format(name, "_"*len(name)))
   308        f.write("This runs tests from the repository `{0} <https://{0}>`_\n\n".format(repo["importpath"]))
   309        for test in repo["actual"]:
   310            f.write("* {}\n".format(test))
   311        f.write("\n\n")
   312  
   313  
   314  def main():
   315    popular_repos_bzl()
   316    build_bazel()
   317    readme_rst()
   318  
   319  if __name__ == "__main__":
   320      main()