Skip to content

Commit 0c9c8d5

Browse files
authored
enable netrc on non-darwin platforms (#3466)
motivation: * netrc functionality is useful on all platforms * underlying functionality is avaialbe via swiftlang/swift-tools-support-core#210 changes: * remove platforms restructions where appropriate * add test fixute that actually exercises the netrc parsing logic * adjust tests to run on all platforms
1 parent 06e2885 commit 0c9c8d5

File tree

7 files changed

+79
-94
lines changed

7 files changed

+79
-94
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>AvailableLibraries</key>
6+
<array>
7+
<dict>
8+
<key>LibraryIdentifier</key>
9+
<string>macos-x86_64</string>
10+
<key>LibraryPath</key>
11+
<string>Framework.framework</string>
12+
<key>SupportedArchitectures</key>
13+
<array>
14+
<string>x86_64</string>
15+
</array>
16+
<key>SupportedPlatform</key>
17+
<string>macos</string>
18+
</dict>
19+
</array>
20+
<key>CFBundlePackageType</key>
21+
<string>XFWK</string>
22+
<key>XCFrameworkFormatVersion</key>
23+
<string>1.0</string>
24+
</dict>
25+
</plist>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public func foo() {
2+
{}()
3+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// swift-tools-version:5.3
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "Foo",
7+
products: [
8+
.library(name: "Foo", targets: ["Foo", "XCFramework"]),
9+
],
10+
targets: [
11+
.target(name: "Foo", path: "./Foo"),
12+
.binaryTarget(name: "XCFramework", path: "./Foo.xcframework")
13+
]
14+
)

Sources/Commands/SwiftTool.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -439,19 +439,6 @@ public class SwiftTool {
439439
if !options.archs.isEmpty && options.customCompileTriple != nil {
440440
diagnostics.emit(.mutuallyExclusiveArgumentsError(arguments: ["--arch", "--triple"]))
441441
}
442-
443-
if options.netrcFilePath != nil {
444-
// --netrc-file option only supported on macOS >=10.13
445-
#if os(macOS)
446-
if #available(macOS 10.13, *) {
447-
// ok, check succeeds
448-
} else {
449-
diagnostics.emit(error: "'--netrc-file' option is only supported on macOS >=10.13")
450-
}
451-
#else
452-
diagnostics.emit(error: "'--netrc-file' option is only supported on macOS >=10.13")
453-
#endif
454-
}
455442

456443
// --enable-test-discovery should never be called on darwin based platforms
457444
#if canImport(Darwin)

Sources/Workspace/Workspace.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,10 +1589,8 @@ extension Workspace {
15891589
let tempDiagnostics = DiagnosticsEngine()
15901590
let result = ThreadSafeArrayStore<ManagedArtifact>()
15911591

1592-
var authProvider: AuthorizationProviding? = nil
1593-
#if os(macOS) // Netrc feature currently only supported on macOS
1594-
authProvider = try? Netrc.load(fromFileAtPath: netrcFilePath).get()
1595-
#endif
1592+
// FIXME: should this handle the error more gracefully?
1593+
let authProvider: AuthorizationProviding? = try? Netrc.load(fromFileAtPath: netrcFilePath).get()
15961594

15971595
// zip files to download
15981596
// stored in a thread-safe way as we may fetch more from "ari" files

Tests/BasicsTests/URLSessionHTTPClientTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ import FoundationNetworking
1717
#endif
1818
import TSCBasic
1919
import TSCTestSupport
20-
// // Netrc only available on macOS for now
21-
#if os(macOS)
2220
import struct TSCUtility.Netrc
23-
#endif
2421
import XCTest
2522

2623
final class URLSessionHTTPClientTest: XCTestCase {

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 35 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -47,89 +47,50 @@ final class PackageToolTests: XCTestCase {
4747
let stdout = try execute(["--version"]).stdout
4848
XCTAssert(stdout.contains("Swift Package Manager"), "got stdout:\n" + stdout)
4949
}
50-
51-
func testNetrcSupportedOS() throws {
52-
func verifyUnsupportedOSThrows() {
50+
51+
func testNetrcFile() throws {
52+
fixture(name: "DependencyResolution/External/XCFramework") { packageRoot in
53+
let fs = localFileSystem
54+
let netrcPath = packageRoot.appending(component: ".netrc")
55+
try fs.writeFileContents(netrcPath) { stream in
56+
stream <<< "machine mymachine.labkey.org login [email protected] password mypassword"
57+
}
58+
5359
do {
54-
// should throw and be caught
55-
try execute(["update", "--netrc-file", "/Users/me/.hidden/.netrc"])
56-
XCTFail()
60+
// file at correct location
61+
try execute(["--netrc-file", netrcPath.pathString, "resolve"], packagePath: packageRoot)
62+
// file does not exist, but is optional
63+
let textOutput = try execute(["--netrc-file", "/foo", "--netrc-optional", "resolve"], packagePath: packageRoot).stderr
64+
XCTAssert(textOutput.contains("warning: Did not find optional .netrc file at /foo."))
65+
66+
// required file does not exist, will throw
67+
try execute(["--netrc-file", "/foo", "resolve"], packagePath: packageRoot)
5768
} catch {
58-
XCTAssert(true)
69+
XCTAssert(String(describing: error).contains("Cannot find mandatory .netrc file at /foo"), "\(error)")
5970
}
6071
}
61-
#if os(macOS)
62-
if #available(macOS 10.13, *) {
63-
// should succeed
64-
XCTAssert(try execute(["--netrc"]).stdout.contains("USAGE: swift package"))
65-
XCTAssert(try execute(["--netrc-file", "/Users/me/.hidden/.netrc"]).stdout.contains("USAGE: swift package"))
66-
XCTAssert(try execute(["--netrc-optional"]).stdout.contains("USAGE: swift package"))
67-
} else {
68-
verifyUnsupportedOSThrows()
69-
}
70-
#else
71-
verifyUnsupportedOSThrows()
72-
#endif
73-
}
74-
75-
func testNetrcFile() throws {
76-
#if os(macOS)
77-
if #available(macOS 10.13, *) {
78-
// SUPPORTED OS
79-
fixture(name: "DependencyResolution/External/Complex") { prefix in
80-
let packageRoot = prefix.appending(component: "app")
81-
82-
let fs = localFileSystem
83-
let netrcPath = prefix.appending(component: ".netrc")
84-
try fs.writeFileContents(netrcPath) { stream in
85-
stream <<< "machine mymachine.labkey.org login [email protected] password mypassword"
86-
}
87-
88-
do {
89-
// file at correct location
90-
try execute(["--netrc-file", netrcPath.pathString, "resolve"], packagePath: packageRoot)
91-
XCTAssert(true)
72+
73+
fixture(name: "DependencyResolution/External/XCFramework") { packageRoot in
74+
do {
75+
// Developer machine may have .netrc file at NSHomeDirectory; modify test accordingly
76+
if localFileSystem.exists(localFileSystem.homeDirectory.appending(RelativePath(".netrc"))) {
77+
try execute(["--netrc", "resolve"], packagePath: packageRoot)
78+
} else {
9279
// file does not exist, but is optional
93-
let textOutput = try execute(["--netrc-file", "/foo", "--netrc-optional", "resolve"], packagePath: packageRoot).stderr
94-
XCTAssert(textOutput.contains("warning: Did not find optional .netrc file at /foo."))
95-
80+
let textOutput = try execute(["--netrc", "--netrc-optional", "resolve"], packagePath: packageRoot)
81+
XCTAssert(textOutput.stderr.contains("Did not find optional .netrc file at \(localFileSystem.homeDirectory)/.netrc."))
82+
83+
// file does not exist, but is optional
84+
let textOutput2 = try execute(["--netrc-optional", "resolve"], packagePath: packageRoot)
85+
XCTAssert(textOutput2.stderr.contains("Did not find optional .netrc file at \(localFileSystem.homeDirectory)/.netrc."))
86+
9687
// required file does not exist, will throw
97-
try execute(["--netrc-file", "/foo", "resolve"], packagePath: packageRoot)
98-
99-
} catch {
100-
XCTAssert(String(describing: error).contains("Cannot find mandatory .netrc file at /foo"))
101-
}
102-
}
103-
104-
fixture(name: "DependencyResolution/External/Complex") { prefix in
105-
let packageRoot = prefix.appending(component: "app")
106-
do {
107-
// Developer machine may have .netrc file at NSHomeDirectory; modify test accordingly
108-
if localFileSystem.exists(localFileSystem.homeDirectory.appending(RelativePath(".netrc"))) {
109-
try execute(["--netrc", "resolve"], packagePath: packageRoot)
110-
XCTAssert(true)
111-
} else {
112-
// file does not exist, but is optional
113-
let textOutput = try execute(["--netrc", "--netrc-optional", "resolve"], packagePath: packageRoot)
114-
XCTAssert(textOutput.stderr.contains("Did not find optional .netrc file at \(localFileSystem.homeDirectory)/.netrc."))
115-
116-
// file does not exist, but is optional
117-
let textOutput2 = try execute(["--netrc-optional", "resolve"], packagePath: packageRoot)
118-
XCTAssert(textOutput2.stderr.contains("Did not find optional .netrc file at \(localFileSystem.homeDirectory)/.netrc."))
119-
120-
// required file does not exist, will throw
121-
try execute(["--netrc", "resolve"], packagePath: packageRoot)
122-
}
123-
} catch {
124-
XCTAssert(String(describing: error).contains("Cannot find mandatory .netrc file at \(localFileSystem.homeDirectory)/.netrc"))
88+
try execute(["--netrc", "resolve"], packagePath: packageRoot)
12589
}
90+
} catch {
91+
XCTAssert(String(describing: error).contains("Cannot find mandatory .netrc file at \(localFileSystem.homeDirectory)/.netrc"))
12692
}
127-
} else {
128-
// UNSUPPORTED OS, HANDLED ELSEWHERE
12993
}
130-
#else
131-
// UNSUPPORTED OS, HANDLED ELSEWHERE
132-
#endif
13394
}
13495

13596
func testResolve() throws {

0 commit comments

Comments
 (0)