Skip to content

Commit

Permalink
Fix injecting tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnno1962 committed Dec 20, 2020
1 parent 8a39ac5 commit 73fae23
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
20 changes: 19 additions & 1 deletion InjectionBundle/SwiftEval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by John Holdsworth on 02/11/2017.
// Copyright © 2017 John Holdsworth. All rights reserved.
//
// $Id: //depot/ResidentEval/InjectionBundle/SwiftEval.swift#158 $
// $Id: //depot/ResidentEval/InjectionBundle/SwiftEval.swift#160 $
//
// Basic implementation of a Swift "eval()" including the
// mechanics of recompiling a class and loading the new
Expand Down Expand Up @@ -451,8 +451,26 @@ public class SwiftEval: NSObject {
return tmpfile
}

lazy var loadXCTest: () = {
#if os(macOS)
let sdk = "MacOSX"
#elseif os(tvOS)
let sdk = "AppleTVSimulator"
#elseif targetEnvironment(simulator)
let sdk = "iPhoneSimulator"
#else
let sdk = "iPhoneOS"
#endif

if dlopen("\(xcodeDev)/Platforms/\(sdk).platform/Developer/Library/Frameworks/XCTest.framework/XCTest", RTLD_LAZY) == nil {
debug(String(cString: dlerror()))
}
}()

@objc func loadAndInject(tmpfile: String, oldClass: AnyClass? = nil) throws -> [AnyClass] {

_ = loadXCTest

print("💉 Loading .dylib ...")
// load patched .dylib into process with new version of class
guard let dl = dlopen("\(tmpfile).dylib", RTLD_NOW) else {
Expand Down
3 changes: 2 additions & 1 deletion InjectionBundle/SwiftInjection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by John Holdsworth on 05/11/2017.
// Copyright © 2017 John Holdsworth. All rights reserved.
//
// $Id: //depot/ResidentEval/InjectionBundle/SwiftInjection.swift#115 $
// $Id: //depot/ResidentEval/InjectionBundle/SwiftInjection.swift#116 $
//
// Cut-down version of code injection in Swift. Uses code
// from SwiftEval.swift to recompile and reload class.
Expand Down Expand Up @@ -222,6 +222,7 @@ public class SwiftInjection: NSObject {
for suffix in SwiftTrace.swiftFunctionSuffixes {
findSwiftSymbols(dylib, suffix) { (loadedFunc, symbol, _, _) in
guard let existing = dlsym(main, symbol),
UnsafeRawPointer(existing) != loadedFunc,
let current = SwiftTrace.interposed(replacee: existing) else {
return
}
Expand Down
2 changes: 1 addition & 1 deletion InjectionIII/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>5633</string>
<string>5638</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion SwiftTrace

0 comments on commit 73fae23

Please sign in to comment.