Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel integration tests get default repos from the actual WORKSPACE file. #8986

Open
aiuto opened this issue Jul 25, 2019 · 11 comments
Open
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: feature request

Comments

@aiuto
Copy link
Contributor

aiuto commented Jul 25, 2019

We reference some repositories in WORKSPACE then we replace the reference in test harnesses. This is brittle and can lead to tests which do not match the repo version we actually use. Below is the case for rules_cc and shell test. The problem exists for Java and Python tests too. This will get worse as we move more code out of native and //tools and into external repos.

In WORKSPACE:

http_archive(
    name = "rules_cc",
    sha256 = "36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89",
    strip_prefix = "rules_cc-0d5f3f2768c6ca2faca0079a997a97ce22997a0c",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip",
        "https://github.com/bazelbuild/rules_cc/archive/0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip",
    ],
)

function add_rules_cc_to_workspace() {

function add_rules_cc_to_workspace() {
  cat >> "$1"<<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_cc",
    sha256 = "36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89",
    strip_prefix = "rules_cc-0d5f3f2768c6ca2faca0079a997a97ce22997a0c",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip",
        "https://github.com/bazelbuild/rules_cc/archive/0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip",
    ],
)
EOF
}

It is more than just one file.

grep -r 36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89 .
./src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE:    sha256 = "36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89",
./src/test/shell/testenv.sh:    sha256 = "36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89",
./src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java:            "    sha256 = '36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89',",
./src/test/py/bazel/test_base.py:        '"36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89",',
./src/test/py/bazel/testdata/runfiles_test/WORKSPACE.mock:  sha256 = "36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89",
./WORKSPACE:        "0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip": "36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89",
./WORKSPACE:    sha256 = "36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89",
./WORKSPACE:        "0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip": "36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89",
@sergiocampama
Copy link
Contributor

I believe rules_apple uses this on purpose to avoid downloading all WORKSPACE dependencies every time we run bazel tests. so as things start migrating into different repos, it might be worthwhile to rethink how shell tests work in order to avoid these extra downloads on each run, or risk tests being flaky on network calls

@aiuto
Copy link
Contributor Author

aiuto commented Jul 25, 2019

Yes. I did not intend that we use the entire WORKSPACE. What we require is a scheme where the repos used in WORKSPACE can be marked in a particular way so that any test may do something like
add_to_workspace WORKSPACE rules_cc
Which will

  • extract the rules_cc stanza from the overall WORKSPACE
  • see if it is http_archive or git_repository (or maven ....) and add a loadI() for that to the top of WORKSPACE if not already there
  • append the desired stanza to the end.

And then the tests should be respoonsible for saying what they really need, rather than relying on the "default" WORKSPACE, which happens to have rules_cc in it today.

@jin jin added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged labels Jul 28, 2019
@laurentlb laurentlb added team-Rules-Server Issues for serverside rules included with Bazel and removed team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. labels Jul 29, 2019
@aiuto
Copy link
Contributor Author

aiuto commented Aug 1, 2019

Straw man proposal for external repositories we depend on by reference.

Example with rules_pkg

  • create 'deps/WORKSPACE.rules_pkg
  • create a test to make sure that WORKSPACE containts the same content as the deps. It would validate that
    for dep in deps/WORKSPACE.*
    • /WORKSPACE contains the text
    #### begin dep
      ... content of dep
    #### end dep
    
  • enhance .../devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java to allow reference to rules_pkg. That would include the content of //deps/WORKSPACE.rules_pkg in the WORKSPACE file it is constructing.
  • same or use the same utility for that .../devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java

Extended proposal:

  • deps/WORKSPACE.foo is generated
  • input to rule which generates WORKSPACE stanza is type, name, urls, sha, deps function and initialization function
  • integration tests depend on generated content, but that just works
  • WORKSPACE sanity checks need a little tweaking because it can not glob deps/WORKSPACE.*
  • BONUS: //:additional_distfiles can extract the repo name, urls and sha from the deps/ rules so that we do not have to repeat them multiple places in //WORKSPACE.

@philwo @aehlig WDYT?

@aiuto
Copy link
Contributor Author

aiuto commented Aug 1, 2019

This is not rules server. It is a 'how do we build bazel problem'. Switching to ProductExcellence for now.

@aiuto aiuto added team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website and removed team-Rules-Server Issues for serverside rules included with Bazel labels Aug 1, 2019
@philwo philwo added P2 We'll consider working on this in future. (Assignee optional) type: feature request and removed untriaged labels Sep 3, 2019
@philwo
Copy link
Member

philwo commented Sep 3, 2019

I think I understand the problem, but maybe not enough to give advice here. The proposal seems rather complex to me, but maybe I'm lacking context here. Why is it a problem if the integration tests just use the global WORKSPACE file? Bazel shouldn't download anything that's not used, even when it's present in the WORKSPACE, so why do we want to minimize the things in each test's WORKSPACE file?

Assigning to Florian to think about it a bit.

@aiuto
Copy link
Contributor Author

aiuto commented Sep 3, 2019

Why is it a problem if the integration tests just use the global WORKSPACE file?

That is an important question. Our current tests do not. They carefully craft just what they need. But I didn't write any of them and they all predate me, so I don't know why we got here.

I do know there are several Java integration tests which create a WORKSPACE and BUILD. They could just as easily copy the top level WORKSPACE. It would get rid of a bunch of test scaffolding.

@aiuto
Copy link
Contributor Author

aiuto commented Apr 22, 2020

I finally fixed the blackbox tests which lead to this issue. There are a bunch of tests that

  • create a "repo writing rule" suite with a WORKSPACE, BUILD and repo.bzl file that generates new rules and then tar's it all up.
  • and now creates a second WORKSPACE that loads the output of the first as an http_archive.

But I am not sure if the tests actually need that complexity. They are underdocumented w.r.t. to intent.

@aiuto
Copy link
Contributor Author

aiuto commented Nov 14, 2020

@fweikert
Copy link
Member

Unfortunately the link is dead. Is this still a problem, given the planned revamp of the whole external deps mechanism?

@github-actions
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 2+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Apr 26, 2023
@aiuto
Copy link
Contributor Author

aiuto commented Apr 29, 2023

I did a quick look and there are a few places left where tests hard code their own version of a repository.

@github-actions github-actions bot removed the stale Issues or PRs that are stale (no activity for 30 days) label Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants