parent
c9399797d8
commit
14839e027f
|
@ -31,10 +31,10 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// findStdPkg needs to find the bundled standard library packages.
|
// findStdPkg needs to find the bundled standard library packages.
|
||||||
func findStdPkg(path, GOOS, GOARCH string) (io.ReadCloser, error) {
|
func (i *importer) findStdPkg(path string) (io.ReadCloser, error) {
|
||||||
if path == "C" {
|
if path == "C" {
|
||||||
// Cgo builds cannot be analyzed. Skip.
|
// Cgo builds cannot be analyzed. Skip.
|
||||||
return nil, ErrSkip
|
return nil, ErrSkip
|
||||||
}
|
}
|
||||||
return os.Open(fmt.Sprintf("external/go_sdk/pkg/%s_%s/%s.a", GOOS, GOARCH, path))
|
return os.Open(fmt.Sprintf("external/go_sdk/pkg/%s_%s/%s.a", i.GOOS, i.GOARCH, path))
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,10 @@ def _nogo_aspect_impl(target, ctx):
|
||||||
else:
|
else:
|
||||||
return [NogoInfo()]
|
return [NogoInfo()]
|
||||||
|
|
||||||
# Construct the Go environment from the go_context.env dictionary.
|
go_ctx = go_context(ctx)
|
||||||
env_prefix = " ".join(["%s=%s" % (key, value) for (key, value) in go_context(ctx).env.items()])
|
|
||||||
|
# Construct the Go environment from the go_ctx.env dictionary.
|
||||||
|
env_prefix = " ".join(["%s=%s" % (key, value) for (key, value) in go_ctx.env.items()])
|
||||||
|
|
||||||
# Start with all target files and srcs as input.
|
# Start with all target files and srcs as input.
|
||||||
inputs = target.files.to_list() + srcs
|
inputs = target.files.to_list() + srcs
|
||||||
|
@ -45,7 +47,7 @@ def _nogo_aspect_impl(target, ctx):
|
||||||
"#!/bin/bash",
|
"#!/bin/bash",
|
||||||
"%s %s tool objdump %s > %s\n" % (
|
"%s %s tool objdump %s > %s\n" % (
|
||||||
env_prefix,
|
env_prefix,
|
||||||
go_context(ctx).go.path,
|
go_ctx.go.path,
|
||||||
[f.path for f in binaries if f.path.endswith(".a")][0],
|
[f.path for f in binaries if f.path.endswith(".a")][0],
|
||||||
disasm_file.path,
|
disasm_file.path,
|
||||||
),
|
),
|
||||||
|
@ -53,7 +55,7 @@ def _nogo_aspect_impl(target, ctx):
|
||||||
ctx.actions.run(
|
ctx.actions.run(
|
||||||
inputs = binaries,
|
inputs = binaries,
|
||||||
outputs = [disasm_file],
|
outputs = [disasm_file],
|
||||||
tools = go_context(ctx).runfiles,
|
tools = go_ctx.runfiles,
|
||||||
mnemonic = "GoObjdump",
|
mnemonic = "GoObjdump",
|
||||||
progress_message = "Objdump %s" % target.label,
|
progress_message = "Objdump %s" % target.label,
|
||||||
executable = dumper,
|
executable = dumper,
|
||||||
|
@ -70,9 +72,11 @@ def _nogo_aspect_impl(target, ctx):
|
||||||
ImportPath = importpath,
|
ImportPath = importpath,
|
||||||
GoFiles = [src.path for src in srcs if src.path.endswith(".go")],
|
GoFiles = [src.path for src in srcs if src.path.endswith(".go")],
|
||||||
NonGoFiles = [src.path for src in srcs if not src.path.endswith(".go")],
|
NonGoFiles = [src.path for src in srcs if not src.path.endswith(".go")],
|
||||||
GOOS = go_context(ctx).goos,
|
# Google's internal build system needs a bit more help to find std.
|
||||||
GOARCH = go_context(ctx).goarch,
|
StdZip = go_ctx.std_zip.short_path if hasattr(go_ctx, "std_zip") else "",
|
||||||
Tags = go_context(ctx).tags,
|
GOOS = go_ctx.goos,
|
||||||
|
GOARCH = go_ctx.goarch,
|
||||||
|
Tags = go_ctx.tags,
|
||||||
FactMap = {}, # Constructed below.
|
FactMap = {}, # Constructed below.
|
||||||
ImportMap = {}, # Constructed below.
|
ImportMap = {}, # Constructed below.
|
||||||
FactOutput = facts.path,
|
FactOutput = facts.path,
|
||||||
|
@ -110,7 +114,7 @@ def _nogo_aspect_impl(target, ctx):
|
||||||
ctx.actions.run(
|
ctx.actions.run(
|
||||||
inputs = inputs,
|
inputs = inputs,
|
||||||
outputs = [facts],
|
outputs = [facts],
|
||||||
tools = go_context(ctx).runfiles,
|
tools = go_ctx.runfiles,
|
||||||
executable = ctx.files._nogo[0],
|
executable = ctx.files._nogo[0],
|
||||||
mnemonic = "GoStaticAnalysis",
|
mnemonic = "GoStaticAnalysis",
|
||||||
progress_message = "Analyzing %s" % target.label,
|
progress_message = "Analyzing %s" % target.label,
|
||||||
|
|
|
@ -55,6 +55,7 @@ type pkgConfig struct {
|
||||||
FactMap map[string]string
|
FactMap map[string]string
|
||||||
FactOutput string
|
FactOutput string
|
||||||
Objdump string
|
Objdump string
|
||||||
|
StdZip string
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadFacts finds and loads facts per FactMap.
|
// loadFacts finds and loads facts per FactMap.
|
||||||
|
@ -111,7 +112,7 @@ func (i *importer) Import(path string) (*types.Package, error) {
|
||||||
if !ok {
|
if !ok {
|
||||||
// Not found in the import path. Attempt to find the package
|
// Not found in the import path. Attempt to find the package
|
||||||
// via the standard library.
|
// via the standard library.
|
||||||
rc, err = findStdPkg(path, i.GOOS, i.GOARCH)
|
rc, err = i.findStdPkg(path)
|
||||||
} else {
|
} else {
|
||||||
// Open the file.
|
// Open the file.
|
||||||
rc, err = os.Open(realPath)
|
rc, err = os.Open(realPath)
|
||||||
|
|
Loading…
Reference in New Issue