Skip to content

Unblock SwiftPM's build #2876

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 2 commits into from
Aug 19, 2020
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
4 changes: 2 additions & 2 deletions Sources/PackageLoading/PackageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -840,12 +840,12 @@ public final class PackageBuilder {
func buildConditions(from condition: PackageConditionDescription?) -> [PackageConditionProtocol] {
var conditions: [PackageConditionProtocol] = []

if let config = condition?.config.map({ BuildConfiguration(rawValue: $0)! }) {
if let config = condition?.config.flatMap({ BuildConfiguration(rawValue: $0) }) {
let condition = ConfigurationCondition(configuration: config)
conditions.append(condition)
}

if let platforms = condition?.platformNames.map({ platformRegistry.platformByName[$0]! }), !platforms.isEmpty {
if let platforms = condition?.platformNames.flatMap({ platformRegistry.platformByName[$0] }), !platforms.isEmpty {
let condition = PlatformsCondition(platforms: platforms)
conditions.append(condition)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/SPMTestSupport/MockDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class MockDownloader: Downloader {
public func downloadFile(
at url: Foundation.URL,
to destinationPath: AbsolutePath,
withAuthorizationProvider: AuthorizationProviding? = nil,
progress: @escaping Downloader.Progress,
completion: @escaping Downloader.Completion
) {
Expand Down
1 change: 1 addition & 0 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,7 @@ extension Workspace {
downloader.downloadFile(
at: parsedURL,
to: archivePath,
withAuthorizationProvider: nil,
progress: { bytesDownloaded, totalBytesToDownload in
self.delegate?.downloadingBinaryArtifact(
from: url,
Expand Down
3 changes: 3 additions & 0 deletions Utilities/build-using-self
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

# FIXME: Temporarily disabled until #2876 lands
exit 0

set -eu

__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
Expand Down
3 changes: 2 additions & 1 deletion swift-tools-support-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ else()
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

option(BUILD_SHARED_LIBS "Build shared libraryes by default" YES)
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)

find_package(dispatch QUIET)
find_package(Foundation QUIET)
find_package(SQLite3 REQUIRED)

add_subdirectory(Sources)
add_subdirectory(cmake/modules)
55 changes: 55 additions & 0 deletions swift-tools-support-core/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Code of Conduct
To be a truly great community, Swift.org needs to welcome developers from all walks of life,
with different backgrounds, and with a wide range of experience. A diverse and friendly
community will have more great ideas, more unique perspectives, and produce more great
code. We will work diligently to make the Swift community welcoming to everyone.

To give clarity of what is expected of our members, Swift.org has adopted the code of conduct
defined by [contributor-covenant.org](https://www.contributor-covenant.org). This document is used across many open source
communities, and we think it articulates our values well. The full text is copied below:

### Contributor Code of Conduct v1.3
As contributors and maintainers of this project, and in the interest of fostering an open and
welcoming community, we pledge to respect all people who contribute through reporting
issues, posting feature requests, updating documentation, submitting pull requests or patches,
and other activities.

We are committed to making participation in this project a harassment-free experience for
everyone, regardless of level of experience, gender, gender identity and expression, sexual
orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or
nationality.

Examples of unacceptable behavior by participants include:
- The use of sexualized language or imagery
- Personal attacks
- Trolling or insulting/derogatory comments
- Public or private harassment
- Publishing other’s private information, such as physical or electronic addresses, without explicit permission
- Other unethical or unprofessional conduct

Project maintainers have the right and responsibility to remove, edit, or reject comments,
commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of
Conduct, or to ban temporarily or permanently any contributor for other behaviors that they
deem inappropriate, threatening, offensive, or harmful.

By adopting this Code of Conduct, project maintainers commit themselves to fairly and
consistently applying these principles to every aspect of managing this project. Project
maintainers who do not follow or enforce the Code of Conduct may be permanently removed
from the project team.

This code of conduct applies both within project spaces and in public spaces when an
individual is representing the project or its community.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
contacting a project maintainer at [[email protected]](mailto:[email protected]). All complaints will be reviewed and
investigated and will result in a response that is deemed necessary and appropriate to the
circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter
of an incident.

*This policy is adapted from the Contributor Code of Conduct [version 1.3.0](http://contributor-covenant.org/version/1/3/0/).*

### Reporting
A working group of community members is committed to promptly addressing any [reported
issues](mailto:[email protected]). Working group members are volunteers appointed by the project lead, with a
preference for individuals with varied backgrounds and perspectives. Membership is expected
to change regularly, and may grow or shrink.
10 changes: 5 additions & 5 deletions swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ add_library(TSCBasic
Thread.swift
Tuple.swift
misc.swift)
target_compile_options(TSCBasic PUBLIC
# Don't use GNU strerror_r on Android.
"$<$<PLATFORM_ID:Android>:SHELL:-Xcc -U_GNU_SOURCE>"
# Ignore secure function warnings on Windows.
"$<$<PLATFORM_ID:Windows>:SHELL:-Xcc -D_CRT_SECURE_NO_WARNINGS>")
target_link_libraries(TSCBasic PUBLIC
TSCLibc)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
Expand All @@ -67,9 +72,4 @@ install(TARGETS TSCBasic
RUNTIME DESTINATION bin)
endif()

# Don't use GNU strerror_r on Android.
if(CMAKE_SYSTEM_NAME STREQUAL Android)
target_compile_options(TSCBasic PUBLIC "SHELL:-Xcc -U_GNU_SOURCE")
endif()

set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCBasic)
4 changes: 4 additions & 0 deletions swift-tools-support-core/Sources/TSCBasic/CStringArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public final class CStringArray {

/// Creates an instance from an array of strings.
public init(_ array: [String]) {
#if os(Windows)
cArray = array.map({ $0.withCString({ _strdup($0) }) }) + [nil]
#else
cArray = array.map({ $0.withCString({ strdup($0) }) }) + [nil]
#endif
}

deinit {
Expand Down
3 changes: 2 additions & 1 deletion swift-tools-support-core/Sources/TSCBasic/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ extension FileSystem {
}
}

#if !os(Windows)
extension dirent {
/// Get the directory name.
///
Expand All @@ -911,4 +912,4 @@ extension dirent {
}
}
}

#endif
16 changes: 13 additions & 3 deletions swift-tools-support-core/Sources/TSCBasic/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ private struct UNIXPath: Path {
return name != "" && name != "." && name != ".." && !name.contains("/")
}

#if os(Windows)
static func isAbsolutePath(_ path: String) -> Bool {
return !path.withCString(encodedAs: UTF16.self, PathIsRelativeW)
}
#endif

var dirname: String {
#if os(Windows)
let dir = string.deletingLastPathComponent
Expand All @@ -445,7 +451,11 @@ private struct UNIXPath: Path {
}

var isAbsolute: Bool {
string.hasPrefix("/")
#if os(Windows)
return UNIXPath.isAbsolutePath(string)
#else
return string.hasPrefix("/")
#endif
}

var basename: String {
Expand Down Expand Up @@ -632,7 +642,7 @@ private struct UNIXPath: Path {
defer { fsr.deallocate() }

let realpath = String(cString: fsr)
if realpath.withCString(encodedAs: UTF16.self, PathIsRelativeW) {
if !UNIXPath.isAbsolutePath(realpath) {
throw PathValidationError.invalidAbsolutePath(path)
}
self.init(normalizingAbsolutePath: path)
Expand All @@ -654,7 +664,7 @@ private struct UNIXPath: Path {
defer { fsr.deallocate() }

let realpath: String = String(cString: fsr)
if !realpath.withCString(encodedAs: UTF16.self, PathIsRelativeW) {
if UNIXPath.isAbsolutePath(realpath) {
throw PathValidationError.invalidRelativePath(path)
}
self.init(normalizingRelativePath: path)
Expand Down
22 changes: 15 additions & 7 deletions swift-tools-support-core/Sources/TSCBasic/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public struct ProcessResult: CustomStringConvertible {
public enum ExitStatus: Equatable {
/// The process was terminated normally with a exit code.
case terminated(code: Int32)

#if !os(Windows)
/// The process was terminated due to a signal.
case signalled(signal: Int32)
#endif
}

/// The arguments with which the process was launched.
Expand Down Expand Up @@ -177,6 +178,8 @@ public final class Process: ObjectIdentifierProtocol {
/// Typealias for process id type.
#if !os(Windows)
public typealias ProcessID = pid_t
#else
public typealias ProcessID = DWORD
#endif

/// Typealias for stdout/stderr output closure.
Expand Down Expand Up @@ -206,6 +209,9 @@ public final class Process: ObjectIdentifierProtocol {
/// The process id of the spawned process, available after the process is launched.
#if os(Windows)
private var _process: Foundation.Process?
public var processID: ProcessID {
return DWORD(_process?.processIdentifier ?? 0)
}
#else
public private(set) var processID = ProcessID()
#endif
Expand Down Expand Up @@ -314,7 +320,7 @@ public final class Process: ObjectIdentifierProtocol {
}
// FIXME: This can be cached.
let envSearchPaths = getEnvSearchPaths(
pathString: ProcessEnv.vars["PATH"],
pathString: ProcessEnv.path,
currentWorkingDirectory: localFileSystem.currentWorkingDirectory
)
// Lookup and cache the executable path.
Expand All @@ -340,14 +346,15 @@ public final class Process: ObjectIdentifierProtocol {
}

// Look for executable.
guard Process.findExecutable(arguments[0]) != nil else {
throw Process.Error.missingExecutableProgram(program: arguments[0])
let executable = arguments[0]
guard let executablePath = Process.findExecutable(executable) else {
throw Process.Error.missingExecutableProgram(program: executable)
}

#if os(Windows)
_process = Foundation.Process()
_process?.arguments = arguments
_process?.executableURL = URL(fileURLWithPath: arguments[0])
_process?.arguments = Array(arguments.dropFirst()) // Avoid including the executable URL twice.
_process?.executableURL = executablePath.asURL
_process?.environment = environment

if outputRedirection.redirectsOutput {
Expand Down Expand Up @@ -752,9 +759,10 @@ extension ProcessResult.Error: CustomStringConvertible {
switch result.exitStatus {
case .terminated(let code):
stream <<< "terminated(\(code)): "

#if !os(Windows)
case .signalled(let signal):
stream <<< "signalled(\(signal)): "
#endif
}

// Strip sandbox information from arguments to keep things pretty.
Expand Down
10 changes: 10 additions & 0 deletions swift-tools-support-core/Sources/TSCBasic/ProcessEnv.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public enum ProcessEnv {
invalidateEnv()
}

/// `PATH` variable in the process's environment (`Path` under Windows).
public static var path: String? {
#if os(Windows)
let pathArg = "Path"
#else
let pathArg = "PATH"
#endif
return vars[pathArg]
}

/// The current working directory of the process.
public static var cwd: AbsolutePath? {
return localFileSystem.currentWorkingDirectory
Expand Down
32 changes: 22 additions & 10 deletions swift-tools-support-core/Sources/TSCBasic/StringConversions.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
Expand All @@ -15,6 +15,11 @@
///
/// - Returns: True if shell escaping is not needed.
private func inShellWhitelist(_ codeUnit: UInt8) -> Bool {
#if os(Windows)
if codeUnit == UInt8(ascii: "\\") {
return true
}
#endif
switch codeUnit {
case UInt8(ascii: "a")...UInt8(ascii: "z"),
UInt8(ascii: "A")...UInt8(ascii: "Z"),
Expand All @@ -38,7 +43,7 @@ private func inShellWhitelist(_ codeUnit: UInt8) -> Bool {
extension String {

/// Creates a shell escaped string. If the string does not need escaping, returns the original string.
/// Otherwise escapes using single quotes. For example:
/// Otherwise escapes using single quotes on Unix and double quotes on Windows. For example:
/// hello -> hello, hello$world -> 'hello$world', input A -> 'input A'
///
/// - Returns: Shell escaped string.
Expand All @@ -49,23 +54,30 @@ extension String {
return self
}

// If there are no single quotes then we can just wrap the string around single quotes.
guard let singleQuotePos = utf8[pos...].firstIndex(of: UInt8(ascii: "'")) else {
return "'" + self + "'"
#if os(Windows)
let quoteCharacter: Character = "\""
let escapedQuoteCharacter = "\"\""
#else
let quoteCharacter: Character = "'"
let escapedQuoteCharacter = "'\\''"
#endif
// If there are no quote characters then we can just wrap the string within the quotes.
guard let quotePos = utf8[pos...].firstIndex(of: quoteCharacter.asciiValue!) else {
return String(quoteCharacter) + self + String(quoteCharacter)
}

// Otherwise iterate and escape all the single quotes.
var newString = "'" + String(self[..<singleQuotePos])
var newString = String(quoteCharacter) + String(self[..<quotePos])

for char in self[singleQuotePos...] {
if char == "'" {
newString += "'\\''"
for char in self[quotePos...] {
if char == quoteCharacter {
newString += escapedQuoteCharacter
} else {
newString += String(char)
}
}

newString += "'"
newString += String(quoteCharacter)

return newString
}
Expand Down
6 changes: 6 additions & 0 deletions swift-tools-support-core/Sources/TSCBasic/TemporaryFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ public func withTemporaryFile<Result>(
let tempFile = try TemporaryFile(dir: dir, prefix: prefix, suffix: suffix)
defer {
if deleteOnClose {
#if os(Windows)
_ = tempFile.path.pathString.withCString(encodedAs: UTF16.self) {
_wunlink($0)
}
#else
unlink(tempFile.path.pathString)
#endif
}
}
return try body(tempFile)
Expand Down
Loading