Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnEstropia committed Mar 15, 2024
1 parent 9dcffa6 commit f8ef262
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions Sources/StorybookKit/Internals/machOLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,28 @@ extension Book {
guard !moduleName.isEmpty else {
return nil
}
let allImageNames: [String?] = (0..<_dyld_image_count()).map {
guard let pathC = _dyld_get_image_name($0) else {
return nil
}
let path = String(cString: pathC)
let imageName = path
.components(separatedBy: "/")
.last?
.components(separatedBy: ".")
.first
print(path)
return imageName
}
guard
let imageIndex = (0..<_dyld_image_count()).first(
where: {
guard let pathC = _dyld_get_image_name($0) else {
return false
}
let path = String(cString: pathC)
let imageName = path
.components(separatedBy: "/")
.last?
.components(separatedBy: ".")
.first
if imageName == moduleName {
print(path)
}
return imageName == moduleName
}
)
let imageIndex = allImageNames.firstIndex(of: moduleName)
else {
return nil
}

// Follows same approach here: https://github.com/apple/swift-testing/blob/main/Sources/TestingInternals/Discovery.cpp#L318
guard
let headerRawPtr: UnsafeRawPointer = _dyld_get_image_header(imageIndex)
let headerRawPtr: UnsafeRawPointer = _dyld_get_image_header(.init(imageIndex))
.map(UnsafeRawPointer.init(_:))
else {
return nil
Expand Down

0 comments on commit f8ef262

Please sign in to comment.