bazelbuild / rules_webtesting

Bazel rules to allow testing against a browser with WebDriver.
Apache License 2.0
97 stars 56 forks source link

Unable to use rules_webtesting via git_repository #395

Open zellyn opened 4 years ago

zellyn commented 4 years ago

As a prequel to creating an internal fork of rules_webtesting, I am simply trying to get it to work using a git_repository rule rather than an http_archive rule.

# http_archive(
#     name = "io_bazel_rules_webtesting",
#     sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3",
#     urls = [
#         "https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.3/rules_webtesting.tar.gz","
#     ],
# )

git_repository(
    name = "io_bazel_rules_webtesting",
    tag = "0.3.3",
    remote = "https://github.com/bazelbuild/rules_webtesting.git",
)

However, I get this error:

INFO: Invocation ID: f572a350-6a5d-49f8-85cb-97c6a31f7e82
DEBUG: Rule 'io_bazel_rules_webtesting' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "e7e838126b64c9a51dc06078e2f491b9a07b144e", shallow_since = "1568054629 -0700" and dropping ["tag"]
DEBUG: Call stack for the definition of repository 'io_bazel_rules_webtesting' which is a git_repository (rule definition at /private/var/tmp/_bazel_zellyn/c56e2a60ec67d2dd598d789409bed348/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18):
 - /Users/zellyn/Development/java/WORKSPACE:25:1
ERROR: /Users/zellyn/Development/java/multipass/src/test/java/BUILD.bazel:569:1: error loading package '@io_bazel_rules_webtesting//go/wtl/main': Unable to find package for @io_bazel_rules_go//go:def.bzl: The repository '@io_bazel_rules_go' could not be resolved. and referenced by '//multipass/src/test/java:com/squareup/multipass/frontend/web/browser/LoginCodeAppointmentsBrowserTest_no-sandbox-chromium-local'
ERROR: Analysis of target '//multipass/src/test/java:com/squareup/multipass/frontend/web/browser/LoginCodeAppointmentsBrowserTest_no-sandbox-chromium-local' failed; build aborted: error loading package '@io_bazel_rules_webtesting//go/wtl/main': Unable to find package for @io_bazel_rules_go//go:def.bzl: The repository '@io_bazel_rules_go' could not be resolved.
INFO: Elapsed time: 1.191s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (14 packages loaded, 31 targets configured)
FAILED: Build did NOT complete successfully (14 packages loaded, 31 targets configured)
    currently loading: @io_bazel_rules_webtesting//go/metadata/main ... (3 packages)

Downloading the tar, and comparing, it appears that the go subdirectory is substantially different between the 0.3.3 tag and the 0.3.3 release:

diff -r rules_webtesting/go/ rules_webtesting_tar/go/
Only in rules_webtesting/go/: errors
Only in rules_webtesting/go/: healthreporter
diff -r rules_webtesting/go/metadata/main/BUILD.bazel rules_webtesting_tar/go/metadata/main/BUILD.bazel
1c1
< # Copyright 2017 Google Inc.
---
> # Copyright 2019 Google Inc.
17,18d16
< load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
< 
21,29c19
< go_library(
<     name = "go_default_library",
<     srcs = ["merger.go"],
<     importpath = "github.com/bazelbuild/rules_webtesting/go/metadata/main",
<     visibility = ["//go:__subpackages__"],
<     deps = ["//go/metadata:go_default_library"],
< )
< 
< go_binary(
---
> alias(
31,32c21,25
<     testonly = True,
<     embed = [":go_default_library"],
---
>     actual  = select({
>         "//common/conditions:linux": "linux_amd64_pure_stripped/main",
>         "//common/conditions:mac": "darwin_amd64_pure_stripped/main",
>         "//common/conditions:windows": "windows_amd64_pure_stripped/main.exe",
>     }),
34,43c27
< )
< 
< sh_test(
<     name = "merger_test",
<     srcs = ["merger_test.sh"],
<     data = [
<         ":main",
<         "//testdata",
<     ],
<     tags = ["noci"],
---
>     testonly = True,
Only in rules_webtesting_tar/go/metadata/main: darwin_amd64_pure_stripped
Only in rules_webtesting_tar/go/metadata/main: linux_amd64_pure_stripped
Only in rules_webtesting/go/metadata/main: merger.go
Only in rules_webtesting/go/metadata/main: merger_test.sh
Only in rules_webtesting_tar/go/metadata/main: windows_amd64_pure_stripped
Only in rules_webtesting/go/: webdriver
diff -r rules_webtesting/go/wsl/BUILD.bazel rules_webtesting_tar/go/wsl/BUILD.bazel
1c1
< # Copyright 2018 Google Inc.
---
> # Copyright 2019 Google Inc.
18d17
< load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
24d22
<     testonly = True,
26c24,28
<     executable = "//go/wsl/main",
---
>     executable = select({
>         "//common/conditions:linux": "main/linux_amd64_pure_stripped/main",
>         "//common/conditions:mac": "main/darwin_amd64_pure_stripped/main",
>         "//common/conditions:windows": "main/windows_amd64_pure_stripped/main.exe",
>     }),
28,50c30
< )
< 
< go_library(
<     name = "go_default_library",
<     srcs = ["wsl.go"],
<     importpath = "github.com/bazelbuild/rules_webtesting/go/wsl",
<     visibility = [":__subpackages__"],
<     deps = [
<         "//go/httphelper:go_default_library",
<         "//go/wsl/hub:go_default_library",
<         "//go/wsl/upload:go_default_library",
<     ],
< )
< 
< go_test(
<     name = "go_default_test",
<     srcs = ["wsl_test.go"],
<     data = ["//testdata"],
<     embed = [":go_default_library"],
<     deps = [
<         "//go/bazel:go_default_library",
<         "//go/portpicker:go_default_library",
<     ],
---
>     testonly = True,
Only in rules_webtesting/go/wsl: driver
Only in rules_webtesting/go/wsl: hub
Only in rules_webtesting/go/wsl/main: BUILD.bazel
Only in rules_webtesting_tar/go/wsl/main: darwin_amd64_pure_stripped
Only in rules_webtesting_tar/go/wsl/main: linux_amd64_pure_stripped
Only in rules_webtesting/go/wsl/main: main.go
Only in rules_webtesting_tar/go/wsl/main: windows_amd64_pure_stripped
Only in rules_webtesting/go/wsl: resolver
Only in rules_webtesting/go/wsl: upload
Only in rules_webtesting/go/wsl: wsl.go
Only in rules_webtesting/go/wsl: wsl_test.go
Only in rules_webtesting/go/wtl: BUILD.bazel
Only in rules_webtesting/go/wtl: diagnostics
Only in rules_webtesting/go/wtl: environment
diff -r rules_webtesting/go/wtl/main/BUILD.bazel rules_webtesting_tar/go/wtl/main/BUILD.bazel
1c1
< # Copyright 2017 Google Inc.
---
> # Copyright 2019 Google Inc.
17,18d16
< load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
< 
21,32c19
< go_library(
<     name = "go_default_library",
<     srcs = ["main.go"],
<     importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/main",
<     visibility = ["//go/wtl:__subpackages__"],
<     deps = [
<         "//go/wtl:go_default_library",
<         "//go/wtl/diagnostics:go_default_library",
<     ],
< )
< 
< go_binary(
---
> alias(
34,35c21,25
<     testonly = True,
<     embed = [":go_default_library"],
---
>     actual  = select({
>         "//common/conditions:linux": "linux_amd64_pure_stripped/main",
>         "//common/conditions:mac": "darwin_amd64_pure_stripped/main",
>         "//common/conditions:windows": "windows_amd64_pure_stripped/main.exe",
>     }),
36a27
>     testonly = True,
Only in rules_webtesting_tar/go/wtl/main: darwin_amd64_pure_stripped
Only in rules_webtesting_tar/go/wtl/main: linux_amd64_pure_stripped
Only in rules_webtesting/go/wtl/main: main.go
Only in rules_webtesting_tar/go/wtl/main: windows_amd64_pure_stripped
Only in rules_webtesting/go/wtl: proxy
Only in rules_webtesting/go/wtl: service
Only in rules_webtesting/go/wtl: wtl.go
zellyn commented 4 years ago

For reference, setting branch = "master" on the git_repository rule gives the same error.

DrMarcII commented 4 years ago

The published archive includes precompiled versions of two go binaries (Web Test Launcher and WebDriver Server Lite) and removes the source code for those binaries. If using rules_webtesting directly from Git, you need to add a repository rule for rules_go and some go libraries used by the Go code. Adding the following to your WORKSPACE should do the trick:

load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()

go_register_toolchains()

http_archive(
    name = "bazel_gazelle",
    sha256 = "be9296bfd64882e3c08e3283c58fcb461fa6dd3c171764fcc4cf322f60615a9b",
    urls = [
        "https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/0.18.1/bazel-gazelle-0.18.1.tar.gz",
        "https://github.com/bazelbuild/bazel-gazelle/releases/download/0.18.1/bazel-gazelle-0.18.1.tar.gz",
    ],
)

load("@io_bazel_rules_webtesting//web:go_repositories.bzl", "go_internal_repositories")

go_internal_repositories()
zellyn commented 4 years ago

That worked, at least in spirit 😄

What I ended up with was:

http_archive(
    name = "io_bazel_rules_go",
    sha256 = "313f2c7a23fecc33023563f082f381a32b9b7254f727a7dd2d6380ccc6dfe09b",
    urls = [
        "https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/0.19.3/rules_go-0.19.3.tar.gz",
        "https://github.com/bazelbuild/rules_go/releases/download/0.19.3/rules_go-0.19.3.tar.gz",
    ],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()

http_archive(
    name = "bazel_gazelle",
    sha256 = "be9296bfd64882e3c08e3283c58fcb461fa6dd3c171764fcc4cf322f60615a9b",
    urls = [
        "https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/0.18.1/bazel-gazelle-0.18.1.tar.gz",
        "https://github.com/bazelbuild/bazel-gazelle/releases/download/0.18.1/bazel-gazelle-0.18.1.tar.gz",
    ],
)
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
gazelle_dependencies()

git_repository(
    name = "io_bazel_rules_webtesting",
    # commit = "75694821771b21546cd36c59f4e93304e71f25a0", # Zellyn's commit that allows REMOVE:--foo to remove browser arguments
    tag = "0.3.3",
    # branch = "master",
    #remote = "ssh://git@gitmirror-us-west.sqcorp.co/git/~zellyn/bazel_rules_webtesting.git",
    remote = "https://github.com/bazelbuild/rules_webtesting.git",
)

http_archive(
    name = "rules_jvm_external",
    sha256 = "e5b97a31a3e8feed91636f42e19b11c49487b85e5de2f387c999ea14d77c7f45",
    strip_prefix = "rules_jvm_external-2.9",
    url = "https://maven.global.square/artifactory/bazel-binaries/bazelbuild/rules_jvm_external/archive/2.9.zip",
)

load("@io_bazel_rules_webtesting//web:java_repositories.bzl", "java_repositories", "RULES_WEBTESTING_ARTIFACTS")
java_repositories()

load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories")
browser_repositories(chromium=True, firefox=True)

load("@io_bazel_rules_webtesting//web:go_repositories.bzl", "go_internal_repositories")
go_internal_repositories()
zellyn commented 4 years ago

Although it's using the updated metadata merger, it's not actually removing flags. I think it may be an ordering problem; investigating.

zellyn commented 4 years ago

397 fixed it