Skip to content

Commit

Permalink
internal/shaderlister: separate File into GoFile and KageFile
Browse files Browse the repository at this point in the history
Updates #3157
  • Loading branch information
hajimehoshi committed Feb 8, 2025
1 parent 42125a8 commit 5e2f2d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
22 changes: 13 additions & 9 deletions internal/shaderlister/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func main() {

type Shader struct {
Package string
File string
GoFile string `json:",omitempty"`
KageFile string `json:",omitempty"`
Source string
SourceHash string
GLSL *GLSL `json:",omitempty"`
Expand Down Expand Up @@ -236,7 +237,8 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
return nil
}
visitedPaths[path] = struct{}{}
shaders, err = appendShaderFromFile(shaders, pkg.PkgPath, path)
goFile := pkg.Fset.Position(c.Pos()).Filename
shaders, err = appendShaderFromFile(shaders, pkg.PkgPath, goFile, path)
if err != nil {
return err
}
Expand All @@ -258,7 +260,8 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
continue
}
visitedPaths[path] = struct{}{}
shaders, err = appendShaderFromFile(shaders, pkg.PkgPath, path)
goFile := pkg.Fset.Position(c.Pos()).Filename
shaders, err = appendShaderFromFile(shaders, pkg.PkgPath, goFile, path)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -395,7 +398,7 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err

shaders = append(shaders, Shader{
Package: pkg.PkgPath,
File: pkg.Fset.Position(spec.Pos()).Filename,
GoFile: pkg.Fset.Position(spec.Pos()).Filename,
Source: constant.StringVal(val),
})
return false
Expand All @@ -408,15 +411,16 @@ func appendShaderSources(shaders []Shader, pkg *packages.Package) ([]Shader, err
return shaders, nil
}

func appendShaderFromFile(shaders []Shader, pkgPath string, filePath string) ([]Shader, error) {
content, err := os.ReadFile(filePath)
func appendShaderFromFile(shaders []Shader, pkgPath string, goFile string, kageFile string) ([]Shader, error) {
content, err := os.ReadFile(kageFile)
if err != nil {
return nil, err
}
shaders = append(shaders, Shader{
Package: pkgPath,
File: filePath,
Source: string(content),
Package: pkgPath,
GoFile: goFile,
KageFile: kageFile,
Source: string(content),
})
return shaders, nil
}
Expand Down
6 changes: 4 additions & 2 deletions internal/shaderlister/shaderlister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func TestRun(t *testing.T) {

type shader struct {
Package string
File string
GoFile string
KageFile string
Source string
SourceHash string
}
Expand Down Expand Up @@ -89,9 +90,10 @@ func TestRun(t *testing.T) {
if s.shader.Package == "" {
t.Errorf("s.Package is empty: %v", s)
}
if s.shader.File == "" {
if s.shader.GoFile == "" {
t.Errorf("s.File is empty: %v", s)
}
// KageFile can be empty.
hash, err := graphics.CalcSourceHash([]byte(s.shader.Source))
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 5e2f2d3

Please sign in to comment.