mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-10 18:13:18 +01:00
internal/shaderlister: enable to specify multiple patterns
Updates #3157
This commit is contained in:
parent
76bba89589
commit
5db5346272
@ -188,7 +188,7 @@ const (
|
||||
|
||||
var (
|
||||
reShaderSourceDirective = regexp.MustCompile(`(?m)^\s*//` + regexp.QuoteMeta(shaderSourceDirective) + `$`)
|
||||
reShaderFileDirective = regexp.MustCompile(`(?m)^\s*//` + regexp.QuoteMeta(shaderFileDirective) + ` (.+)$`)
|
||||
reShaderFileDirective = regexp.MustCompile(`(?m)^\s*//` + regexp.QuoteMeta(shaderFileDirective) + ` `)
|
||||
)
|
||||
|
||||
func hasShaderSourceDirectiveInComment(commentGroup *ast.CommentGroup) bool {
|
||||
@ -200,6 +200,10 @@ func hasShaderSourceDirectiveInComment(commentGroup *ast.CommentGroup) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func isAsciiSpace(r rune) bool {
|
||||
return r == ' ' || r == '\t' || r == '\v' || r == '\n' || r == '\r'
|
||||
}
|
||||
|
||||
func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, error) {
|
||||
topLevelDecls := map[ast.Decl]struct{}{}
|
||||
for _, file := range pkg.Syntax {
|
||||
@ -213,14 +217,22 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
|
||||
}
|
||||
|
||||
// Resolve ebitengine:shaderfile directives.
|
||||
visitedPatterns := map[string]struct{}{}
|
||||
visitedPaths := map[string]struct{}{}
|
||||
for _, f := range pkg.Syntax {
|
||||
for _, c := range f.Comments {
|
||||
for _, l := range c.List {
|
||||
m := reShaderFileDirective.FindStringSubmatch(l.Text)
|
||||
if len(m) == 0 {
|
||||
m := reShaderFileDirective.FindString(l.Text)
|
||||
if m == "" {
|
||||
continue
|
||||
}
|
||||
pattern := filepath.Join(pkg.Dir, filepath.FromSlash(m[1]))
|
||||
patterns := strings.TrimPrefix(l.Text, m)
|
||||
for _, pattern := range strings.FieldsFunc(patterns, isAsciiSpace) {
|
||||
pattern := filepath.Join(pkg.Dir, filepath.FromSlash(pattern))
|
||||
if _, ok := visitedPatterns[pattern]; ok {
|
||||
continue
|
||||
}
|
||||
visitedPatterns[pattern] = struct{}{}
|
||||
stat, err := os.Stat(pattern)
|
||||
if err == nil && stat.IsDir() {
|
||||
// If the pattern is a directory, read all files in the directory recursively.
|
||||
@ -231,6 +243,10 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if _, ok := visitedPaths[path]; ok {
|
||||
return nil
|
||||
}
|
||||
visitedPaths[path] = struct{}{}
|
||||
shaders, err = appendShaderFromFile(shaders, pkg.PkgPath, path)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -249,6 +265,10 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
|
||||
return nil, err
|
||||
}
|
||||
for _, path := range paths {
|
||||
if _, ok := visitedPaths[path]; ok {
|
||||
continue
|
||||
}
|
||||
visitedPaths[path] = struct{}{}
|
||||
shaders, err = appendShaderFromFile(shaders, pkg.PkgPath, path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -257,6 +277,7 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve ebitengine:shadersource directives.
|
||||
var genDeclStack []*ast.GenDecl
|
||||
|
@ -69,7 +69,9 @@ const (
|
||||
_, _ = "ignored", "ignored again" // multiple consts are ignored to avoid confusion.
|
||||
)
|
||||
|
||||
//ebitengine:shaderfile *_kage.go
|
||||
//ebitengine:shaderfile resource
|
||||
//ebitengine:shaderfile *_kage.go resource nonexistent.go
|
||||
|
||||
// Duplicated files are ignored.
|
||||
//ebitengine:shaderfile *_kage.go *_kage.go *_kage.go
|
||||
|
||||
//ebitengine:shaderfile nonexistent.go
|
||||
|
Loading…
Reference in New Issue
Block a user