Skip to content

Commit

Permalink
extractor: Add a "strict extraction" mode
Browse files Browse the repository at this point in the history
The more permissive current behavior remains the default.
  • Loading branch information
woodruffw committed Aug 4, 2020
1 parent 3389f1f commit c14c8e6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions shared/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type ExtractionArgs struct {
SortBitcodeFiles bool // sort the arguments to linking and archiving (debugging too)
BuildBitcodeModule bool // buld an archive rather than a module
KeepTemp bool // keep temporary linking folder
StrictExtract bool // turn extraction failures into errors
LinkArgSize int // maximum size of a llvm-link command line
InputType int
ObjectTypeInArchive int // Type of file that can be put into an archive
Expand Down Expand Up @@ -85,10 +86,11 @@ ea.OutputFile: %v
ea.LlvmArchiverName: %v
ea.LlvmLinkerName: %v
ea.ArchiverName: %v
ea.StrictExtract: %v
`
return fmt.Sprintf(format, ea.Verbose, ea.WriteManifest, ea.SortBitcodeFiles, ea.BuildBitcodeModule,
ea.KeepTemp, ea.LinkArgSize, ea.InputFile, ea.OutputFile, ea.LlvmArchiverName,
ea.LlvmLinkerName, ea.ArchiverName)
ea.LlvmLinkerName, ea.ArchiverName, ea.StrictExtract)
}

//ParseSwitches parses the command line into an ExtractionArgs object.
Expand All @@ -106,6 +108,7 @@ func ParseSwitches(args []string) (ea ExtractionArgs) {
flagSet.StringVar(&ea.LlvmLinkerName, "l", "llvm-link", "the llvm linker (i.e. llvm-link)")
flagSet.IntVar(&ea.LinkArgSize, "n", 0, "maximum llvm-link command line size (in bytes)")
flagSet.BoolVar(&ea.KeepTemp, "t", false, "keep temporary linking folder")
flagSet.BoolVar(&ea.StrictExtract, "S", false, "exit with an error if extraction fails")

err := flagSet.Parse(args[1:])

Expand Down Expand Up @@ -259,7 +262,7 @@ func handleExecutable(ea ExtractionArgs) (success bool) {
// get the list of bitcode paths
var artifactPaths []string
artifactPaths, success = ea.Extractor(ea.InputFile)
if !success {
if !success && ea.StrictExtract {
return
}

Expand Down Expand Up @@ -310,7 +313,7 @@ func handleThinArchive(ea ExtractionArgs) (success bool) {
if len(obj) > 0 {
var artifacts []string
artifacts, success = ea.Extractor(obj)
if !success {
if !success && ea.StrictExtract {
return
}
LogInfo("\t%v\n", artifacts)
Expand Down Expand Up @@ -466,7 +469,7 @@ func handleArchive(ea ExtractionArgs) (success bool) {
if obj != "" && extractFile(ea, inputFile, obj, i) {
var artifacts []string
artifacts, success = ea.Extractor(obj)
if !success {
if !success && ea.StrictExtract {
return
}
LogInfo("\t%v\n", artifacts)
Expand Down

0 comments on commit c14c8e6

Please sign in to comment.