small corrections

This commit is contained in:
Rob1103 2023-05-17 21:48:04 +02:00
parent bac05d60b8
commit de071b8c0c
4 changed files with 38 additions and 131 deletions

View file

@ -126,7 +126,9 @@ func addConfigFiles(configFiles []string, selectedFiles *[]string, includeFolder
// Add Makefile.uk entry // Add Makefile.uk entry
*selectedFiles = append(*selectedFiles, configFile) *selectedFiles = append(*selectedFiles, configFile)
} else { } 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 // Match micro-libs
matchedLibs, externalLibs, err := matchLibs(unikraftPath+"lib"+u.SEP, data) matchedLibs, externalLibs, err := matchLibs(unikraftPath+"lib"+u.SEP, data)
if err != nil { if err != nil {
u.PrintErr(err) u.PrintErr(err)
} }
@ -271,7 +272,6 @@ func RunBuildTool(homeDir string, data *u.Data) {
// Match internal dependencies between micro-libs // Match internal dependencies between micro-libs
if err := searchInternalDependencies(workspacePath, &matchedLibs, if err := searchInternalDependencies(workspacePath, &matchedLibs,
externalLibs); err != nil { externalLibs); err != nil {
u.PrintErr(err) u.PrintErr(err)
} }
@ -285,7 +285,6 @@ func RunBuildTool(homeDir string, data *u.Data) {
// Generate Makefiles // Generate Makefiles
if err := generateMake(programName, appFolder, workspacePath, *args.StringArg[makefileArg], if err := generateMake(programName, appFolder, workspacePath, *args.StringArg[makefileArg],
matchedLibs, selectedFiles, externalLibs); err != nil { matchedLibs, selectedFiles, externalLibs); err != nil {
u.PrintErr(err) u.PrintErr(err)
} }
@ -337,7 +336,6 @@ func searchInternalDependencies(unikraftPath string, matchedLibs *[]string,
// Process Config.UK file // Process Config.UK file
mapConfig := make(map[string][]string) mapConfig := make(map[string][]string)
u.ProcessConfigUK(lines, true, mapConfig, nil) u.ProcessConfigUK(lines, true, mapConfig, nil)
for config := range mapConfig { for config := range mapConfig {
// Remove LIB prefix // Remove LIB prefix

View file

@ -196,7 +196,6 @@ func addAndApplyPatchFiles(patchPath string, patchFolder, appFolder string) erro
// Copy and conform patch files // Copy and conform patch files
err := filepath.Walk(patchPath, func(filePath string, info os.FileInfo, err := filepath.Walk(patchPath, func(filePath string, info os.FileInfo,
err error) error { err error) error {
if !info.IsDir() { if !info.IsDir() {
extension := filepath.Ext(info.Name()) extension := filepath.Ext(info.Name())
if extension == ".patch" { if extension == ".patch" {
@ -219,7 +218,6 @@ func addAndApplyPatchFiles(patchPath string, patchFolder, appFolder string) erro
// Apply patches // Apply patches
err = filepath.Walk(patchPath, func(filePath string, info os.FileInfo, err = filepath.Walk(patchPath, func(filePath string, info os.FileInfo,
err error) error { err error) error {
if !info.IsDir() { if !info.IsDir() {
_, _, _ = u.ExecuteRunCmd("git", appFolder, true, "am", patchFolder+info.Name()) _, _, _ = 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 := filepath.Walk(sourcePath, func(path string, info os.FileInfo,
err error) error { err error) error {
if !info.IsDir() { if !info.IsDir() {
extension := filepath.Ext(info.Name()) extension := filepath.Ext(info.Name())
if extension == ".h" || extension == ".hpp" || extension == ".hcc" { if extension == ".h" || extension == ".hpp" || extension == ".hcc" {
@ -332,7 +329,6 @@ func conformIncludeDirectives(sourcePath string) error {
} }
return nil return nil
}) })
if err != nil { if err != nil {
return err return err
} }
@ -387,7 +383,6 @@ func processSourceFiles(sourcesPath, appFolder, includeFolder string,
err := filepath.Walk(sourcesPath, func(path string, info os.FileInfo, err := filepath.Walk(sourcesPath, func(path string, info os.FileInfo,
err error) error { err error) error {
if !info.IsDir() { if !info.IsDir() {
extension := filepath.Ext(info.Name()) extension := filepath.Ext(info.Name())
if _, ok := srcLanguages[extension]; ok { if _, ok := srcLanguages[extension]; ok {
@ -413,10 +408,8 @@ func processSourceFiles(sourcesPath, appFolder, includeFolder string,
u.PrintWarning("Unsupported extension for file: " + info.Name()) u.PrintWarning("Unsupported extension for file: " + info.Name())
} }
} }
return nil return nil
}) })
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -6,6 +6,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp"
"strconv" "strconv"
"strings" "strings"
u "tools/srcs/common" u "tools/srcs/common"
@ -13,25 +14,6 @@ import (
// ---------------------------------Gather Data--------------------------------- // ---------------------------------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. // sourceFileIncludesAnalysis collects all the include directives from a C/C++ source file.
// //
// It returns a slice containing the found header names. // It returns a slice containing the found header names.
@ -44,14 +26,18 @@ func sourceFileIncludesAnalysis(sourceFile string) []string {
u.PrintErr(err) u.PrintErr(err)
} }
for _, line := range fileLines { // Find user-defined include directives using regexp
if strings.Contains(line, "#include") { var re = regexp.MustCompile(`(.*)(#include)(.*)("|<)(.*)("|>)(.*)`)
line = strings.ReplaceAll(line, " ", "")
line = strings.Split(line, "#include")[1] for lineIndex := range fileLines {
if strings.HasPrefix(line, "\"") { for _, match := range re.FindAllStringSubmatch(fileLines[lineIndex], -1) {
fileIncludes = append(fileIncludes, line[1:strings.Index(line[1:], "\"")+1])
} else if strings.HasPrefix(line, "<") { // Find the last element of the path and append it to the list of found header names
fileIncludes = append(fileIncludes, line[1:strings.Index(line[1:], ">")+1]) 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 // Only interested in headers not coming from the standard library
if strings.Contains(line, "\""+outAppFolder) { if strings.Contains(line, "\""+outAppFolder) {
line = strings.Split(line, "\""+outAppFolder)[1] 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) { if !u.Contains(fileIncludes, includeDirective) {
fileIncludes = append(fileIncludes, includeDirective) fileIncludes = append(fileIncludes, includeDirective)
} }
@ -208,15 +194,12 @@ func requestUnikraftExtLibs() []string {
func interdependAnalyser(programPath, programName, outFolder string) string { func interdependAnalyser(programPath, programName, outFolder string) string {
// Find all program source files // Find all program source files
sourceFiles, err := findSourcesFiles(getProgramFolder(programPath)) sourceFiles, err := findSourcesFiles(programPath)
if err != nil { if err != nil {
u.PrintErr(err) u.PrintErr(err)
} }
// Create a folder and copy all source files into it for use with the gcc preprocessor // 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 outAppFolder := outFolder + programName + u.SEP
_, err = u.CreateFolder(outAppFolder) _, err = u.CreateFolder(outAppFolder)
if err != nil { if err != nil {

View file

@ -11,6 +11,25 @@ import (
"github.com/fatih/color" "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. // RunAnalyserTool allows to run the dependency analyser tool.
func RunAnalyserTool(homeDir string, data *u.Data) { func RunAnalyserTool(homeDir string, data *u.Data) {
@ -88,7 +107,7 @@ func RunAnalyserTool(homeDir string, data *u.Data) {
// Run interdependence analyser // Run interdependence analyser
if typeAnalysis == 0 || typeAnalysis == 3 { if typeAnalysis == 0 || typeAnalysis == 3 {
u.PrintHeader1("(1.3) RUN INTERDEPENDENCE ANALYSIS") u.PrintHeader1("(1.3) RUN INTERDEPENDENCE ANALYSIS")
_ = runInterdependAnalyser(programPath, programName, outFolder) _ = runInterdependAnalyser(getProgramFolder(programPath), programName, outFolder)
} }
// Run sources analyser // Run sources analyser
@ -260,89 +279,3 @@ func runInterdependAnalyser(programPath, programName, outFolder string) string {
return interdependAnalyser(programPath, programName, outFolder) return interdependAnalyser(programPath, programName, outFolder)
} }
/*
// /!\ MISSING "/" !!!
stringFile := "#include<stdlib.h>\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"}
*/