Skip to content
Open
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
6 changes: 3 additions & 3 deletions third_party/binary/BUILD
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
remote_file(
name = "gosec_download",
hashes = ["226bd8825b7aed3d454446d1ec094f817f37859dded4211a5b707d0f36c5fdb7"],
hashes = ["38e596e1ad580666e5efaa159fbaf63bd5873ea1e74beacbdf785b025b52e1db"],
test_only = True,
url = ["https://github.com/securego/gosec/releases/download/v2.14.0/gosec_2.14.0_linux_amd64.tar.gz"],
url = ["https://github.com/securego/gosec/releases/download/v2.22.0/gosec_2.22.0_linux_amd64.tar.gz"],
)

genrule(
name = "gosec",
srcs = [":gosec_download"],
outs = ["gosec"],
binary = True,
cmd = "$TOOLS x $SRCS -s v2.14.0",
cmd = "$TOOLS x $SRCS -s v2.22.0",
test_only = True,
tools = [CONFIG.ARCAT_TOOL],
visibility = ["//tools/driver/..."],
Expand Down
4 changes: 4 additions & 0 deletions tools/driver/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 0.7.0
-------------
* Use the now-exported types for the request/response (#317)

Version 0.6.0
-------------
* Migrate to `go_repo` and upgrade golang.org/x packages (#316)
Expand Down
2 changes: 1 addition & 1 deletion tools/driver/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.0
0.7.0
6 changes: 3 additions & 3 deletions tools/driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var log = logging.MustGetLogger()
var opts = struct {
Usage string
Verbosity logging.Verbosity `short:"v" long:"verbosity" env:"PLZ_GOPACKAGESDRIVER_VERBOSITY" default:"warning" description:"Verbosity of output (higher number = more output)"`
LogFile string `long:"log_file" env:"PLZ_GOPACKAGESDRIVER_LOG_FILE" description:"Log additionally to this file"`
LogFile string `long:"log_file" env:"PLZ_GOPACKAGESDRIVER_LOG_FILE" description:"Log additionally to this file"`
NoInput bool `short:"n" long:"no_input" description:"Assume a default config and don't try to read from stdin"`
WorkingDir string `short:"w" long:"working_dir" description:"Change to this working directory before running"`
OutputFile string `short:"o" long:"output_file" env:"PLZ_GOPACKAGESDRIVER_OUTPUT_FILE" description:"File to write output to (in addition to stdout)"`
Expand Down Expand Up @@ -48,7 +48,7 @@ func main() {
}
}

req := &packages.DriverRequest{}
req := &xpackages.DriverRequest{}
if opts.NoInput {
req.Mode = xpackages.NeedExportFile
} else {
Expand Down Expand Up @@ -77,7 +77,7 @@ func main() {
}
}

func load(req *packages.DriverRequest) (*packages.DriverResponse, error) {
func load(req *xpackages.DriverRequest) (*xpackages.DriverResponse, error) {
if opts.SearchDir == "" {
return packages.Load(req, opts.Args.Files)
}
Expand Down
37 changes: 7 additions & 30 deletions tools/driver/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"go/build"
"go/types"
"io"
"io/fs"
"os"
Expand All @@ -24,29 +23,12 @@ import (

var log = logging.MustGetLogger()

// DriverRequest is copied from go/packages; it's the format of config that we get on stdin.
type DriverRequest struct {
Mode packages.LoadMode `json:"mode"`
Env []string `json:"env"`
BuildFlags []string `json:"build_flags"`
Tests bool `json:"tests"`
Overlay map[string][]byte `json:"overlay"`
}

// DriverResponse is copied from go/packages; it's our response about packages we've loaded.
type DriverResponse struct {
NotHandled bool
Sizes *types.StdSizes
Roots []string `json:",omitempty"`
Packages []*packages.Package
}

// Load reads a set of packages and returns information about them.
// Most of the request structure isn't honoured at the moment.
func Load(req *DriverRequest, files []string) (*DriverResponse, error) {
func Load(req *packages.DriverRequest, files []string) (*packages.DriverResponse, error) {
// If there are no files provided, do nothing.
if len(files) == 0 {
return &DriverResponse{NotHandled: true}, nil
return &packages.DriverResponse{NotHandled: true}, nil
}
// We need to find the plz repo that we need to be in (we might be invoked from outside it)
// For now we're assuming they're all in the same repo (which is probably reasonable) and just
Expand All @@ -65,7 +47,7 @@ func Load(req *DriverRequest, files []string) (*DriverResponse, error) {
} else if len(files) == 0 {
// Not obvious that this really is an error case.
log.Warning("No Go files found in initial query")
return &DriverResponse{NotHandled: true}, nil
return &packages.DriverResponse{NotHandled: true}, nil
} else if err := os.Chdir(filepath.Dir(files[0])); err != nil {
return nil, err
}
Expand Down Expand Up @@ -93,7 +75,7 @@ func Load(req *DriverRequest, files []string) (*DriverResponse, error) {

// LoadOffline is like Load but rather than querying plz to find the file to load, it just
// walks a file tree looking for pkg_info.json files.
func LoadOffline(req *DriverRequest, searchDir string, files []string) (*DriverResponse, error) {
func LoadOffline(req *packages.DriverRequest, searchDir string, files []string) (*packages.DriverResponse, error) {
pkgs := []*packages.Package{}
if err := filepath.WalkDir(searchDir, func(path string, d fs.DirEntry, err error) error {
lpkgs := []*packages.Package{}
Expand Down Expand Up @@ -127,7 +109,7 @@ func LoadOffline(req *DriverRequest, searchDir string, files []string) (*DriverR
return packagesToResponse(searchDir, pkgs, dirs)
}

func packagesToResponse(rootpath string, pkgs []*packages.Package, dirs map[string]struct{}) (*DriverResponse, error) {
func packagesToResponse(rootpath string, pkgs []*packages.Package, dirs map[string]struct{}) (*packages.DriverResponse, error) {
// Build the set of root packages
seenRoots := map[string]struct{}{}
roots := []string{}
Expand Down Expand Up @@ -178,13 +160,8 @@ func packagesToResponse(rootpath string, pkgs []*packages.Package, dirs map[stri
}
pkgs = append(pkgs, stdlib...)
}
log.Debug("Built package set")
return &DriverResponse{
Sizes: &types.StdSizes{
// These are obviously hardcoded. To worry about later.
WordSize: 8,
MaxAlign: 8,
},
log.Debugf("Built package set")
return &packages.DriverResponse{
Packages: pkgs,
Roots: roots,
}, nil
Expand Down
5 changes: 3 additions & 2 deletions tools/driver/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ gentest(
cmd = [
'export PLZ_GOPACKAGESDRIVER_SEARCHDIR="$TMP_DIR"',
'export GOPACKAGESDRIVER="$TOOLS_DRIVER"',
'"$TOOLS_GOSEC" --exclude G104,G304,G307 tools/driver/packages',
'"$TOOLS_GOSEC" --exclude G104,G304,G307 tools/driver/packages/... | tee $OUT',
],
outs = ["gosec_test.txt"],
needs_transitive_deps = True,
no_test_output = True,
requires = [
"go",
"go_src",
],
test_cmd = "true",
test_cmd = "cat $TEST",
tools = {
"driver": ["//tools/driver:plz-gopackagesdriver"],
"gosec": ["//third_party/binary:gosec"],
Expand Down