lang: Pass through the fs and be consistent in usage
This simplifies the API by passing through the filesystem so that function signatures don't need to be as complicated, and furthermore use that consistently throughout.
This commit is contained in:
@@ -3474,7 +3474,7 @@ func (obj *StmtProg) importSystemScope(name string) (*interfaces.Scope, error) {
|
||||
// importScopeWithInputs returns a local or remote scope from an inputs string.
|
||||
// The inputs string is the common frontend for a lot of our parsing decisions.
|
||||
func (obj *StmtProg) importScopeWithInputs(s string, scope *interfaces.Scope, parentVertex *pgraph.SelfVertex) (*interfaces.Scope, error) {
|
||||
output, err := inputs.ParseInput(s, obj.data.Fs)
|
||||
input, err := inputs.ParseInput(s, obj.data.Fs)
|
||||
if err != nil {
|
||||
return nil, errwrap.Wrapf(err, "could not activate an input parser")
|
||||
}
|
||||
@@ -3484,12 +3484,12 @@ func (obj *StmtProg) importScopeWithInputs(s string, scope *interfaces.Scope, pa
|
||||
// run recursion detection by checking for duplicates in the seen files
|
||||
// TODO: do the paths need to be cleaned for "../", etc before compare?
|
||||
//for _, name := range obj.data.Files { // existing seen files
|
||||
// if util.StrInList(name, output.Files) {
|
||||
// if util.StrInList(name, input.Files) {
|
||||
// return nil, fmt.Errorf("recursive import of: `%s`", name)
|
||||
// }
|
||||
//}
|
||||
|
||||
reader := bytes.NewReader(output.Main)
|
||||
reader := bytes.NewReader(input.Main)
|
||||
|
||||
// nested logger
|
||||
logf := func(format string, v ...interface{}) {
|
||||
@@ -3498,11 +3498,11 @@ func (obj *StmtProg) importScopeWithInputs(s string, scope *interfaces.Scope, pa
|
||||
|
||||
// build new list of files
|
||||
files := []string{}
|
||||
files = append(files, output.Files...)
|
||||
files = append(files, input.Files...)
|
||||
files = append(files, obj.data.Files...)
|
||||
|
||||
// store a reference to the parent metadata
|
||||
metadata := output.Metadata
|
||||
metadata := input.Metadata
|
||||
metadata.Metadata = obj.data.Metadata
|
||||
|
||||
// now run the lexer/parser to do the import
|
||||
@@ -3518,9 +3518,9 @@ func (obj *StmtProg) importScopeWithInputs(s string, scope *interfaces.Scope, pa
|
||||
// init and validate the structure of the AST
|
||||
data := &interfaces.Data{
|
||||
// TODO: add missing fields here if/when needed
|
||||
Fs: obj.data.Fs,
|
||||
FsURI: obj.data.FsURI,
|
||||
Base: output.Base, // new base dir (absolute path)
|
||||
Fs: input.FS, // formerly: obj.data.Fs,
|
||||
FsURI: input.FS.URI(), // formerly: obj.data.FsURI,
|
||||
Base: input.Base, // new base dir (absolute path)
|
||||
Files: files,
|
||||
Imports: parentVertex, // the parent vertex that imported me
|
||||
Metadata: metadata,
|
||||
@@ -3593,7 +3593,7 @@ func (obj *StmtProg) importScopeWithInputs(s string, scope *interfaces.Scope, pa
|
||||
obj.importProgs = append(obj.importProgs, prog)
|
||||
|
||||
// collecting these here is more elegant (and possibly more efficient!)
|
||||
obj.importFiles = append(obj.importFiles, output.Files...) // save for CollectFiles
|
||||
obj.importFiles = append(obj.importFiles, input.Files...) // save for CollectFiles
|
||||
|
||||
return prog.scope, nil
|
||||
}
|
||||
|
||||
@@ -263,8 +263,8 @@ func (obj *GAPI) Cli(cliInfo *gapi.CliInfo) (*gapi.Deploy, error) {
|
||||
// init and validate the structure of the AST
|
||||
data := &interfaces.Data{
|
||||
// TODO: add missing fields here if/when needed
|
||||
Fs: localFs, // the local fs!
|
||||
FsURI: localFs.URI(), // TODO: is this right?
|
||||
Fs: output.FS, // formerly: localFs // the local fs!
|
||||
FsURI: output.FS.URI(), // formerly: localFs.URI() // TODO: is this right?
|
||||
Base: output.Base, // base dir (absolute path) that this is rooted in
|
||||
Files: output.Files,
|
||||
Imports: importVertex,
|
||||
@@ -770,8 +770,8 @@ func (obj *GAPI) Get(getInfo *gapi.GetInfo) error {
|
||||
// init and validate the structure of the AST
|
||||
data := &interfaces.Data{
|
||||
// TODO: add missing fields here if/when needed
|
||||
Fs: localFs, // the local fs!
|
||||
FsURI: localFs.URI(), // TODO: is this right?
|
||||
Fs: output.FS, // formerly: localFs // the local fs!
|
||||
FsURI: output.FS.URI(), // formerly: localFs.URI() // TODO: is this right?
|
||||
Base: output.Base, // base dir (absolute path) that this is rooted in
|
||||
Files: output.Files,
|
||||
Imports: importVertex,
|
||||
|
||||
@@ -66,6 +66,7 @@ var (
|
||||
// ParsedInput is the output struct which contains all the information we need.
|
||||
type ParsedInput struct {
|
||||
//activated bool // if struct is not nil we're activated
|
||||
FS engine.Fs // reference to the engine.Fs used to call the parse
|
||||
Base string // base path (abs path with trailing slash)
|
||||
Main []byte // contents of main entry mcl code
|
||||
Files []string // files and dirs to copy to fs (abs paths)
|
||||
@@ -214,6 +215,7 @@ func inputMetadata(s string, fs engine.Fs) (*ParsedInput, error) {
|
||||
return nil, errwrap.Wrapf(err, "could not build metadata")
|
||||
}
|
||||
return &ParsedInput{
|
||||
FS: fs,
|
||||
Base: basePath,
|
||||
Main: b,
|
||||
Files: files,
|
||||
@@ -261,6 +263,7 @@ func inputMcl(s string, fs engine.Fs) (*ParsedInput, error) {
|
||||
},
|
||||
}
|
||||
return &ParsedInput{
|
||||
FS: fs,
|
||||
Base: dirify(filepath.Dir(s)), // base path with trailing slash
|
||||
Main: b,
|
||||
Files: []string{
|
||||
@@ -363,6 +366,7 @@ func inputCode(s string, fs engine.Fs) (*ParsedInput, error) {
|
||||
}
|
||||
|
||||
return &ParsedInput{
|
||||
FS: fs,
|
||||
Base: dirify(wd),
|
||||
Main: b,
|
||||
Files: []string{}, // they're already copied in
|
||||
|
||||
@@ -374,8 +374,8 @@ func TestAstFunc1(t *testing.T) {
|
||||
|
||||
data := &interfaces.Data{
|
||||
// TODO: add missing fields here if/when needed
|
||||
Fs: fs,
|
||||
FsURI: fs.URI(), // TODO: is this right?
|
||||
Fs: output.FS, // formerly: fs
|
||||
FsURI: output.FS.URI(), // formerly: fs.URI() // TODO: is this right?
|
||||
Base: output.Base, // base dir (absolute path) the metadata file is in
|
||||
Files: output.Files, // no really needed here afaict
|
||||
Imports: importVertex,
|
||||
@@ -904,8 +904,8 @@ func TestAstFunc2(t *testing.T) {
|
||||
|
||||
data := &interfaces.Data{
|
||||
// TODO: add missing fields here if/when needed
|
||||
Fs: fs,
|
||||
FsURI: "memmapfs:///", // we're in standalone mode
|
||||
Fs: output.FS, // formerly: fs
|
||||
FsURI: output.FS.URI(),
|
||||
Base: output.Base, // base dir (absolute path) the metadata file is in
|
||||
Files: output.Files, // no really needed here afaict
|
||||
Imports: importVertex,
|
||||
@@ -1706,8 +1706,8 @@ func TestAstFunc3(t *testing.T) {
|
||||
|
||||
data := &interfaces.Data{
|
||||
// TODO: add missing fields here if/when needed
|
||||
Fs: fs,
|
||||
FsURI: "memmapfs:///", // we're in standalone mode
|
||||
Fs: output.FS, // formerly: fs
|
||||
FsURI: output.FS.URI(),
|
||||
Base: output.Base, // base dir (absolute path) the metadata file is in
|
||||
Files: output.Files, // no really needed here afaict
|
||||
Imports: importVertex,
|
||||
|
||||
@@ -139,8 +139,8 @@ func (obj *Lang) Init() error {
|
||||
// init and validate the structure of the AST
|
||||
data := &interfaces.Data{
|
||||
// TODO: add missing fields here if/when needed
|
||||
Fs: obj.Fs,
|
||||
FsURI: obj.FsURI,
|
||||
Fs: output.FS, // formerly: obj.Fs
|
||||
FsURI: output.FS.URI(), // formerly: obj.FsURI
|
||||
Base: output.Base, // base dir (absolute path) the metadata file is in
|
||||
Files: output.Files,
|
||||
Imports: importVertex,
|
||||
|
||||
Reference in New Issue
Block a user