Add option to specify module search paths manually

This commit is contained in:
Sasha Koshka 2024-03-27 13:13:22 -04:00
parent 2caed5b4ae
commit 76615df4d4
2 changed files with 12 additions and 4 deletions

View File

@ -47,6 +47,13 @@ func main () {
'O', "optimization",
"Optimization level (0-3)", "0",
cli.NewValSet("0", "1", "2", "3"))
includePath := cli.NewInputFlag (
'u', "unit-directory",
"Extra directory(s) to search for units in", "",
cli.ValString)
includePath.Found = func (application *cli.Cli, value string) {
comp.Resolver.AddPathFront(value)
}
application := cli.New (
"Compile FSPL source files",
@ -55,7 +62,8 @@ func main () {
quiet,
filetype,
output,
optimization)
optimization,
includePath)
application.Syntax = "[OPTION]... ADDRESS"
application.ParseOrExit(os.Args)

View File

@ -48,7 +48,7 @@ func (resolver *Resolver) AddPathFront (path ...string) {
// - If the address starts with '/', it is treated as an absolute path from
// the fs root
// - Else, the address is searched for in the resolver's paths
func (resolver Resolver) Resolve (context string, address entity.Address) (string, error) {
func (resolver *Resolver) Resolve (context string, address entity.Address) (string, error) {
strAddr := string(address)
switch {
case strings.HasPrefix(strAddr, "."):
@ -71,7 +71,7 @@ func (resolver Resolver) Resolve (context string, address entity.Address) (strin
}
}
func (resolver Resolver) search (needle string) (string, error) {
func (resolver *Resolver) search (needle string) (string, error) {
for _, dirPath := range resolver.Path {
// attempt to open the file as dir.
// if we can't open the dir, just skip it, because it is
@ -98,7 +98,7 @@ func (resolver Resolver) search (needle string) (string, error) {
// ResolveCwd resolves the address within the context of the current working
// directory.
func (resolver Resolver) ResolveCwd (address entity.Address) (string, error) {
func (resolver *Resolver) ResolveCwd (address entity.Address) (string, error) {
wd, err := os.Getwd()
if err != nil { return "", err }
return resolver.Resolve(wd, address)