matchLibs and searchInternalDependencies fixed
This commit is contained in:
parent
d641975f97
commit
7f26ca5d3d
2 changed files with 93 additions and 29 deletions
|
@ -41,7 +41,6 @@ type MicroLibsFunction struct {
|
||||||
// -----------------------------Match micro-libs--------------------------------
|
// -----------------------------Match micro-libs--------------------------------
|
||||||
|
|
||||||
// processSymbols adds symbols within the 'exportsyms.uk' file into a map.
|
// processSymbols adds symbols within the 'exportsyms.uk' file into a map.
|
||||||
//
|
|
||||||
func processSymbols(microLib, output string, mapSymbols map[string][]string) {
|
func processSymbols(microLib, output string, mapSymbols map[string][]string) {
|
||||||
|
|
||||||
lines := strings.Split(output, "\n")
|
lines := strings.Split(output, "\n")
|
||||||
|
@ -134,6 +133,32 @@ func fetchSymbolsExternalLibs(folder string,
|
||||||
return externalLibs, nil
|
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
|
// matchSymbols performs the matching between Unikraft's micro-libs and
|
||||||
// libraries used by a given application based on the list of symbols that both
|
// libraries used by a given application based on the list of symbols that both
|
||||||
// contain.
|
// contain.
|
||||||
|
@ -144,13 +169,6 @@ func matchSymbols(matchedLibs []string, data map[string]string,
|
||||||
for key := range data {
|
for key := range data {
|
||||||
if values, ok := microLibs[key]; ok {
|
if values, ok := microLibs[key]; ok {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
|
|
||||||
// todo remove
|
|
||||||
if strings.Compare(NOLIBC, value) == 0 {
|
|
||||||
value = NEWLIB
|
|
||||||
}
|
|
||||||
// remove above
|
|
||||||
|
|
||||||
if !u.Contains(matchedLibs, value) {
|
if !u.Contains(matchedLibs, value) {
|
||||||
matchedLibs = append(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)
|
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")
|
folder := filepath.Join(os.Getenv("GOPATH"), "src", "tools", "libs", "internal")
|
||||||
if err := fetchSymbolsInternalLibs(folder, mapSymbols); err != nil {
|
if err := fetchSymbolsInternalLibs(folder, mapSymbols); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -189,11 +202,13 @@ func matchLibs(unikraftLibs string, data *u.Data) ([]string, map[string]string,
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the matching symbols on static data
|
dataMap := putJsonSymbolsTogether(data)
|
||||||
matchedLibs = matchSymbols(matchedLibs, data.StaticData.Symbols, mapSymbols)
|
//matchedLibs = append(matchedLibs, POSIXPROCESS)
|
||||||
|
//matchedLibs = append(matchedLibs, POSIXUSER)
|
||||||
// Perform the matching symbols on dynamic data
|
//matchedLibs = append(matchedLibs, POSIXSYSINFO)
|
||||||
matchedLibs = matchSymbols(matchedLibs, data.DynamicData.Symbols, mapSymbols)
|
//matchedLibs = append(matchedLibs, POSIXLIBDL)
|
||||||
|
// Perform the symbol matching
|
||||||
|
matchedLibs = matchSymbols(matchedLibs, dataMap, mapSymbols)
|
||||||
|
|
||||||
return matchedLibs, externalLibs, nil
|
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
|
// cloneLibsFolders clones all the needed micro-libs that are needed by a
|
||||||
// given application
|
// given application
|
||||||
//
|
|
||||||
func cloneLibsFolders(workspacePath string, matchedLibs []string,
|
func cloneLibsFolders(workspacePath string, matchedLibs []string,
|
||||||
externalLibs map[string]string) {
|
externalLibs map[string]string) {
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,15 @@
|
||||||
package buildtool
|
package buildtool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
u "tools/srcs/common"
|
u "tools/srcs/common"
|
||||||
|
|
||||||
|
"github.com/AlecAivazis/survey/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// STATES
|
// STATES
|
||||||
|
@ -51,7 +53,8 @@ func generateConfigUk(filename, programName string, matchedLibs []string) error
|
||||||
// execution of the 'make' command.
|
// execution of the 'make' command.
|
||||||
//
|
//
|
||||||
// It returns an integer that defines the result of 'make':
|
// 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 {
|
func checkMakeOutput(appFolder string, stderr *string) int {
|
||||||
|
|
||||||
if stderr == nil {
|
if stderr == nil {
|
||||||
|
@ -107,7 +110,6 @@ func parseMakeOutput(output string) string {
|
||||||
|
|
||||||
// RunBuildTool runs the automatic build tool to build a unikernel of a
|
// RunBuildTool runs the automatic build tool to build a unikernel of a
|
||||||
// given application.
|
// given application.
|
||||||
//
|
|
||||||
func RunBuildTool(homeDir string, data *u.Data) {
|
func RunBuildTool(homeDir string, data *u.Data) {
|
||||||
|
|
||||||
// Init and parse local arguments
|
// Init and parse local arguments
|
||||||
|
@ -216,7 +218,8 @@ func RunBuildTool(homeDir string, data *u.Data) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.PrintErr(err)
|
u.PrintErr(err)
|
||||||
}
|
}
|
||||||
|
fmt.Println("\nPREFINAL\n")
|
||||||
|
fmt.Println(matchedLibs)
|
||||||
// Clone the external git repositories
|
// Clone the external git repositories
|
||||||
cloneLibsFolders(workspacePath, matchedLibs, externalLibs)
|
cloneLibsFolders(workspacePath, matchedLibs, externalLibs)
|
||||||
|
|
||||||
|
@ -229,7 +232,8 @@ func RunBuildTool(homeDir string, data *u.Data) {
|
||||||
for _, lib := range matchedLibs {
|
for _, lib := range matchedLibs {
|
||||||
u.PrintOk("Match lib: " + lib)
|
u.PrintOk("Match lib: " + lib)
|
||||||
}
|
}
|
||||||
|
fmt.Println("\nFINAL\n")
|
||||||
|
fmt.Println(matchedLibs)
|
||||||
// Clone the external git repositories (if changed)
|
// Clone the external git repositories (if changed)
|
||||||
cloneLibsFolders(workspacePath, matchedLibs, externalLibs)
|
cloneLibsFolders(workspacePath, matchedLibs, externalLibs)
|
||||||
|
|
||||||
|
@ -274,11 +278,6 @@ func searchInternalDependencies(unikraftPath string, matchedLibs *[]string,
|
||||||
config = strings.TrimPrefix(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
|
// Check if matchedLibs already contains the lib
|
||||||
config = strings.ToLower(config)
|
config = strings.ToLower(config)
|
||||||
if !u.Contains(*matchedLibs, config) {
|
if !u.Contains(*matchedLibs, config) {
|
||||||
|
@ -291,6 +290,57 @@ func searchInternalDependencies(unikraftPath string, matchedLibs *[]string,
|
||||||
return nil
|
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,
|
func generateMake(programName, appFolder, workspacePath, makefile string,
|
||||||
matchedLibs, sourceFiles []string, externalLibs map[string]string) error {
|
matchedLibs, sourceFiles []string, externalLibs map[string]string) error {
|
||||||
// Generate Makefile
|
// Generate Makefile
|
||||||
|
|
Loading…
Add table
Reference in a new issue