func (p *project) buildFileDeps(prog *goload.Program) map[string]interface{} { pkgDeps := godep.FileDepLoaded(prog) ret := make(map[string]interface{}) for pkg, g := range pkgDeps { m, e := dagvis.Layout(g) if p.err(e) { continue } ret[pkg] = dagvis.JSONMap(m) } return ret }
func (r *repo) pkgDeps() (interface{}, error) { g, err := godep.PkgDep(r.pkgs) if err != nil { return nil, err } g, err = g.Rename(r.trimPath) if err != nil { return nil, err } m, err := dagvis.Layout(g) if err != nil { return nil, err } return dagvis.JSONMap(m), nil }
func (p *project) buildPkgDep(pkgs []string) interface{} { g, e := godep.PkgDep(pkgs) if p.err(e) { return nil } g, e = g.Rename(p.trimPath) if p.err(e) { return nil } m, e := dagvis.Layout(g) if p.err(e) { return nil } return dagvis.JSONMap(m) }
func (r *repo) fileDeps() (map[string]interface{}, []error) { deps := godep.FileDepLoaded(r.prog) var errs []error ret := make(map[string]interface{}) for pkg, dep := range deps { m, err := dagvis.Layout(dep) if err != nil { errs = append(errs, err) continue } p, err := r.trimPath(pkg) if err != nil { errs = append(errs, err) continue } ret[p] = dagvis.JSONMap(m) } return ret, errs }
// Build builds a repo into a repodb build. // It performs static analysis on the repository. func Build(src, path string) (*repodb.Build, []error) { buildHash, err := git.CommitHash(src) if err != nil { return nil, []error{err} } lang := pl.LangGoLike() input := builds.NewDirHome(src, lang) input.AddLang("asm", asm.Lang()) output := builds.NewMemHome(lang) pkgs := input.Pkgs(".") for _, p := range pkgs { output.NewPkg(p) } deps := new(repodb.Deps) fileToks := make(map[string][]*lexing.Token) b := builds.NewBuilder(input, output) b.Verbose = true b.InitPC = arch.InitPC b.RunTests = false b.StaticOnly = true b.SaveDeps = func(m *dagvis.Map) { deps.Pkgs = dagvis.JSONMap(m) } b.SaveFileTokens = func(p string, toks []*lexing.Token) { fileToks[p] = toks } es := b.BuildPkgs(pkgs) if es != nil { return nil, lexErrors(es) } deps.Files = make(map[string]interface{}) for _, pkg := range pkgs { bs := output.OutputBytes(pkg, "depmap") if bs == nil { continue } var m map[string]interface{} err := json.Unmarshal(bs, &m) if err != nil { return nil, []error{err} } deps.Files[pkg] = m } files := make(map[string]*repodb.File) for _, pkg := range pkgs { srcFiles := input.Src(pkg) for name, f := range srcFiles { p := filepath.Join(pkg, name) toks := fileToks[p] if toks == nil { continue } res, err := renderFile(f, toks) if err != nil { return nil, []error{err} } p = filepath.Join(path, p) files[p] = res } } return &repodb.Build{ Name: path, Build: buildHash, Lang: "g", Deps: deps, Files: files, }, nil }