mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 15:33:40 +00:00
Adding extra files for testing multiline, globbing, etc.
This commit is contained in:
+24
-3
@@ -8,7 +8,6 @@ import (
|
|||||||
"go/constant"
|
"go/constant"
|
||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
"log"
|
|
||||||
"math/bits"
|
"math/bits"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -760,13 +759,35 @@ func (c *compilerContext) createPackage(irbuilder llvm.Builder, pkg *ssa.Package
|
|||||||
case *ssa.Global:
|
case *ssa.Global:
|
||||||
// Global variable.
|
// Global variable.
|
||||||
info := c.getGlobalInfo(member)
|
info := c.getGlobalInfo(member)
|
||||||
|
// process go:embed pragmas
|
||||||
|
// TODO: skip this if not Go 1.16 or higher
|
||||||
if strings.TrimSpace(info.embeds) != "" {
|
if strings.TrimSpace(info.embeds) != "" {
|
||||||
embeds, err := parseGoEmbed(info.embeds)
|
embeds, err := parseGoEmbed(info.embeds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
c.addError(member.Pos(), `invalid go:embed pragma: `+err.Error())
|
||||||
|
goto getGlobal
|
||||||
}
|
}
|
||||||
fmt.Printf("file embed found at %v: %v\n", info.linkName, embeds)
|
importsEmbedPkg := false
|
||||||
|
for _, imprt := range pkg.Pkg.Imports() {
|
||||||
|
if imprt.Name() == "embed" {
|
||||||
|
importsEmbedPkg = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !importsEmbedPkg {
|
||||||
|
// FIXME: technically the "embed" package needs to be imported in every
|
||||||
|
// *source file* that has a //go:embed pragma... that will always be the
|
||||||
|
// case when referencing embed.FS but not necessarily when a go:embed
|
||||||
|
// pragma is added to a string or []byte. For now, as long as the embed
|
||||||
|
// package is imported in at least one source file, TinyGo will process
|
||||||
|
// any go:embed pragmas in the entire package.
|
||||||
|
c.addError(member.Pos(), `//go:embed only allowed in Go files that import "embed"`)
|
||||||
|
goto getGlobal
|
||||||
|
}
|
||||||
|
fmt.Printf("file embed found at %v (import: %v): %v\n", info.linkName, importsEmbedPkg, embeds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getGlobal:
|
||||||
global := c.getGlobal(member)
|
global := c.getGlobal(member)
|
||||||
if !info.extern {
|
if !info.extern {
|
||||||
global.SetInitializer(llvm.ConstNull(global.Type().ElementType()))
|
global.SetInitializer(llvm.ConstNull(global.Type().ElementType()))
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed file1.txt file2.txt
|
//go:embed file*.txt
|
||||||
//go:embed file3.txt
|
//go:embed index.html styles.css
|
||||||
var files embed.FS
|
var files embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
println(".....")
|
||||||
println(msg)
|
println(msg)
|
||||||
contents, err := files.ReadDir(".")
|
contents, err := files.ReadDir(".")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user