Skip to content

Commit 53389ca

Browse files
authored
fix: correct parameter name in error log when split fails to open a… (#948)
* fix: correct parameter name in error log when `split` fails to open a library handle * improve error reporting a bit * pulls the error up from GetHandle() into Split() where more context exists * tells the user only to use the --xcode parameter if they haven't done so * differentiates between a missing path and a failure to dlopen()
1 parent cd8e465 commit 53389ca

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

pkg/dyld/split.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type XCodeAppInfoPlist struct {
6060
}
6161

6262
// GetHandle returns a handle to a library
63-
func GetHandle(libs []string) (*LibHandle, error) {
63+
func GetHandle(libs []string) *LibHandle {
6464
for _, name := range libs {
6565
libname := C.CString(name)
6666
defer C.free(unsafe.Pointer(libname))
@@ -71,10 +71,10 @@ func GetHandle(libs []string) (*LibHandle, error) {
7171
Handle: handle,
7272
Libname: name,
7373
}
74-
return h, nil
74+
return h
7575
}
7676
}
77-
return nil, fmt.Errorf("unable to open a handle to the Xcode library (use --xcode-path to specify the path to Xcode)")
77+
return nil
7878
}
7979

8080
// GetSymbolPointer takes a symbol name and returns a pointer to the symbol.
@@ -107,22 +107,40 @@ func (l *LibHandle) Close() error {
107107
// Split extracts all the dyld_shared_cache libraries
108108
func Split(dyldSharedCachePath, destinationPath, xcodePath string, xcodeCache bool) error {
109109
var xcodeVersion string
110+
var xcodePathProvided bool
110111

111112
if len(xcodePath) == 0 {
112113
var err error
113114
xcodePath, err = utils.GetXCodePath()
114115
if err != nil {
115116
return fmt.Errorf("failed to get Xcode path: %v", err)
116117
}
118+
xcodePathProvided = false
117119
} else {
118120
if !strings.HasSuffix(xcodePath, "Contents/Developer") {
119121
xcodePath = filepath.Join(xcodePath, "Contents/Developer")
120122
}
123+
xcodePathProvided = true
121124
}
122125

123-
dscExtractor, err := GetHandle([]string{filepath.Join(xcodePath, "Platforms/iPhoneOS.platform/usr/lib/dsc_extractor.bundle")})
126+
dscExtractorPath := filepath.Join(xcodePath, "Platforms/iPhoneOS.platform/usr/lib/dsc_extractor.bundle")
127+
_, err := os.Stat(dscExtractorPath)
124128
if err != nil {
125-
return fmt.Errorf("failed to split %s: %v", dyldSharedCachePath, err)
129+
err_msg := "failed to find DSC extractor library in %s"
130+
if !xcodePathProvided {
131+
err_msg += " (use --xcode to specify the path to Xcode)"
132+
}
133+
return fmt.Errorf(err_msg, dscExtractorPath)
134+
}
135+
136+
dscExtractor := GetHandle([]string{dscExtractorPath})
137+
if dscExtractor == nil {
138+
err_msg := "unable to open a handle to the DSC extractor library in %s"
139+
if !xcodePathProvided {
140+
err_msg += " (use --xcode to specify the path to Xcode)"
141+
}
142+
143+
return fmt.Errorf(err_msg, dyldSharedCachePath, dscExtractorPath)
126144
}
127145

128146
if xcodeCache {

0 commit comments

Comments
 (0)