Skip to content

Commit 586d7ba

Browse files
committed
Implemented "legacy" entrypoints for PlaygroundLogger.
These functions match those used by LLDB in its playground preamble, allowing this framework to be used as a drop-in replacement for the legacy PlaygroundLogger framework. Since these functions return NSData objects, they do not call the `sendData` function. As a result, the legacy initialization function sets `sendData` to a stub which calls through to `fatalError`.
1 parent 230ac68 commit 586d7ba

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

PlaygroundLogger/PlaygroundLogger.xcodeproj/project.pbxproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
5E2756911FCF967300B69C83 /* NSBitmapImageRep+OpaqueImageRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2756901FCF967300B69C83 /* NSBitmapImageRep+OpaqueImageRepresentable.swift */; };
7373
5E2756941FCF9CB000B69C83 /* SpriteKitOpaqueLoggable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2756931FCF9CB000B69C83 /* SpriteKitOpaqueLoggable.swift */; };
7474
5E4AF1AD1FDDBDE400B7C9D9 /* Unimplemented.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E4AF1AC1FDDBDE400B7C9D9 /* Unimplemented.swift */; };
75+
5E4AF1AF1FDDC12A00B7C9D9 /* LegacyEntrypoints.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E4AF1AE1FDDC12A00B7C9D9 /* LegacyEntrypoints.swift */; };
7576
/* End PBXBuildFile section */
7677

7778
/* Begin PBXContainerItemProxy section */
@@ -167,6 +168,7 @@
167168
5E2756901FCF967300B69C83 /* NSBitmapImageRep+OpaqueImageRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSBitmapImageRep+OpaqueImageRepresentable.swift"; sourceTree = "<group>"; };
168169
5E2756931FCF9CB000B69C83 /* SpriteKitOpaqueLoggable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpriteKitOpaqueLoggable.swift; sourceTree = "<group>"; };
169170
5E4AF1AC1FDDBDE400B7C9D9 /* Unimplemented.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Unimplemented.swift; sourceTree = "<group>"; };
171+
5E4AF1AE1FDDC12A00B7C9D9 /* LegacyEntrypoints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyEntrypoints.swift; sourceTree = "<group>"; };
170172
/* End PBXFileReference section */
171173

172174
/* Begin PBXFrameworksBuildPhase section */
@@ -345,6 +347,7 @@
345347
isa = PBXGroup;
346348
children = (
347349
5E27564E1FC4E58300B69C83 /* PlaygroundQuickLook+OpaqueRepresentationSupport.swift */,
350+
5E4AF1AE1FDDC12A00B7C9D9 /* LegacyEntrypoints.swift */,
348351
);
349352
name = "Legacy Support";
350353
path = LegacySupport;
@@ -592,6 +595,7 @@
592595
5E2756261FC488DC00B69C83 /* Float+TaggedOpaqueRepresentation.swift in Sources */,
593596
5E2756721FC51FF400B69C83 /* CGImage+CustomOpaqueLoggable.swift in Sources */,
594597
5E2756801FCF435300B69C83 /* NSBezierPath+CustomOpaqueLoggable.swift in Sources */,
598+
5E4AF1AF1FDDC12A00B7C9D9 /* LegacyEntrypoints.swift in Sources */,
595599
5E27568F1FCF964400B69C83 /* NSBitmapImageRep+CustomOpaqueLoggable.swift in Sources */,
596600
5E27568D1FCF45AE00B69C83 /* UIView+CustomOpaqueLoggable.swift in Sources */,
597601
5E27566B1FC51D2B00B69C83 /* NSAttributedString+CustomOpaqueLoggable.swift in Sources */,
@@ -796,7 +800,7 @@
796800
FRAMEWORK_VERSION = A;
797801
INFOPLIST_FILE = PlaygroundLogger/Info.plist;
798802
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
799-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
803+
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../../../";
800804
OTHER_SWIFT_FLAGS = "-Xfrontend -debugger-support";
801805
PRODUCT_BUNDLE_IDENTIFIER = org.swift.PlaygroundLogger;
802806
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@@ -820,7 +824,7 @@
820824
FRAMEWORK_VERSION = A;
821825
INFOPLIST_FILE = PlaygroundLogger/Info.plist;
822826
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
823-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
827+
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../../../";
824828
OTHER_SWIFT_FLAGS = "-Xfrontend -debugger-support";
825829
PRODUCT_BUNDLE_IDENTIFIER = org.swift.PlaygroundLogger;
826830
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//===--- LegacyEntrypoints.swift ------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
/*
14+
LLDB contains references to the following functions:
15+
16+
@_silgen_name ("playground_logger_initialize") func $builtin_logger_initialize() -> Void
17+
@_silgen_name ("playground_log_hidden") func $builtin_log_with_id<T>(_ object : T, _ name : String, _ id : Int, _ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject
18+
@_silgen_name ("playground_log_scope_entry") func $builtin_log_scope_entry(_ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject
19+
@_silgen_name ("playground_log_scope_exit") func $builtin_log_scope_exit(_ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject
20+
@_silgen_name ("playground_log_postprint") func $builtin_postPrint(_ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject
21+
22+
where the `AnyObject` returned by each function is actually an `NSData` instance.
23+
24+
To maintain compatibility with current and previous LLDB, we need to export these functions as well.
25+
*/
26+
27+
@_silgen_name("playground_logger_initialize")
28+
@available(*, deprecated, message: "Use modern PlaygroundLogger initialization instead")
29+
public func legacyInitializePlaygroundLogger() -> Void {
30+
Swift._playgroundPrintHook = printHook
31+
sendData = legacySendDataStub
32+
}
33+
34+
fileprivate func legacySendDataStub(_: NSData) -> Void {
35+
fatalError("A legacy-initialized PlaygroundLogger should not use the sendData function pointer!")
36+
}
37+
38+
@_silgen_name("playground_log_hidden")
39+
@available(*, deprecated, message: "Use modern PlaygroundLogger log function instead")
40+
public func legacyLog<T>(instance: T, name: String, id: Int, startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject {
41+
let packet = LogPacket(describingResult: instance, named: name, startLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn)
42+
43+
let data = packet.encode()
44+
45+
return data as NSData
46+
}
47+
48+
@_silgen_name ("playground_log_scope_entry")
49+
@available(*, deprecated, message: "Use modern PlaygroundLogger log scope entry function instead")
50+
public func legacyLogScopeEntry(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject {
51+
let packet = LogPacket(scopeEntryWithStartLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn)
52+
53+
let data = packet.encode()
54+
55+
return data as NSData
56+
}
57+
58+
@_silgen_name ("playground_log_scope_exit")
59+
@available(*, deprecated, message: "Use modern PlaygroundLogger log scope exit function instead")
60+
public func legacyLogScopeExit(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject {
61+
let packet = LogPacket(scopeExitWithStartLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn)
62+
63+
let data = packet.encode()
64+
65+
return data as NSData
66+
}
67+
68+
@_silgen_name ("playground_log_postprint")
69+
@available(*, deprecated, message: "Use modern PlaygroundLogger postprint function instead")
70+
func legacyLogPostPrint(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject {
71+
let printedString = Thread.current.threadDictionary[printedStringThreadDictionaryKey] as! String? ?? ""
72+
73+
Thread.current.threadDictionary.removeObject(forKey: printedStringThreadDictionaryKey)
74+
75+
let packet = LogPacket(printedString: printedString, startLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn)
76+
77+
let data = packet.encode()
78+
79+
return data as NSData
80+
}

PlaygroundLogger/PlaygroundLogger/LoggerEntrypoints.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2017-2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -48,7 +48,7 @@ func logScopeExit(startLine: Int,
4848
sendData(data as NSData)
4949
}
5050

51-
fileprivate let printedStringThreadDictionaryKey: NSString = "org.swift.PlaygroundLogger.printedString"
51+
let printedStringThreadDictionaryKey: NSString = "org.swift.PlaygroundLogger.printedString"
5252

5353
func printHook(string: String) {
5454
Thread.current.threadDictionary[printedStringThreadDictionaryKey] = string as NSString

0 commit comments

Comments
 (0)