From 53aeeba760a2976a05a460da0114f6acbca8590f Mon Sep 17 00:00:00 2001 From: Rob1103 Date: Mon, 2 Jan 2023 15:58:29 +0100 Subject: [PATCH] added config files argument --- srcs/buildtool/args.go | 10 +++++++--- srcs/buildtool/run_buildtool.go | 25 ++++++++++++++++++++++++ srcs/buildtool/unikraft_files_process.go | 2 +- srcs/common/arguments.go | 15 ++++++++++---- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/srcs/buildtool/args.go b/srcs/buildtool/args.go index 52c665c..80e77df 100644 --- a/srcs/buildtool/args.go +++ b/srcs/buildtool/args.go @@ -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) } diff --git a/srcs/buildtool/run_buildtool.go b/srcs/buildtool/run_buildtool.go index 035bd95..8bfc63f 100644 --- a/srcs/buildtool/run_buildtool.go +++ b/srcs/buildtool/run_buildtool.go @@ -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) diff --git a/srcs/buildtool/unikraft_files_process.go b/srcs/buildtool/unikraft_files_process.go index 28aa3ef..034260b 100644 --- a/srcs/buildtool/unikraft_files_process.go +++ b/srcs/buildtool/unikraft_files_process.go @@ -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()) diff --git a/srcs/common/arguments.go b/srcs/common/arguments.go index 38e171e..5a9fd84 100644 --- a/srcs/common/arguments.go +++ b/srcs/common/arguments.go @@ -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. @@ -38,9 +40,10 @@ const ( // Exported constants to represent different types of arguments. type Arguments struct { - IntArg map[string]*int - BoolArg map[string]*bool - StringArg map[string]*string + 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) } }