mirror of https://github.com/markbates/pkger.git
new include
This commit is contained in:
parent
5497054b42
commit
6c1b23a5cb
|
@ -5,6 +5,9 @@ import (
|
|||
"fmt"
|
||||
"go/token"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/markbates/pkger/here"
|
||||
)
|
||||
|
||||
var _ Decl = IncludeDecl{}
|
||||
|
@ -15,6 +18,34 @@ type IncludeDecl struct {
|
|||
value string
|
||||
}
|
||||
|
||||
func NewInclude(her here.Info, inc string) (IncludeDecl, error) {
|
||||
var id IncludeDecl
|
||||
pt, err := her.Parse(inc)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
|
||||
if pt.Pkg != her.ImportPath {
|
||||
her, err = here.Package(pt.Pkg)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
}
|
||||
|
||||
abs := filepath.Join(her.Module.Dir, pt.Name)
|
||||
|
||||
f := &File{
|
||||
Abs: abs,
|
||||
Path: pt,
|
||||
Here: her,
|
||||
}
|
||||
|
||||
return IncludeDecl{
|
||||
value: inc,
|
||||
file: f,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d IncludeDecl) String() string {
|
||||
return fmt.Sprintf("pkger.Include(%q)", d.value)
|
||||
}
|
||||
|
|
|
@ -226,30 +226,12 @@ func (p *Parser) parse() error {
|
|||
|
||||
func (p *Parser) parseIncludes() error {
|
||||
for _, i := range p.includes {
|
||||
pt, err := p.Info.Parse(i)
|
||||
d, err := NewInclude(p.Info, i)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
her := p.Info
|
||||
if pt.Pkg != her.ImportPath {
|
||||
her, err = here.Package(pt.Pkg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
abs := filepath.Join(her.Module.Dir, pt.Name)
|
||||
|
||||
f := &File{
|
||||
Abs: abs,
|
||||
Path: pt,
|
||||
Here: her,
|
||||
}
|
||||
p.decls["Include"] = append(p.decls["Include"], IncludeDecl{
|
||||
value: i,
|
||||
file: f,
|
||||
})
|
||||
p.decls["Include"] = append(p.decls["Include"], d)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue