From 3ea1db0849e4274ee281b572ee3e5187e14957ed Mon Sep 17 00:00:00 2001 From: "Ian A. Mason" Date: Tue, 17 Apr 2018 11:46:22 -0700 Subject: [PATCH] Better error reporting if things go pear shaped. --- ians-notes.txt | 2 +- shared/extractor.go | 37 +++++++++++++++++++++++++++---------- shared/logging.go | 13 +++++++++++++ 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/ians-notes.txt b/ians-notes.txt index 05c1a25..4a27757 100644 --- a/ians-notes.txt +++ b/ians-notes.txt @@ -4,7 +4,7 @@ To edit the code locally use the repository here: Then do: -go install -a github.com/SRI-CSL/gllvm/cmd/... +go install github.com/SRI-CSL/gllvm/cmd/... To format for the badge: diff --git a/shared/extractor.go b/shared/extractor.go index 4d88fc8..c4df9d4 100644 --- a/shared/extractor.go +++ b/shared/extractor.go @@ -191,6 +191,9 @@ func parseSwitches() (ea extractionArgs) { func handleExecutable(ea extractionArgs) { artifactPaths := ea.Extractor(ea.InputFile) + + LogInfo("handleExecutable: artifactPaths = %v\n", artifactPaths) + if len(artifactPaths) == 0 { return } @@ -211,6 +214,8 @@ func handleArchive(ea extractionArgs) { var bcFiles []string var artifactFiles []string + LogInfo("handleArchive: extractionArgs = %v\n", ea) + // Create tmp dir tmpDirName, err := ioutil.TempDir("", "gllvm") if err != nil { @@ -222,6 +227,9 @@ func handleArchive(ea extractionArgs) { arArgs := ea.ArArgs inputAbsPath, _ := filepath.Abs(ea.InputFile) arArgs = append(arArgs, inputAbsPath) + + LogInfo("handleArchive: executing ar %v %v\n", arArgs, tmpDirName) + success, err := execCmd("ar", arArgs, tmpDirName) if !success { LogFatal("Failed to extract object files from %s to %s because: %v.\n", ea.InputFile, tmpDirName, err) @@ -235,7 +243,9 @@ func handleArchive(ea extractionArgs) { artifactPaths := ea.Extractor(path) for _, artPath := range artifactPaths { bcPath := resolveBitcodePath(artPath) - bcFiles = append(bcFiles, bcPath) + if bcPath != "" { + bcFiles = append(bcFiles, bcPath) + } } artifactFiles = append(artifactFiles, artifactPaths...) } @@ -246,16 +256,22 @@ func handleArchive(ea extractionArgs) { // Handle object files filepath.Walk(tmpDirName, walkHandlingFunc) - // Build archive - if ea.BuildBitcodeArchive { - extractTimeLinkFiles(ea, bcFiles) - } else { - archiveBcFiles(ea, bcFiles) - } + LogDebug("handleArchive: walked %v\nartifactFiles:\n%v\nbcFiles:\n%v\n", tmpDirName, artifactFiles, bcFiles) - // Write manifest - if ea.WriteManifest { - writeManifest(ea, bcFiles, artifactFiles) + if len(bcFiles) > 0 { + // Build archive + if ea.BuildBitcodeArchive { + extractTimeLinkFiles(ea, bcFiles) + } else { + archiveBcFiles(ea, bcFiles) + } + + // Write manifest + if ea.WriteManifest { + writeManifest(ea, bcFiles, artifactFiles) + } + } else { + LogError("No bitcode files found\n") } } @@ -349,6 +365,7 @@ func resolveBitcodePath(bcPath string) string { } return storeBcPath } + LogWarning("Failed to find the file %v\n", bcPath) return "" } return bcPath diff --git a/shared/logging.go b/shared/logging.go index 77aead5..97cf658 100644 --- a/shared/logging.go +++ b/shared/logging.go @@ -54,6 +54,15 @@ var loggingLevels = map[string]int{ "DEBUG": debugV, } +var loggingPrefixes = map[int]string{ + errorV: "Error: ", + warningV: "Warning: ", + infoV: "Info: ", + debugV: "Debug: ", +} + + + //loggingLevel is the user configured level of logging: ERROR, WARNING, INFO, DEBUG var loggingLevel = errorV @@ -86,6 +95,10 @@ func makeLogger(lvl int) func(format string, a ...interface{}) { //and send output to both os.Stderr and loggingFilePointer. We wouldn't //want the user to miss any excitement. Then the sanity checker would not //need to futz with it. + prefix := loggingPrefixes[lvl] + if len(prefix) > 0 { + loggingFilePointer.WriteString(prefix) + } loggingFilePointer.WriteString(msg) } }