Skip to content

enable netrc on non-darwin platforms #3466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>LibraryIdentifier</key>
<string>macos-x86_64</string>
<key>LibraryPath</key>
<string>Framework.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>macos</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public func foo() {
{}()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// swift-tools-version:5.3

import PackageDescription

let package = Package(
name: "Foo",
products: [
.library(name: "Foo", targets: ["Foo", "XCFramework"]),
],
targets: [
.target(name: "Foo", path: "./Foo"),
.binaryTarget(name: "XCFramework", path: "./Foo.xcframework")
]
)
13 changes: 0 additions & 13 deletions Sources/Commands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -439,19 +439,6 @@ public class SwiftTool {
if !options.archs.isEmpty && options.customCompileTriple != nil {
diagnostics.emit(.mutuallyExclusiveArgumentsError(arguments: ["--arch", "--triple"]))
}

if options.netrcFilePath != nil {
// --netrc-file option only supported on macOS >=10.13
#if os(macOS)
if #available(macOS 10.13, *) {
// ok, check succeeds
} else {
diagnostics.emit(error: "'--netrc-file' option is only supported on macOS >=10.13")
}
#else
diagnostics.emit(error: "'--netrc-file' option is only supported on macOS >=10.13")
#endif
}
Copy link
Contributor Author

@tomerd tomerd May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not meaningful any longer since SwiftPM is >= 10.15 and its supported on other platforms


// --enable-test-discovery should never be called on darwin based platforms
#if canImport(Darwin)
Expand Down
6 changes: 2 additions & 4 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1589,10 +1589,8 @@ extension Workspace {
let tempDiagnostics = DiagnosticsEngine()
let result = ThreadSafeArrayStore<ManagedArtifact>()

var authProvider: AuthorizationProviding? = nil
#if os(macOS) // Netrc feature currently only supported on macOS
authProvider = try? Netrc.load(fromFileAtPath: netrcFilePath).get()
#endif
// FIXME: should this handle the error more gracefully?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neonichu do you know why the error is ignored here? topic for different PR, but curios

let authProvider: AuthorizationProviding? = try? Netrc.load(fromFileAtPath: netrcFilePath).get()

// zip files to download
// stored in a thread-safe way as we may fetch more from "ari" files
Expand Down
3 changes: 0 additions & 3 deletions Tests/BasicsTests/URLSessionHTTPClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import FoundationNetworking
#endif
import TSCBasic
import TSCTestSupport
// // Netrc only available on macOS for now
#if os(macOS)
import struct TSCUtility.Netrc
#endif
import XCTest

final class URLSessionHTTPClientTest: XCTestCase {
Expand Down
109 changes: 35 additions & 74 deletions Tests/CommandsTests/PackageToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,89 +47,50 @@ final class PackageToolTests: XCTestCase {
let stdout = try execute(["--version"]).stdout
XCTAssert(stdout.contains("Swift Package Manager"), "got stdout:\n" + stdout)
}

func testNetrcSupportedOS() throws {
Copy link
Contributor Author

@tomerd tomerd May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not meaningful any longer since SwiftPM is >= 10.15 and its supported on other platforms

func verifyUnsupportedOSThrows() {

func testNetrcFile() throws {
fixture(name: "DependencyResolution/External/XCFramework") { packageRoot in
let fs = localFileSystem
let netrcPath = packageRoot.appending(component: ".netrc")
try fs.writeFileContents(netrcPath) { stream in
stream <<< "machine mymachine.labkey.org login [email protected] password mypassword"
}

do {
// should throw and be caught
try execute(["update", "--netrc-file", "/Users/me/.hidden/.netrc"])
XCTFail()
// file at correct location
try execute(["--netrc-file", netrcPath.pathString, "resolve"], packagePath: packageRoot)
// file does not exist, but is optional
let textOutput = try execute(["--netrc-file", "/foo", "--netrc-optional", "resolve"], packagePath: packageRoot).stderr
XCTAssert(textOutput.contains("warning: Did not find optional .netrc file at /foo."))

// required file does not exist, will throw
try execute(["--netrc-file", "/foo", "resolve"], packagePath: packageRoot)
} catch {
XCTAssert(true)
XCTAssert(String(describing: error).contains("Cannot find mandatory .netrc file at /foo"), "\(error)")
}
}
#if os(macOS)
if #available(macOS 10.13, *) {
// should succeed
XCTAssert(try execute(["--netrc"]).stdout.contains("USAGE: swift package"))
XCTAssert(try execute(["--netrc-file", "/Users/me/.hidden/.netrc"]).stdout.contains("USAGE: swift package"))
XCTAssert(try execute(["--netrc-optional"]).stdout.contains("USAGE: swift package"))
} else {
verifyUnsupportedOSThrows()
}
#else
verifyUnsupportedOSThrows()
#endif
}

func testNetrcFile() throws {
#if os(macOS)
if #available(macOS 10.13, *) {
// SUPPORTED OS
fixture(name: "DependencyResolution/External/Complex") { prefix in
let packageRoot = prefix.appending(component: "app")

let fs = localFileSystem
let netrcPath = prefix.appending(component: ".netrc")
try fs.writeFileContents(netrcPath) { stream in
stream <<< "machine mymachine.labkey.org login [email protected] password mypassword"
}

do {
// file at correct location
try execute(["--netrc-file", netrcPath.pathString, "resolve"], packagePath: packageRoot)
XCTAssert(true)

fixture(name: "DependencyResolution/External/XCFramework") { packageRoot in
Copy link
Contributor Author

@tomerd tomerd May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new fixtures that actually uses netrc :D

do {
// Developer machine may have .netrc file at NSHomeDirectory; modify test accordingly
if localFileSystem.exists(localFileSystem.homeDirectory.appending(RelativePath(".netrc"))) {
try execute(["--netrc", "resolve"], packagePath: packageRoot)
} else {
// file does not exist, but is optional
let textOutput = try execute(["--netrc-file", "/foo", "--netrc-optional", "resolve"], packagePath: packageRoot).stderr
XCTAssert(textOutput.contains("warning: Did not find optional .netrc file at /foo."))

let textOutput = try execute(["--netrc", "--netrc-optional", "resolve"], packagePath: packageRoot)
XCTAssert(textOutput.stderr.contains("Did not find optional .netrc file at \(localFileSystem.homeDirectory)/.netrc."))

// file does not exist, but is optional
let textOutput2 = try execute(["--netrc-optional", "resolve"], packagePath: packageRoot)
XCTAssert(textOutput2.stderr.contains("Did not find optional .netrc file at \(localFileSystem.homeDirectory)/.netrc."))

// required file does not exist, will throw
try execute(["--netrc-file", "/foo", "resolve"], packagePath: packageRoot)

} catch {
XCTAssert(String(describing: error).contains("Cannot find mandatory .netrc file at /foo"))
}
}

fixture(name: "DependencyResolution/External/Complex") { prefix in
let packageRoot = prefix.appending(component: "app")
do {
// Developer machine may have .netrc file at NSHomeDirectory; modify test accordingly
if localFileSystem.exists(localFileSystem.homeDirectory.appending(RelativePath(".netrc"))) {
try execute(["--netrc", "resolve"], packagePath: packageRoot)
XCTAssert(true)
} else {
// file does not exist, but is optional
let textOutput = try execute(["--netrc", "--netrc-optional", "resolve"], packagePath: packageRoot)
XCTAssert(textOutput.stderr.contains("Did not find optional .netrc file at \(localFileSystem.homeDirectory)/.netrc."))

// file does not exist, but is optional
let textOutput2 = try execute(["--netrc-optional", "resolve"], packagePath: packageRoot)
XCTAssert(textOutput2.stderr.contains("Did not find optional .netrc file at \(localFileSystem.homeDirectory)/.netrc."))

// required file does not exist, will throw
try execute(["--netrc", "resolve"], packagePath: packageRoot)
}
} catch {
XCTAssert(String(describing: error).contains("Cannot find mandatory .netrc file at \(localFileSystem.homeDirectory)/.netrc"))
try execute(["--netrc", "resolve"], packagePath: packageRoot)
}
} catch {
XCTAssert(String(describing: error).contains("Cannot find mandatory .netrc file at \(localFileSystem.homeDirectory)/.netrc"))
}
} else {
// UNSUPPORTED OS, HANDLED ELSEWHERE
}
#else
// UNSUPPORTED OS, HANDLED ELSEWHERE
#endif
}

func testResolve() throws {
Expand Down