Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.

Commit 5d6a3ea

Browse files
authored
Merge pull request #54 from tfiala/fix-SR-2637-test
Add back "added tests for SR-2637"
2 parents a463070 + c418888 commit 5d6a3ea

File tree

6 files changed

+180
-0
lines changed

6 files changed

+180
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
3+
@objc public class A: NSObject {
4+
public func foo() -> Int {
5+
return 4 // Set breakpoint here
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
3+
@objc public class B: NSObject {
4+
public func bar() -> Int {
5+
return 8 // Set breakpoint here
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Build swift modules with debug info
2+
3+
LEVEL=../../../../make
4+
5+
# Don't use 'all' target. There is a default build rule that will kick in that
6+
# will be wrong. WE use 'first' so that the normal 'make' command (without
7+
# a target) selects the first (but not 'all') target so we avoid the undesired
8+
# default behavior.
9+
first: main
10+
11+
SWIFT_OBJC_INTEROP=1
12+
13+
include $(LEVEL)/Makefile.rules
14+
15+
# Add back the SDK settings to the swift flags. Normally this happens
16+
# automatically, but since we're overriding the normal swiftc invocation,
17+
# we're not specifying SWIFT_SOURCES, and thus don't get the SDK.
18+
SWIFTFLAGS+=-sdk "$(SWIFTSDKROOT)"
19+
20+
# To use the path commented out below, which is what we'd really want to do,
21+
# we'd also need to require that the Swift standard library be built along
22+
# with the compiler. I'd like to avoid that requirement.
23+
# SWIFT_LIB_DIR=$(dir $(SWIFTCC))../lib
24+
SWIFT_LIB_DIR="$(shell xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx"
25+
26+
main: A.o B.o objc_main.m
27+
$(CC) $(CFLAGS) objc_main.m -fobjc-arc -o main A.o B.o -L $(SWIFT_LIB_DIR) -Xlinker -add_ast_path -Xlinker A.swiftmodule -Xlinker -add_ast_path -Xlinker B.swiftmodule -Xlinker -rpath -Xlinker $(SWIFT_LIB_DIR)
28+
29+
A.o: A.swift
30+
$(SWIFTCC) $(SWIFTFLAGS) -c -parse-as-library -module-name A -emit-module-path A.swiftmodule -emit-objc-header-path A-Swift.h -output-file-map output_map A.swift
31+
32+
B.o: B.swift
33+
$(SWIFTCC) $(SWIFTFLAGS) -c -parse-as-library -module-name B -emit-module-path B.swiftmodule -emit-objc-header-path B-Swift.h -output-file-map output_map B.swift -o B.o
34+
35+
clean::
36+
rm -f *.o main *-Swift.h *.swiftmodule *.swiftdoc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# TestSwiftStaticLinkingMacOS.py
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 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+
Test that macOS can statically link two separately-compiled Swift modules
14+
with one Objective-C module, link them through the clang driver, and still
15+
access debug info for each of the Swift modules.
16+
"""
17+
from __future__ import print_function
18+
19+
20+
# System imports
21+
import os
22+
import commands
23+
24+
# Third-party imports
25+
26+
# LLDB imports
27+
import lldb
28+
from lldbsuite.test.lldbtest import TestBase
29+
from lldbsuite.test import decorators, lldbtest, lldbutil
30+
31+
32+
class SwiftStaticLinkingMacOSTestCase(TestBase):
33+
34+
mydir = TestBase.compute_mydir(__file__)
35+
36+
NO_DEBUG_INFO_TESTCASE = True
37+
38+
def expect_self_var_available_at_breakpoint(
39+
self, process, breakpoint, module_name):
40+
# Frame #0 should be at the given breakpoint
41+
threads = lldbutil.get_threads_stopped_at_breakpoint(
42+
process, breakpoint)
43+
44+
self.assertEquals(1, len(threads))
45+
self.thread = threads[0]
46+
self.frame = self.thread.frames[0]
47+
self.assertTrue(self.frame, "Frame 0 is valid.")
48+
49+
patterns = [
50+
# Ensure we report a self with an address.
51+
r"self\s*=\s*0x[0-9a-fA-F]+",
52+
# Ensure we think it is an NSObject.
53+
r"ObjectiveC.NSObject"]
54+
substrs = [
55+
"(%s.%s)" % (module_name, module_name)
56+
]
57+
self.expect("frame variable self", patterns=patterns,
58+
substrs=substrs)
59+
60+
@decorators.skipUnlessDarwin
61+
def test_variables_print_from_both_swift_modules(self):
62+
"""Test that variables from two modules can be accessed."""
63+
self.build()
64+
65+
# I could not find a reasonable way to say "skipUnless(archs=[])".
66+
# That would probably be worth adding.
67+
if self.getArchitecture() != 'x86_64':
68+
self.skipTest("This test requires x86_64 as the architecture "
69+
"for the inferior")
70+
71+
exe_name = "main"
72+
src_a = lldb.SBFileSpec("A.swift")
73+
line_a = 5
74+
src_b = lldb.SBFileSpec("B.swift")
75+
line_b = 5
76+
exe = os.path.join(os.getcwd(), exe_name)
77+
78+
# Create the target
79+
target = self.dbg.CreateTarget(exe)
80+
self.assertTrue(target, lldbtest.VALID_TARGET)
81+
82+
# Set the breakpoints
83+
# breakpoint_a = target.BreakpointCreateBySourceRegex(
84+
# 'Set breakpoint here', src_a)
85+
breakpoint_a = target.BreakpointCreateByLocation(
86+
src_a, line_a)
87+
self.assertTrue(breakpoint_a.GetNumLocations() > 0,
88+
lldbtest.VALID_BREAKPOINT)
89+
90+
# breakpoint_b = target.BreakpointCreateBySourceRegex(
91+
# 'Set breakpoint here', src_b)
92+
breakpoint_b = target.BreakpointCreateByLocation(
93+
src_b, line_b)
94+
self.assertTrue(breakpoint_b.GetNumLocations() > 0,
95+
lldbtest.VALID_BREAKPOINT)
96+
97+
# Launch the process, and do not stop at the entry point.
98+
envp = ['DYLD_FRAMEWORK_PATH=.']
99+
process = target.LaunchSimple(None, envp, os.getcwd())
100+
101+
self.assertTrue(process, lldbtest.PROCESS_IS_VALID)
102+
103+
# We should be at breakpoint in module A.
104+
self.expect_self_var_available_at_breakpoint(
105+
process, breakpoint_a, "A")
106+
107+
# Jump to the next breakpoint
108+
process.Continue()
109+
110+
# We should be at breakpoint in module B.
111+
self.expect_self_var_available_at_breakpoint(
112+
process, breakpoint_b, "B")
113+
114+
return
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#import <Foundation/Foundation.h>
2+
3+
#import "A-Swift.h"
4+
#import "B-Swift.h"
5+
6+
int main(int argc, const char * argv[]) {
7+
@autoreleasepool {
8+
NSLog(@"Hello, World!");
9+
NSLog(@"A = %ld", [[[A alloc] init] foo]);
10+
NSLog(@"B = %ld", [[[B alloc] init] bar]);
11+
}
12+
return 0;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{'A.swift': {'object': 'A.o'},
2+
'B.swift': {'object': 'B.o'},
3+
}

0 commit comments

Comments
 (0)