added config files argument

This commit is contained in:
Rob1103 2023-01-02 15:58:29 +01:00
parent 816d1958ad
commit 53aeeba760
4 changed files with 44 additions and 8 deletions

View file

@ -7,9 +7,10 @@
package buildtool
import (
"github.com/akamensky/argparse"
"os"
u "tools/srcs/common"
"github.com/akamensky/argparse"
)
const (
@ -18,6 +19,7 @@ const (
sourcesArg = "sources"
objsArg = "objects"
makefileArg = "makefile"
configArg = "config"
)
// ParseArguments parses arguments of the application.
@ -34,11 +36,13 @@ func parseLocalArguments(p *argparse.Parser, args *u.Arguments) error {
&argparse.Options{Required: true, Help: "App Sources " +
"Folder"})
args.InitArgParse(p, args, u.BOOL, "o", objsArg,
&argparse.Options{Required: false, Default: false, Help: "Add objects from external build system " +
"Folder"})
&argparse.Options{Required: false, Default: false, Help: "Add objects from external" +
"build system Folder"})
args.InitArgParse(p, args, u.STRING, "m", makefileArg,
&argparse.Options{Required: false, Help: "Add additional properties " +
"for Makefile"})
args.InitArgParse(p, args, u.STRINGLIST, "c", configArg,
&argparse.Options{Required: false, Help: "Add configuration files"})
return u.ParserWrapper(p, os.Args)
}

View file

@ -123,6 +123,8 @@ func RunBuildTool(homeDir string, data *u.Data) {
u.PrintErr(err)
}
fmt.Println(args)
fmt.Println(*args.StringListArg[configArg])
// Get program Name
programName := *args.StringArg[programArg]
@ -213,11 +215,33 @@ func RunBuildTool(homeDir string, data *u.Data) {
panic(err)
}
// Move config files to Unikraft folder
configArg := *args.StringListArg[configArg]
for _, configFilePath := range configArg {
pathSplit := strings.Split(configFilePath, "/")
file := pathSplit[len(pathSplit)-1]
fileSplit := strings.Split(file, ".")
ext := fileSplit[len(fileSplit)-1]
if ext == "h" || ext == "hpp" || ext == "hcc" {
if err = u.CopyFileContents(configFilePath, *includeFolder+file); err != nil {
u.PrintErr(err)
}
} else if ext == "c" || ext == "cpp" || ext == "cc" {
if err = u.CopyFileContents(configFilePath, appFolder+file); err != nil {
u.PrintErr(err)
}
} else {
u.PrintWarning("Unsupported extension for file: " + file)
}
}
// Match micro-libs
matchedLibs, externalLibs, err := matchLibs(unikraftPath+"lib"+u.SEP, data)
if err != nil {
u.PrintErr(err)
}
fmt.Println("\nPREFINAL\n")
fmt.Println(matchedLibs)
// Clone the external git repositories
@ -232,6 +256,7 @@ func RunBuildTool(homeDir string, data *u.Data) {
for _, lib := range matchedLibs {
u.PrintOk("Match lib: " + lib)
}
fmt.Println("\nFINAL\n")
fmt.Println(matchedLibs)
// Clone the external git repositories (if changed)

View file

@ -195,7 +195,7 @@ func processSourceFiles(sourcesPath, appFolder, includeFolder string,
if err = u.CopyFileContents(path, appFolder+info.Name()); err != nil {
return err
}
} else if extension == ".h" {
} else if extension == ".h" || extension == ".hpp" || extension == ".hcc" {
// Add source files to includesFiles list
includesFiles = append(includesFiles, info.Name())

View file

@ -8,9 +8,10 @@ package common
import (
"errors"
"github.com/akamensky/argparse"
"os"
"strings"
"github.com/akamensky/argparse"
)
// Exported constants to determine arguments type.
@ -18,6 +19,7 @@ const (
INT = iota
BOOL
STRING
STRINGLIST
)
// Exported constants to determine which tool is used.
@ -41,6 +43,7 @@ type Arguments struct {
IntArg map[string]*int
BoolArg map[string]*bool
StringArg map[string]*string
StringListArg map[string]*[]string
}
// InitArguments allows to initialize the parser in order to parse given
@ -52,6 +55,7 @@ func (args *Arguments) InitArguments(name, description string) (*argparse.Parser
args.IntArg = make(map[string]*int)
args.BoolArg = make(map[string]*bool)
args.StringArg = make(map[string]*string)
args.StringListArg = make(map[string]*[]string)
p := argparse.NewParser(name, description)
@ -130,5 +134,8 @@ func (*Arguments) InitArgParse(p *argparse.Parser, args *Arguments, typeVar int,
case STRING:
args.StringArg[long] = new(string)
args.StringArg[long] = p.String(short, long, options)
case STRINGLIST:
args.StringListArg[long] = new([]string)
args.StringListArg[long] = p.StringList(short, long, options)
}
}