Skip to content

Commit 9f22fa5

Browse files
committed
Make sure the Swift REPL is initialized with host OS availablity.
This is fixed by unifying the code that updates the ArchSpec after finding a fat binary with how it is done for a lean binary. <rdar://problem/66024437>
1 parent 6888a19 commit 9f22fa5

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

lldb/source/Target/TargetList.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ Status TargetList::CreateTargetInternal(
9292
ArchSpec platform_arch(arch);
9393

9494
bool prefer_platform_arch = false;
95+
auto update_platform_arch = [&](const ArchSpec &module_arch) {
96+
// If the OS or vendor weren't specified, then adopt the module's
97+
// architecture so that the platform matching can be more accurate.
98+
if (!platform_arch.TripleOSWasSpecified() ||
99+
!platform_arch.TripleVendorWasSpecified()) {
100+
prefer_platform_arch = true;
101+
platform_arch = module_arch;
102+
}
103+
};
95104

96105
CommandInterpreter &interpreter = debugger.GetCommandInterpreter();
97106

@@ -134,12 +143,8 @@ Status TargetList::CreateTargetInternal(
134143
matching_module_spec.GetArchitecture())) {
135144
// If the OS or vendor weren't specified, then adopt the module's
136145
// architecture so that the platform matching can be more
137-
// accurate
138-
if (!platform_arch.TripleOSWasSpecified() ||
139-
!platform_arch.TripleVendorWasSpecified()) {
140-
prefer_platform_arch = true;
141-
platform_arch = matching_module_spec.GetArchitecture();
142-
}
146+
// accurate.
147+
update_platform_arch(matching_module_spec.GetArchitecture());
143148
} else {
144149
StreamString platform_arch_strm;
145150
StreamString module_arch_strm;
@@ -162,16 +167,15 @@ Status TargetList::CreateTargetInternal(
162167
}
163168
} else {
164169
if (arch.IsValid()) {
170+
// Fat binary. A (valid) architecture was specified.
165171
module_spec.GetArchitecture() = arch;
166172
if (module_specs.FindMatchingModuleSpec(module_spec,
167173
matching_module_spec)) {
168-
prefer_platform_arch = true;
169-
platform_arch = matching_module_spec.GetArchitecture();
174+
update_platform_arch(matching_module_spec.GetArchitecture());
170175
}
171176
} else {
172-
// No architecture specified, check if there is only one platform for
173-
// all of the architectures.
174-
177+
// Fat binary. No architecture specified, check if there is
178+
// only one platform for all of the architectures.
175179
typedef std::vector<PlatformSP> PlatformList;
176180
PlatformList platforms;
177181
PlatformSP host_platform_sp = Platform::GetHostPlatform();
@@ -263,7 +267,8 @@ Status TargetList::CreateTargetInternal(
263267
// If we have a valid architecture, make sure the current platform is
264268
// compatible with that architecture
265269
if (!prefer_platform_arch && arch.IsValid()) {
266-
if (!platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) {
270+
ArchSpec compatible_arch;
271+
if (!platform_sp->IsCompatibleArchitecture(arch, false, &compatible_arch)) {
267272
platform_sp = Platform::GetPlatformForArchitecture(arch, &platform_arch);
268273
if (!is_dummy_target && platform_sp)
269274
debugger.GetPlatformList().SetSelectedPlatform(platform_sp);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// -*- mode: swift; -*-
2+
// Test that the REPL is launched with the current OS as availability target.
3+
// REQUIRES: system-darwin
4+
5+
// RUN: mkdir -p %t.dir
6+
// RUN: echo '@available(macOS '>%t.dir/NewModule.swift
7+
// RUN: sw_vers | grep ProductVersion | cut -d : -f 2 >>%t.dir/NewModule.swift
8+
// RUN: echo ', *) public let message = "Hello"' >>%t.dir/NewModule.swift
9+
// RUN: %target-swiftc -module-name NewModule -emit-module -emit-library -o %t.dir/libNewModule%target-shared-library-suffix %t.dir/NewModule.swift
10+
11+
// RUN: %lldb --repl="-I%t.dir -L%t.dir -lNewModule" --repl-language swift < %s | FileCheck %s
12+
import NewModule
13+
message
14+
// CHECK: $R0{{.*}}Hello

0 commit comments

Comments
 (0)