Skip to content

Commit

Permalink
Move runfiles logic into separate package (bazelbuild#182)
Browse files Browse the repository at this point in the history
This is a pure refactoring, which makes it easier for us to use Bazelisk internally.
  • Loading branch information
fweikert authored Oct 8, 2020
1 parent 35d180f commit f796b5e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ go_test(
"//core:go_default_library",
"//httputil:go_default_library",
"//repositories:go_default_library",
"//runfiles:go_default_library",
"//versions:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)

Expand Down
9 changes: 2 additions & 7 deletions bazelisk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ package main

import (
"fmt"
"io/ioutil"
"sort"
"testing"

"github.com/bazelbuild/bazelisk/core"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/bazelbuild/bazelisk/runfiles"
)

func TestScanIssuesForIncompatibleFlags(t *testing.T) {
path, err := bazel.Runfile("sample-issues-migration.json")
if err != nil {
t.Errorf("Can not load sample github issues")
}
samplesJSON, err := ioutil.ReadFile(path)
samplesJSON, err := runfiles.ReadFile("sample-issues-migration.json")
if err != nil {
t.Errorf("Can not load sample github issues")
}
Expand Down
13 changes: 13 additions & 0 deletions runfiles/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"runfiles.go",
],
importpath = "github.com/bazelbuild/bazelisk/runfiles",
visibility = ["//visibility:public"],
deps = [
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)
20 changes: 20 additions & 0 deletions runfiles/runfiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Package runfiles offers functionality to read data dependencies of tests.
package runfiles

import (
"io/ioutil"

"github.com/bazelbuild/rules_go/go/tools/bazel"
)

func ReadFile(name string) ([]byte, error) {
path, err := bazel.Runfile(name)
if err != nil {
return nil, err
}
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return data, nil
}

0 comments on commit f796b5e

Please sign in to comment.