diff --git a/srcs/buildtool/run_buildtool.go b/srcs/buildtool/run_buildtool.go index d1d2d39..d27f292 100644 --- a/srcs/buildtool/run_buildtool.go +++ b/srcs/buildtool/run_buildtool.go @@ -126,7 +126,9 @@ func addConfigFiles(configFiles []string, selectedFiles *[]string, includeFolder // Add Makefile.uk entry *selectedFiles = append(*selectedFiles, configFile) } else { - u.PrintWarning("Unsupported extension for file: " + configFile) + if err := u.CopyFileContents(configFilePath, appFolder+configFile); err != nil { + u.PrintErr(err) + } } } } @@ -261,7 +263,6 @@ func RunBuildTool(homeDir string, data *u.Data) { // Match micro-libs matchedLibs, externalLibs, err := matchLibs(unikraftPath+"lib"+u.SEP, data) - if err != nil { u.PrintErr(err) } @@ -271,7 +272,6 @@ func RunBuildTool(homeDir string, data *u.Data) { // Match internal dependencies between micro-libs if err := searchInternalDependencies(workspacePath, &matchedLibs, - externalLibs); err != nil { u.PrintErr(err) } @@ -285,7 +285,6 @@ func RunBuildTool(homeDir string, data *u.Data) { // Generate Makefiles if err := generateMake(programName, appFolder, workspacePath, *args.StringArg[makefileArg], - matchedLibs, selectedFiles, externalLibs); err != nil { u.PrintErr(err) } @@ -337,7 +336,6 @@ func searchInternalDependencies(unikraftPath string, matchedLibs *[]string, // Process Config.UK file mapConfig := make(map[string][]string) u.ProcessConfigUK(lines, true, mapConfig, nil) - for config := range mapConfig { // Remove LIB prefix diff --git a/srcs/buildtool/unikraft_files_process.go b/srcs/buildtool/unikraft_files_process.go index 1bb31de..35be7f1 100644 --- a/srcs/buildtool/unikraft_files_process.go +++ b/srcs/buildtool/unikraft_files_process.go @@ -196,7 +196,6 @@ func addAndApplyPatchFiles(patchPath string, patchFolder, appFolder string) erro // Copy and conform patch files err := filepath.Walk(patchPath, func(filePath string, info os.FileInfo, err error) error { - if !info.IsDir() { extension := filepath.Ext(info.Name()) if extension == ".patch" { @@ -219,7 +218,6 @@ func addAndApplyPatchFiles(patchPath string, patchFolder, appFolder string) erro // Apply patches err = filepath.Walk(patchPath, func(filePath string, info os.FileInfo, err error) error { - if !info.IsDir() { _, _, _ = u.ExecuteRunCmd("git", appFolder, true, "am", patchFolder+info.Name()) } @@ -315,7 +313,6 @@ func conformIncludeDirectives(sourcePath string) error { err := filepath.Walk(sourcePath, func(path string, info os.FileInfo, err error) error { - if !info.IsDir() { extension := filepath.Ext(info.Name()) if extension == ".h" || extension == ".hpp" || extension == ".hcc" { @@ -332,7 +329,6 @@ func conformIncludeDirectives(sourcePath string) error { } return nil }) - if err != nil { return err } @@ -387,7 +383,6 @@ func processSourceFiles(sourcesPath, appFolder, includeFolder string, err := filepath.Walk(sourcesPath, func(path string, info os.FileInfo, err error) error { - if !info.IsDir() { extension := filepath.Ext(info.Name()) if _, ok := srcLanguages[extension]; ok { @@ -413,10 +408,8 @@ func processSourceFiles(sourcesPath, appFolder, includeFolder string, u.PrintWarning("Unsupported extension for file: " + info.Name()) } } - return nil }) - if err != nil { return nil, err } diff --git a/srcs/dependtool/interdependence_graph.go b/srcs/dependtool/interdependence_graph.go index e9fed66..943388b 100644 --- a/srcs/dependtool/interdependence_graph.go +++ b/srcs/dependtool/interdependence_graph.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "strconv" "strings" u "tools/srcs/common" @@ -13,25 +14,6 @@ import ( // ---------------------------------Gather Data--------------------------------- -// getProgramFolder gets the folder path in which the given program is located, according to the -// Unikraft standard (e.g., /home/.../apps/programFolder/.../program). -// -// It returns the folder containing the program files according to the standard described above. -func getProgramFolder(programPath string) string { - - tmp := strings.Split(programPath, u.SEP) - i := 2 - - for ; i < len(tmp); i++ { - if tmp[len(tmp)-i] == "apps" { - break - } - } - - folderPath := strings.Join(tmp[:len(tmp)-i+2], u.SEP) - return folderPath -} - // sourceFileIncludesAnalysis collects all the include directives from a C/C++ source file. // // It returns a slice containing the found header names. @@ -44,14 +26,18 @@ func sourceFileIncludesAnalysis(sourceFile string) []string { u.PrintErr(err) } - for _, line := range fileLines { - if strings.Contains(line, "#include") { - line = strings.ReplaceAll(line, " ", "") - line = strings.Split(line, "#include")[1] - if strings.HasPrefix(line, "\"") { - fileIncludes = append(fileIncludes, line[1:strings.Index(line[1:], "\"")+1]) - } else if strings.HasPrefix(line, "<") { - fileIncludes = append(fileIncludes, line[1:strings.Index(line[1:], ">")+1]) + // Find user-defined include directives using regexp + var re = regexp.MustCompile(`(.*)(#include)(.*)("|<)(.*)("|>)(.*)`) + + for lineIndex := range fileLines { + for _, match := range re.FindAllStringSubmatch(fileLines[lineIndex], -1) { + + // Find the last element of the path and append it to the list of found header names + for i := 1; i < len(match); i++ { + if match[i] == "\"" || match[i] == "<" { + fileIncludes = append(fileIncludes, filepath.Base(match[i+1])) + break + } } } } @@ -91,7 +77,7 @@ func gccSourceFileIncludesAnalysis(sourceFile, outAppFolder string) ([]string, e // Only interested in headers not coming from the standard library if strings.Contains(line, "\""+outAppFolder) { line = strings.Split(line, "\""+outAppFolder)[1] - includeDirective := line[0:strings.Index(line[0:], "\"")] + includeDirective := filepath.Base(line[0:strings.Index(line[0:], "\"")]) if !u.Contains(fileIncludes, includeDirective) { fileIncludes = append(fileIncludes, includeDirective) } @@ -208,15 +194,12 @@ func requestUnikraftExtLibs() []string { func interdependAnalyser(programPath, programName, outFolder string) string { // Find all program source files - sourceFiles, err := findSourcesFiles(getProgramFolder(programPath)) + sourceFiles, err := findSourcesFiles(programPath) if err != nil { u.PrintErr(err) } // Create a folder and copy all source files into it for use with the gcc preprocessor - //tmp := strings.Split(getProgramFolder(programPath), u.SEP) - //outAppFolder := strings.Join(tmp[:len(tmp)-1], u.SEP) + u.SEP + programName + - //"_deptool_output" + u.SEP outAppFolder := outFolder + programName + u.SEP _, err = u.CreateFolder(outAppFolder) if err != nil { diff --git a/srcs/dependtool/run_deptool.go b/srcs/dependtool/run_deptool.go index 79eb01d..2683cd6 100644 --- a/srcs/dependtool/run_deptool.go +++ b/srcs/dependtool/run_deptool.go @@ -11,6 +11,25 @@ import ( "github.com/fatih/color" ) +// getProgramFolder gets the folder path in which the given program is located, according to the +// Unikraft standard (e.g., /home/.../apps/programFolder/.../program). +// +// It returns the folder containing the program files according to the standard described above. +func getProgramFolder(programPath string) string { + + tmp := strings.Split(programPath, u.SEP) + i := 2 + + for ; i < len(tmp); i++ { + if tmp[len(tmp)-i] == "apps" { + break + } + } + + folderPath := strings.Join(tmp[:len(tmp)-i+2], u.SEP) + return folderPath +} + // RunAnalyserTool allows to run the dependency analyser tool. func RunAnalyserTool(homeDir string, data *u.Data) { @@ -88,7 +107,7 @@ func RunAnalyserTool(homeDir string, data *u.Data) { // Run interdependence analyser if typeAnalysis == 0 || typeAnalysis == 3 { u.PrintHeader1("(1.3) RUN INTERDEPENDENCE ANALYSIS") - _ = runInterdependAnalyser(programPath, programName, outFolder) + _ = runInterdependAnalyser(getProgramFolder(programPath), programName, outFolder) } // Run sources analyser @@ -260,89 +279,3 @@ func runInterdependAnalyser(programPath, programName, outFolder string) string { return interdependAnalyser(programPath, programName, outFolder) } - -/* -// /!\ MISSING "/" !!! -stringFile := "#include\n/* #include ta mère *\nint main() {\n\t// Salut bitch !\n\treturn 0;\n}" - -for { - comStartIndex := strings.Index(stringFile, "/*") - if comStartIndex != -1 { - comEndIndex := strings.Index(stringFile, "*") - stringFile = strings.Join([]string{stringFile[:comStartIndex], - stringFile[comEndIndex+2:]}, "") - } else { - break - } -} -//what to do with "\t" in lines ? -var finalFile []string -sliceFile := strings.Split(stringFile, "\n") -for i := 0; i < len(sliceFile); i++ { - if !strings.HasPrefix(sliceFile[i], "//") { - finalFile = append(finalFile, sliceFile[i]) - } -} -} - - -// Remove dependencies whose files are not in program directory (e.g., stdio, stdlib, ...) - for internalFile, dependencies := range interdependMap { - var internalDep []string - for _, dependency := range dependencies { - if _, ok := interdependMap[dependency]; ok { - a++ - internalDep = append(internalDep, dependency) - } - } - interdependMap[internalFile] = internalDep - } - - -// Detect and print removable program source files (i.e., files that no other file depends - // on) - var removableFiles []string - for internalFile := range interdependMap { - depends := false - for _, dependencies := range interdependMap { - for _, dependency := range dependencies { - if internalFile == dependency { - depends = true - break - } - } - if depends { - break - } - } - - if !depends { - removableFiles = append(removableFiles, internalFile) - } - } - fmt.Println("Removable program source files of ", programName, ":") - fmt.Println(removableFiles) - - -func isADependency(internalFile string, interdependMap* map[string][]string) bool { - for _, dependencies := range *interdependMap { - for _, dependency := range dependencies { - if internalFile == dependency { - return true - } - } - } - return false -} - - -mymap := make(map[string][]string) - mymap["file_win32"] = make([]string, 0) - mymap["file_1"] = []string{"file_win32"} - mymap["file_2"] = []string{"file_1"} - mymap["file_3"] = make([]string, 0) - mymap["file_4"] = []string{"file_3"} - mymap["file_openssl"] = []string{"file_3"} - mymap["file_5"] = []string{"file_openssl"} - mymap["file_6"] = []string{"file_5"} -*/