Skip to content

Commit 7ee1537

Browse files
Merge pull request #5034 from adrian-prantl/31066897
Resuscitate TestSwiftStaticLinking.py
2 parents a9d7ab2 + a488eaa commit 7ee1537

File tree

5 files changed

+23
-103
lines changed

5 files changed

+23
-103
lines changed
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
// A.swift
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 https://swift.org/LICENSE.txt for license information
9-
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10-
//
11-
// -----------------------------------------------------------------------------
12-
131
import Foundation
142

153
@objc public class A: NSObject {
16-
public func foo() -> Int {
4+
@objc public func foo() -> Int {
175
return 4 // Set breakpoint here
186
}
19-
}
7+
}
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
// B.swift
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 https://swift.org/LICENSE.txt for license information
9-
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10-
//
11-
// -----------------------------------------------------------------------------
12-
131
import Foundation
142

153
@objc public class B: NSObject {
16-
public func bar() -> Int {
4+
@objc public func bar() -> Int {
175
return 8 // Set breakpoint here
186
}
19-
}
7+
}

lldb/test/API/lang/swift/static_linking/macOS/Makefile

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,30 @@
44
# will be wrong. WE use 'first' so that the normal 'make' command (without
55
# a target) selects the first (but not 'all') target so we avoid the undesired
66
# default behavior.
7-
first: main
7+
EXE:=a.out
8+
all: $(EXE)
89

910
SWIFT_OBJC_INTEROP=1
10-
1111
include Makefile.rules
1212

1313
# Add back the SDK settings to the swift flags. Normally this happens
1414
# automatically, but since we're overriding the normal swiftc invocation,
1515
# we're not specifying SWIFT_SOURCES, and thus don't get the SDK.
1616
SWIFTFLAGS+=-sdk "$(SWIFTSDKROOT)"
1717

18-
# To use the path commented out below, which is what we'd really want to do,
19-
# we'd also need to require that the Swift standard library be built along
20-
# with the compiler. I'd like to avoid that requirement.
21-
# SWIFT_LIB_DIR=$(dir $(SWIFTC))../lib
22-
SWIFT_LIB_DIR="$(shell xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx"
23-
24-
main: objc_main.m A.o B.o
25-
$(CC) $(CFLAGS) $< -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)
18+
$(EXE): objc_main.m A.o B.o
19+
$(CC) $(CFLAGS) -c -I. $< -fobjc-arc -o $(BUILDDIR)/objc_main.o
20+
$(SWIFTC) $(SWIFTFLAGS) -o $@ $(BUILDDIR)/objc_main.o $(BUILDDIR)/A.o $(BUILDDIR)/B.o -L$(BUILDDIR) -Xlinker -add_ast_path -Xlinker A.swiftmodule -Xlinker -add_ast_path -Xlinker B.swiftmodule
2621
ifneq "$(CODESIGN)" ""
2722
$(CODESIGN) -s - "$@"
2823
endif
2924

30-
31-
A.o: A.swift
32-
$(SWIFTC) $(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 $<
33-
34-
B.o: B.swift
35-
$(SWIFTC) $(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 $< -o $@
36-
37-
clean::
38-
rm -f *.o main *-Swift.h *.swiftmodule *.swiftdoc
25+
%.o: %.swift
26+
$(MAKE) -f $(MAKEFILE_RULES) \
27+
DYLIB_NAME=$(patsubst %.o,%,$@) \
28+
SWIFT_SOURCES=$(patsubst %.o,%.swift,$@) \
29+
SWIFT_OBJC_HEADER=$(patsubst %.o,%-swift.h,$@) \
30+
MODULENAME=$(patsubst %.o,%,$@) \
31+
$(patsubst %.o,%.swiftmodule,$@) \
32+
$(patsubst %.o,%-Swift.h,$@) \
33+
$@

lldb/test/API/lang/swift/static_linking/macOS/TestSwiftStaticLinkingMacOS.py

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
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 https://swift.org/LICENSE.txt for license information
9-
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10-
#
11-
# ------------------------------------------------------------------------------
121
"""
132
Test that macOS can statically link two separately-compiled Swift modules
143
with one Objective-C module, link them through the clang driver, and still
154
access debug info for each of the Swift modules.
165
"""
17-
from __future__ import print_function
18-
19-
206
# System imports
217
import os
228

@@ -35,67 +21,33 @@ class SwiftStaticLinkingMacOSTestCase(TestBase):
3521

3622
def expect_self_var_available_at_breakpoint(
3723
self, process, breakpoint, module_name):
38-
# Frame #0 should be at the given breakpoint
39-
threads = lldbutil.get_threads_stopped_at_breakpoint(
40-
process, breakpoint)
41-
42-
self.assertEquals(1, len(threads))
43-
4424
patterns = [
4525
# Ensure we report a self with an address.
46-
r"self\s*=\s*0x[0-9a-fA-F]+",
26+
r"=\s*0x[0-9a-fA-F]+",
4727
# Ensure we think it is an NSObject.
4828
r"ObjectiveC.NSObject"]
4929
substrs = [
5030
"(%s.%s)" % (module_name, module_name)
5131
]
52-
self.expect("frame variable self", patterns=patterns,
32+
self.expect("expr self", patterns=patterns,
5333
substrs=substrs)
5434

5535
@skipUnlessDarwin
56-
@skipIf(bugnumber="<rdar://problem/31066897>")
5736
def test_variables_print_from_both_swift_modules(self):
5837
"""Test that variables from two modules can be accessed."""
5938
self.build()
6039

61-
# I could not find a reasonable way to say "skipUnless(archs=[])".
62-
# That would probably be worth adding.
63-
if self.getArchitecture() != 'x86_64':
64-
self.skipTest("This test requires x86_64 as the architecture "
65-
"for the inferior")
66-
67-
exe_name = "main"
68-
src_a = lldb.SBFileSpec("A.swift")
69-
line_a = 5
70-
src_b = lldb.SBFileSpec("B.swift")
71-
line_b = 5
72-
exe = self.getBuildArtifact(exe_name)
73-
7440
# Create the target
75-
target = self.dbg.CreateTarget(exe)
76-
self.assertTrue(target, lldbtest.VALID_TARGET)
77-
78-
# Set the breakpoints
79-
# breakpoint_a = target.BreakpointCreateBySourceRegex(
80-
# 'Set breakpoint here', src_a)
81-
breakpoint_a = target.BreakpointCreateByLocation(
82-
src_a, line_a)
83-
self.assertTrue(breakpoint_a.GetNumLocations() > 0,
84-
lldbtest.VALID_BREAKPOINT)
41+
target, process, _, breakpoint_a = lldbutil.run_to_line_breakpoint(
42+
self, lldb.SBFileSpec("A.swift"), 5)
8543

8644
# breakpoint_b = target.BreakpointCreateBySourceRegex(
8745
# 'Set breakpoint here', src_b)
8846
breakpoint_b = target.BreakpointCreateByLocation(
89-
src_b, line_b)
47+
lldb.SBFileSpec("B.swift"), 5)
9048
self.assertTrue(breakpoint_b.GetNumLocations() > 0,
9149
lldbtest.VALID_BREAKPOINT)
9250

93-
# Launch the process, and do not stop at the entry point.
94-
envp = ['DYLD_FRAMEWORK_PATH=.']
95-
process = target.LaunchSimple(None, envp, os.getcwd())
96-
97-
self.assertTrue(process, lldbtest.PROCESS_IS_VALID)
98-
9951
# We should be at breakpoint in module A.
10052
self.expect_self_var_available_at_breakpoint(
10153
process, breakpoint_a, "A")

lldb/test/API/lang/swift/static_linking/macOS/output_map

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)