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

Add go_repository rule for importing go packages. #96

Merged
merged 1 commit into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions build_files/com_github_gorilla_mux.BUILD

This file was deleted.

37 changes: 0 additions & 37 deletions build_files/com_github_tebeka_selenium.BUILD

This file was deleted.

2 changes: 1 addition & 1 deletion go/launcher/proxy/driver_hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/bazelbuild/rules_webtesting/go/launcher/proxy/webdriver"
"github.com/bazelbuild/rules_webtesting/go/metadata/metadata"
"github.com/bazelbuild/rules_webtesting/go/util/httphelper"
"github.com/gorilla/mux/mux"
"github.com/gorilla/mux"
)

const envTimeout = 5 * time.Minute // some environments such as Android take a long time to start up.
Expand Down
2 changes: 1 addition & 1 deletion go/launcher/proxy/driver_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

"github.com/bazelbuild/rules_webtesting/go/launcher/errors"
"github.com/bazelbuild/rules_webtesting/go/launcher/proxy/webdriver"
"github.com/gorilla/mux/mux"
"github.com/gorilla/mux"
)

// WebDriverSession is an http.Handler for forwarding requests to a WebDriver session.
Expand Down
2 changes: 1 addition & 1 deletion go/launcher/proxy/quit_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/bazelbuild/rules_webtesting/go/util/bazel"
"github.com/bazelbuild/rules_webtesting/go/webtest"
"github.com/tebeka/selenium/selenium"
"github.com/tebeka/selenium"
)

func TestCloseOneWindow(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go/launcher/proxy/screenshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/bazelbuild/rules_webtesting/go/util/bazel"
"github.com/bazelbuild/rules_webtesting/go/webtest"
"github.com/tebeka/selenium/selenium"
"github.com/tebeka/selenium"
)

func TestScreenshot(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go/screenshotter/screenshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"os"
"strings"

"github.com/tebeka/selenium/selenium"
"github.com/tebeka/selenium"
)

// Screenshotter allows configurable screenshotting.
Expand Down
2 changes: 1 addition & 1 deletion go/screenshotter/screenshotter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/bazelbuild/rules_webtesting/go/util/bazel"
"github.com/bazelbuild/rules_webtesting/go/webtest"
"github.com/tebeka/selenium/selenium"
"github.com/tebeka/selenium"
)

func TestOfElement(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go/webtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (

"github.com/bazelbuild/rules_webtesting/go/metadata/metadata"
"github.com/bazelbuild/rules_webtesting/go/util/bazel"
"github.com/tebeka/selenium/selenium"
"github.com/tebeka/selenium"
)

var info *BrowserInfo
Expand Down
2 changes: 1 addition & 1 deletion go/webtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"strings"
"testing"

"github.com/tebeka/selenium/selenium"
"github.com/tebeka/selenium"
)

func TestProvisionBrowser_NoCaps(t *testing.T) {
Expand Down
103 changes: 103 additions & 0 deletions web/internal/go_repository.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Defines a go_repository rule that downloads and sets up a go package."""


def go_repository(name,
urls,
sha256,
license,
import_name,
strip_prefix=None,
excluded_srcs=None,
license_file="LICENSE",
deps=None,
testonly=None):
"""go_repository downloads a go package and makes it available for import.

The bazel dep for the go package is "@name".
The go import for the go package is "import_name".

Args:
name: Name of the repository rule. BUILD files can depend on the package
as "@name"
urls: A list of URLs where the package can be downloaded from.
sha256: SHA256 for downloaded file.
license: A string indicating the licenses for the package.
e.g. "licenses([\"notice\"]) # MIT.".
import_name: The value for go_prefix. Go files can import this package
as import "import_name".
strip_prefix: Any directories to strip of the prefix when extracting the
downloaded file.
excluded_srcs: Any .go file in the package that should be excluded.
**/*test.go is always excluded.
license_file: The name of the license file. By default "LICENSE".
deps: Any dependencies for the go package.
testonly: Whether the rules should be marked testonly.
"""
if deps:
deps_str = '"' + '",\n "'.join(deps) + '"'
else:
deps_str = ''

if excluded_srcs:
excludes_str = '"' + '",\n "'.join(excluded_srcs) + '",'
else:
excludes_str = ''

build_file = """
load("@io_bazel_rules_go//go:def.bzl", "go_prefix", "go_library")

{license}

exports_files(["{license_file}"])

go_prefix("{import_name}")

go_library(
name = "go_default_library",
srcs = glob(
["*.go"],
exclude = [
"*test.go",
{excludes}
],
),
testonly = {testonly},
deps = [
{deps}
],
)

alias(
name = "{name}",
actual = ":go_default_library",
testonly = {testonly},
visibility = ["//visibility:public"],
)
""".format(
name=name,
license=license,
license_file=license_file,
import_name=import_name,
testonly=testonly,
deps=deps_str,
excludes=excludes_str)

native.new_http_archive(
name=name,
build_file_content=build_file,
sha256=sha256,
urls=urls,
strip_prefix=strip_prefix)
13 changes: 8 additions & 5 deletions web/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

load("//web/internal:java_import_external.bzl", "java_import_external")
load("//web/internal:platform_http_file.bzl", "platform_http_file")

load("//web/internal:go_repository.bzl", "go_repository")

def web_test_repositories(
omit_cglib_nodep=False,
Expand Down Expand Up @@ -137,23 +137,26 @@ def cglib_nodep():


def com_github_gorilla_mux():
native.new_http_archive(
go_repository(
name="com_github_gorilla_mux",
build_file=str(Label("//build_files:com_github_gorilla_mux.BUILD")),
import_name="github.com/gorilla/mux",
sha256="a32c13a36c58cb321136231ae8b67b0c6ad3c5f462e65eb6771f59c44b44ccba",
strip_prefix="mux-757bef944d0f21880861c2dd9c871ca543023cba",
excluded_srcs = ["context_gorilla.go"],
license = "licenses([\"notice\"])",
urls=[
"http://bazel-mirror.storage.googleapis.com/github.com/gorilla/mux/archive/757bef944d0f21880861c2dd9c871ca543023cba.tar.gz",
"https://github.com/gorilla/mux/archive/757bef944d0f21880861c2dd9c871ca543023cba.tar.gz",
])


def com_github_tebeka_selenium():
native.new_http_archive(
go_repository(
name="com_github_tebeka_selenium",
build_file=str(Label("//build_files:com_github_tebeka_selenium.BUILD")),
import_name="github.com/tebeka/selenium",
sha256="c33decb47a9b81d5221cda29c8f040ca5cf874956bbb002ef82b06e07ed78c3d",
strip_prefix="selenium-f6f9a3638fa049f85b0aaf42e693e1c4ab257d4f",
license="licenses([\"notice\"]) # MIT.",
urls=[
"http://bazel-mirror.storage.googleapis.com/github.com/tebeka/selenium/archive/f6f9a3638fa049f85b0aaf42e693e1c4ab257d4f.tar.gz",
"https://github.com/tebeka/selenium/archive/f6f9a3638fa049f85b0aaf42e693e1c4ab257d4f.tar.gz",
Expand Down