matchLibs and searchInternalDependencies fixed

This commit is contained in:
Rob1103 2022-10-25 18:39:36 +02:00
parent d641975f97
commit 7f26ca5d3d
2 changed files with 93 additions and 29 deletions

View file

@ -41,7 +41,6 @@ type MicroLibsFunction struct {
// -----------------------------Match micro-libs--------------------------------
// processSymbols adds symbols within the 'exportsyms.uk' file into a map.
//
func processSymbols(microLib, output string, mapSymbols map[string][]string) {
lines := strings.Split(output, "\n")
@ -134,6 +133,32 @@ func fetchSymbolsExternalLibs(folder string,
return externalLibs, nil
}
// putJsonSymbolsTogether puts the json file symbols and system calls resulting from the static and
// dynamic analyses together into a map structure.
//
// It returns the map containing all the symbols and system calls.
func putJsonSymbolsTogether(data *u.Data) map[string]string {
dataMap := make(map[string]string)
for k, v := range data.StaticData.Symbols {
dataMap[k] = v
}
for k := range data.StaticData.SystemCalls {
dataMap[k] = ""
}
for k, v := range data.DynamicData.Symbols {
dataMap[k] = v
}
for k := range data.DynamicData.SystemCalls {
dataMap[k] = ""
}
return dataMap
}
// matchSymbols performs the matching between Unikraft's micro-libs and
// libraries used by a given application based on the list of symbols that both
// contain.
@ -144,13 +169,6 @@ func matchSymbols(matchedLibs []string, data map[string]string,
for key := range data {
if values, ok := microLibs[key]; ok {
for _, value := range values {
// todo remove
if strings.Compare(NOLIBC, value) == 0 {
value = NEWLIB
}
// remove above
if !u.Contains(matchedLibs, value) {
matchedLibs = append(matchedLibs, value)
}
@ -172,11 +190,6 @@ func matchLibs(unikraftLibs string, data *u.Data) ([]string, map[string]string,
matchedLibs := make([]string, 0)
//todo remove
matchedLibs = append(matchedLibs, POSIXLIBDL)
matchedLibs = append(matchedLibs, POSIXSYSINFO)
matchedLibs = append(matchedLibs, UKMMAP)
folder := filepath.Join(os.Getenv("GOPATH"), "src", "tools", "libs", "internal")
if err := fetchSymbolsInternalLibs(folder, mapSymbols); err != nil {
return nil, nil, err
@ -189,11 +202,13 @@ func matchLibs(unikraftLibs string, data *u.Data) ([]string, map[string]string,
return nil, nil, err
}
// Perform the matching symbols on static data
matchedLibs = matchSymbols(matchedLibs, data.StaticData.Symbols, mapSymbols)
// Perform the matching symbols on dynamic data
matchedLibs = matchSymbols(matchedLibs, data.DynamicData.Symbols, mapSymbols)
dataMap := putJsonSymbolsTogether(data)
//matchedLibs = append(matchedLibs, POSIXPROCESS)
//matchedLibs = append(matchedLibs, POSIXUSER)
//matchedLibs = append(matchedLibs, POSIXSYSINFO)
//matchedLibs = append(matchedLibs, POSIXLIBDL)
// Perform the symbol matching
matchedLibs = matchSymbols(matchedLibs, dataMap, mapSymbols)
return matchedLibs, externalLibs, nil
}
@ -223,7 +238,6 @@ func cloneGitRepo(url, unikraftPathLibs, lib string) error {
// cloneLibsFolders clones all the needed micro-libs that are needed by a
// given application
//
func cloneLibsFolders(workspacePath string, matchedLibs []string,
externalLibs map[string]string) {

View file

@ -7,13 +7,15 @@
package buildtool
import (
"github.com/AlecAivazis/survey/v2"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
u "tools/srcs/common"
"github.com/AlecAivazis/survey/v2"
)
// STATES
@ -51,7 +53,8 @@ func generateConfigUk(filename, programName string, matchedLibs []string) error
// execution of the 'make' command.
//
// It returns an integer that defines the result of 'make':
// <SUCCESS, LINKING_ERROR, COMPILER_ERROR>
//
// <SUCCESS, LINKING_ERROR, COMPILER_ERROR>
func checkMakeOutput(appFolder string, stderr *string) int {
if stderr == nil {
@ -107,7 +110,6 @@ func parseMakeOutput(output string) string {
// RunBuildTool runs the automatic build tool to build a unikernel of a
// given application.
//
func RunBuildTool(homeDir string, data *u.Data) {
// Init and parse local arguments
@ -216,7 +218,8 @@ func RunBuildTool(homeDir string, data *u.Data) {
if err != nil {
u.PrintErr(err)
}
fmt.Println("\nPREFINAL\n")
fmt.Println(matchedLibs)
// Clone the external git repositories
cloneLibsFolders(workspacePath, matchedLibs, externalLibs)
@ -229,7 +232,8 @@ 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)
cloneLibsFolders(workspacePath, matchedLibs, externalLibs)
@ -274,11 +278,6 @@ func searchInternalDependencies(unikraftPath string, matchedLibs *[]string,
config = strings.TrimPrefix(config, "LIB")
}
// Replace underscore by dash
if strings.Contains(config, "_") {
config = strings.ReplaceAll(config, "_", "-")
}
// Check if matchedLibs already contains the lib
config = strings.ToLower(config)
if !u.Contains(*matchedLibs, config) {
@ -291,6 +290,57 @@ func searchInternalDependencies(unikraftPath string, matchedLibs *[]string,
return nil
}
/* // This version considers also internal lib dependencies
func searchInternalDependencies(unikraftPath string, matchedLibs *[]string,
externalLibs map[string]string) error {
for _, lib := range *matchedLibs {
if strings.Contains(lib, "_") {
lib = strings.ReplaceAll(lib, "_", "-")
}
// Get and read Config.UK from lib
var configUk string
if _, ok := externalLibs[lib]; ok {
configUk = unikraftPath + u.LIBSFOLDER + lib + u.SEP + "Config.uk"
} else {
configUk = unikraftPath + u.UNIKRAFTFOLDER + "lib" + u.SEP + lib + u.SEP + "Config.uk"
}
lines, err := u.ReadLinesFile(configUk)
if err != nil {
return err
}
// Process Config.UK file
mapConfig := make(map[string][]string)
u.ProcessConfigUK(lines, true, mapConfig, nil)
for config := range mapConfig {
// Remove LIB prefix
if strings.Contains(config, "LIB") {
config = strings.TrimPrefix(config, "LIB")
}
// Replace underscore by dash
//if strings.Contains(config, "_") {
// config = strings.ReplaceAll(config, "_", "-")
//}
// Check if matchedLibs already contains the lib
config = strings.ToLower(config)
if !u.Contains(*matchedLibs, config) {
*matchedLibs = append(*matchedLibs, config)
}
}
}
return nil
}
*/
func generateMake(programName, appFolder, workspacePath, makefile string,
matchedLibs, sourceFiles []string, externalLibs map[string]string) error {
// Generate Makefile