Skip to content

Commit

Permalink
parse full information from go list
Browse files Browse the repository at this point in the history
  • Loading branch information
easeway committed Sep 28, 2021
1 parent 87cb0f5 commit 157d9a5
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 8 deletions.
12 changes: 7 additions & 5 deletions pkg/repos/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ type Repo struct {
// NewRepo creates a Repo from the specified directory as working directory.
// If wd is empty, the current working directory is used.
func NewRepo(workDir string) (*Repo, error) {
var err error
if workDir == "" {
wd, err := os.Getwd()
if err != nil {
return nil, err
}
workDir = wd
workDir, err = os.Getwd()
} else {
workDir, err = filepath.Abs(workDir)
}
if err != nil {
return nil, err
}
r := &Repo{WorkDir: workDir}
if err := r.LocateRoot(); err != nil {
Expand Down
28 changes: 25 additions & 3 deletions pkg/tools/go/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"fmt"
"go/build"
"io"
"os"
"os/exec"
Expand Down Expand Up @@ -51,6 +50,29 @@ type Executor struct {
stateOpaque []string
}

type listPackage struct {
Dir string // directory containing package sources
GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
CgoFiles []string // .go source files that import "C"
CompiledGoFiles []string // .go files presented to compiler (when using -compiled)
IgnoredGoFiles []string // .go source files ignored due to build constraints
IgnoredOtherFiles []string // non-.go source files ignored due to build constraints
CFiles []string // .c source files
CXXFiles []string // .cc, .cxx and .cpp source files
MFiles []string // .m source files
HFiles []string // .h, .hh, .hpp and .hxx source files
FFiles []string // .f, .F, .for and .f90 Fortran source files
SFiles []string // .s source files
SwigFiles []string // .swig files
SwigCXXFiles []string // .swigcxx files
SysoFiles []string // .syso object files to add to archive
TestGoFiles []string // _test.go files in package
XTestGoFiles []string // _test.go files outside package
EmbedFiles []string // files matched by EmbedPatterns
TestEmbedFiles []string // files matched by TestEmbedPatterns
XTestEmbedFiles []string // files matched by XTestEmbedPatterns
}

// CreateToolExecutor implements repos.Tool.
func (t *Tool) CreateToolExecutor(target *repos.Target) (repos.ToolExecutor, error) {
var params Params
Expand Down Expand Up @@ -133,7 +155,7 @@ func (x *Executor) validateCache(ctx context.Context, xctx *repos.ToolExecContex
prefix := xctx.ProjectDir() + string(filepath.Separator)
decoder := json.NewDecoder(&out)
for {
var pkg build.Package
var pkg listPackage
err := decoder.Decode(&pkg)
if err == io.EOF {
break
Expand All @@ -146,7 +168,7 @@ func (x *Executor) validateCache(ctx context.Context, xctx *repos.ToolExecContex
continue
}
err = reportInputFiles(cache, pkg.Dir[len(prefix):],
pkg.GoFiles, pkg.CFiles, pkg.CXXFiles, pkg.MFiles, pkg.HFiles, pkg.SFiles, pkg.SwigFiles, pkg.SwigCXXFiles, pkg.SysoFiles)
pkg.GoFiles, pkg.CFiles, pkg.CXXFiles, pkg.MFiles, pkg.HFiles, pkg.SFiles, pkg.SwigFiles, pkg.SwigCXXFiles, pkg.SysoFiles, pkg.EmbedFiles)
if err != nil {
xctx.Logger.Print(err)
return false
Expand Down
1 change: 1 addition & 0 deletions test/samples/nested/top/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/out
16 changes: 16 additions & 0 deletions test/samples/nested/top/.repos/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: repos.test.top
targets:
say:
rule:
exec:
command: 'echo Say!'
always: true

sub:
deps:
- repos.test.sub:say
rule:
exec:
command: 'echo After sub'
always: true
8 changes: 8 additions & 0 deletions test/samples/nested/top/REPOS.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
data-dir: out/repos
project-path-exclude:
- '_*'
- '.*'
- '/local'
- '/tmp'
- '/out'
1 change: 1 addition & 0 deletions test/samples/nested/top/sub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/out
8 changes: 8 additions & 0 deletions test/samples/nested/top/sub/.repos/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: repos.test.sub
targets:
say:
rule:
exec:
command: 'echo sub Say!'
always: true
8 changes: 8 additions & 0 deletions test/samples/nested/top/sub/REPOS.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
data-dir: out/repos
project-path-exclude:
- '_*'
- '.*'
- '/local'
- '/tmp'
- '/out'

0 comments on commit 157d9a5

Please sign in to comment.