Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassKind(fname string) (isProj, ok bool) #21

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions gopmod/classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package gopmod

import (
"errors"
"path"
"syscall"

"github.com/goplus/mod/modcache"
Expand All @@ -32,7 +33,7 @@ type Project = modfile.Project

var (
SpxProject = &Project{
Ext: ".gmx",
Ext: ".spx",
Class: "Game",
Works: []*Class{{Ext: ".spx", Class: "Sprite"}},
PkgPaths: []string{"github.com/goplus/spx", "math"},
Expand All @@ -45,9 +46,18 @@ var (

// -----------------------------------------------------------------------------

func (p *Module) ClassKind(ext string) (isWork, isProj bool) {
func (p *Module) ClassKind(fname string) (isProj, ok bool) {
ext := path.Ext(fname)
if c, ok := p.projects[ext]; ok {
isWork, isProj = c.Kind(ext)
for _, w := range c.Works {
if w.Ext == ext {
if ext != c.Ext || fname != "main"+ext {
return false, true
}
break
}
}
return true, true
}
return
}
Expand All @@ -68,6 +78,7 @@ func (p *Module) ImportClasses(importClass ...func(c *Project)) (err error) {
impcls = importClass[0]
}
p.importClass(SpxProject, impcls)
p.projects[".gmx"] = SpxProject // old style
if c := p.Project; c != nil {
p.importClass(c, impcls)
}
Expand Down
12 changes: 0 additions & 12 deletions modfile/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,6 @@ type Class struct {
Syntax *Line
}

func (p *Project) Kind(ext string) (isWork, isProj bool) {
for _, w := range p.Works {
if w.Ext == ext {
isWork = true
}
}
if p.Ext == ext {
isProj = true
}
return
}

// A VersionInterval represents a range of versions with upper and lower bounds.
// Intervals are closed: both bounds are included. When Low is equal to High,
// the interval may refer to a single version ('v1.2.3') or an interval
Expand Down
10 changes: 0 additions & 10 deletions modfile/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ func TestMustQuote(t *testing.T) {

// -----------------------------------------------------------------------------

func TestKind(t *testing.T) {
proj := &Project{Works: []*Class{{Ext: ".spx"}}, Ext: ".spx"}
isWork, isProj := proj.Kind(".spx")
if !isWork || !isProj {
t.Fatal("proj.Kind:", isWork, isProj)
}
}

// -----------------------------------------------------------------------------

var addGopTests = []struct {
desc string
in string
Expand Down