* feat: add experimental Apple Silicon support with Nivfold Integrate the standalone Nivfold protocol 1 runner; tested against Nivfold f436fb6. The Windows Reims vGPU runtime remains independent. * fix: open QQ invites and VM SSH on macOS * fix: move VM, View and Help to the macOS menu bar * feat(macos): add resumable Apple restore image downloads Expose the compatible restore image in the VM wizard and Images page, validate downloads before caching, and fix macOS memory reporting and plugin SVG rendering. * fix(macos): localize the native application menu * fix(macos): address native desktop review findings
99 lines
2.2 KiB
Go
99 lines
2.2 KiB
Go
package archtest
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/parser"
|
|
"go/token"
|
|
"io/fs"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
const modulePath = "github.com/Nwflower/reims-go"
|
|
|
|
// source is one Go file of the repository. All build constraints are covered:
|
|
// the checks read every file, not one platform's selection.
|
|
type source struct {
|
|
rel string // slash-separated path from the repository root
|
|
raw string
|
|
file *ast.File
|
|
}
|
|
|
|
func (s source) dir() string { return path.Dir(s.rel) }
|
|
func (s source) isTest() bool { return strings.HasSuffix(s.rel, "_test.go") }
|
|
|
|
// imports maps the local name of every module-internal import to its
|
|
// repository directory.
|
|
func (s source) imports() map[string]string {
|
|
out := map[string]string{}
|
|
for _, imp := range s.file.Imports {
|
|
p, err := strconv.Unquote(imp.Path.Value)
|
|
if err != nil || !strings.HasPrefix(p, modulePath+"/") {
|
|
continue
|
|
}
|
|
name := path.Base(p)
|
|
if imp.Name != nil {
|
|
name = imp.Name.Name
|
|
}
|
|
out[name] = strings.TrimPrefix(p, modulePath+"/")
|
|
}
|
|
return out
|
|
}
|
|
|
|
var fileSet = token.NewFileSet()
|
|
|
|
var loadSources = sync.OnceValues(func() ([]source, error) {
|
|
root, err := filepath.Abs(filepath.Join("..", ".."))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
skip := map[string]bool{".git": true, ".debug": true, ".local": true, "build": true, "frontend": true, "node_modules": true, "archtest": true}
|
|
var out []source
|
|
err = filepath.WalkDir(root, func(p string, d fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if d.IsDir() {
|
|
if skip[d.Name()] {
|
|
return filepath.SkipDir
|
|
}
|
|
return nil
|
|
}
|
|
if !strings.HasSuffix(p, ".go") {
|
|
return nil
|
|
}
|
|
raw, err := os.ReadFile(p)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
f, err := parser.ParseFile(fileSet, p, raw, parser.SkipObjectResolution|parser.ParseComments)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
rel, err := filepath.Rel(root, p)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
out = append(out, source{rel: filepath.ToSlash(rel), raw: string(raw), file: f})
|
|
return nil
|
|
})
|
|
return out, err
|
|
})
|
|
|
|
func sources(t *testing.T) []source {
|
|
t.Helper()
|
|
all, err := loadSources()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(all) < 300 {
|
|
t.Fatalf("found only %d Go files: the walk no longer sees the repository", len(all))
|
|
}
|
|
return all
|
|
}
|