Skip to content

Commit

Permalink
Support for Swift 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YOCKOW committed Sep 23, 2017
1 parent 4b7dd29 commit d2c2d20
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 22 deletions.
13 changes: 10 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
// swift-tools-version:3.1
// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "TimeSpecification",
swiftLanguageVersions:[3]
name: "TimeSpecification",
products: [.library(name: "TimeSpecification", type:.dynamic, targets: ["TimeSpecification"])],
dependencies: [],
targets: [
.target(name: "TimeSpecification", dependencies: [], path:".", sources:["Sources"]),
.testTarget(name: "TimeSpecificationTests", dependencies: ["TimeSpecification"])
],
swiftLanguageVersions:[3, 4]
)
8 changes: 8 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// swift-tools-version:3.1

import PackageDescription

let package = Package(
name: "TimeSpecification",
swiftLanguageVersions:[3]
)
80 changes: 61 additions & 19 deletions build-install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
See "LICENSE.txt" for more information.
=end

ModuleName = 'TimeSpecification'
ModuleVersion = "0.0.0"

# Requirements #####################################################################################
require 'fileutils'
require 'json'
Expand All @@ -23,14 +26,13 @@
end
SharedLibraryPrefix = 'lib'
SharedLibrarySuffix = (OS == :macOS) ? '.dylib' : '.so'
ModuleName = 'TimeSpecification'
ModuleLinkName = 'Swift' + ModuleName
RootDirectory = Pathname(__FILE__).dirname.expand_path

## Default Values ##
Defaults = {
:swift => Pathname('swift'),
:build_directory => Pathname('./build'),
:build_directory => Pathname('./.build'),
:install => false,
:prefix => Pathname('/usr/local'),
:debug => false,
Expand Down Expand Up @@ -58,7 +60,7 @@
}
### Qualifications ###
UnsavableOptions = [:build_directory, :sdk, :clean]
PathnameOptions = [:ninja, :swift, :build_directory, :prefix]
PathnameOptions = [:swift, :build_directory, :prefix]

# Functions ########################################################################################
## Error ##
Expand Down Expand Up @@ -198,20 +200,21 @@ def exit_if_i_am_file
Options.each_pair {|key, value| Options[key] = Defaults[key] if value.nil? }

# Swift? ###########################################################################################
failed("#{Options[:swift]} is not found.") if !system(%Q[which #{Options[:swift].escaped} >/dev/null])
failed("#{Options[:swift]} is not found.") if !system(%Q[which #{Options[:swift].escaped()} >/dev/null])

# Build! ###########################################################################################
configuration = Options[:debug] ? 'debug' : 'release'

binPath = Pathname(%x[#{Options[:swift].escaped()} build --build-path #{Options[:build_directory].escaped()} --configuration #{configuration} --show-bin-path].chomp)
libFilename = Pathname(SharedLibraryPrefix + ModuleLinkName + SharedLibrarySuffix)
libPath = Options[:build_directory] + Pathname(configuration) + libFilename
libPath = binPath + libFilename
moduleFilename = Pathname(ModuleName + '.swiftmodule')
modulePath = Options[:build_directory] + Pathname(configuration) + moduleFilename
modulePath = binPath + moduleFilename

# Build
if !Options[:skip_build]
puts("[Start Building...]")
try_exec(["swift build --build-path #{Options[:build_directory].escaped()}",
try_exec(["#{Options[:swift].escaped()} build --build-path #{Options[:build_directory].escaped()}",
"--configuration #{configuration}",
"-Xswiftc -emit-library -Xswiftc -o#{libPath.escaped()}",
"-Xswiftc -module-link-name -Xswiftc #{ModuleLinkName}",
Expand All @@ -225,10 +228,10 @@ def exit_if_i_am_file
if !Options[:skip_test]
puts("[Start Testing...]")
if !Options[:debug]
$stderr.puts("** WARNING ** No tests will be executed when `release` mode is specified.\n")
$stderr.puts("** WARNING ** No tests will be executed unless debug mode is specified.")
else
try_exec(["swift test --build-path #{Options[:build_directory].escaped()}",
"--configuration #{configuration}"].join(" "), 2)
try_exec(["#{Options[:swift].escaped()} test --build-path #{Options[:build_directory].escaped()}",
"--configuration #{configuration}"].join(" "), 2)
end
puts()
end
Expand All @@ -241,14 +244,53 @@ def exit_if_i_am_file
$stderr.puts("** WARNING ** DEBUG MODE. Products to be installed may not be optimized.\n")
end

libInstallDirPath = Options[:prefix] + Pathname('lib')
libInstallPath = libInstallDirPath + libFilename
moduleInstallDirPath = Options[:prefix] + Pathname('include')
moduleInstallPath = moduleInstallDirPath + moduleFilename

try_exec(["mkdir -p #{libInstallDirPath.escaped()} &&",
"cp #{libPath.escaped()} #{libInstallPath.escaped()} &&",
"mkdir -p #{moduleInstallDirPath.escaped()} &&",
"cp #{modulePath.escaped()} #{moduleInstallPath.escaped()}"].join(" "), 2)
if ModuleVersion =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:\-(.+))?/
majorVersion = $1
minorVersion = $2
patchVersion = $3
prereleaseIdentifiers = $4

suffixes = [
".#{majorVersion}.#{minorVersion}",
".#{majorVersion}",
""
]
if prereleaseIdentifiers
suffixes.unshift(".#{majorVersion}.#{minorVersion}.#{patchVersion}")
end

libInstallDirPath = Options[:prefix] + Pathname('lib')
moduleInstallDirPath = Options[:prefix] + Pathname('include')
originalLibFilename = Pathname(SharedLibraryPrefix + ModuleLinkName + SharedLibrarySuffix + '.' + ModuleVersion)
originalModuleFilename = Pathname(ModuleName + '.swiftmodule' + '.' + ModuleVersion)
originalLibInstallPath = libInstallDirPath + originalLibFilename
originalModuleInstallPath = moduleInstallDirPath + originalModuleFilename

try_exec("mkdir -p #{libInstallDirPath.escaped()}", 2)
try_exec("rm -f #{originalLibInstallPath.escaped()}", 2)
try_exec("cp -f #{libPath.escaped()} #{originalLibInstallPath.escaped()}", 2)
try_exec("mkdir -p #{moduleInstallDirPath.escaped()}", 2)
try_exec("rm -f #{originalModuleInstallPath.escaped()}", 2)
try_exec("cp -f #{modulePath.escaped()} #{originalModuleInstallPath.escaped()}", 2)

suffixes.each_with_index{|suffix, ii|
sourceSuffix = (ii == 0) ? ('.' + ModuleVersion) : suffixes[ii - 1]

libSourceFilename = Pathname(SharedLibraryPrefix + ModuleLinkName + SharedLibrarySuffix + sourceSuffix)
moduleSourceFilename = Pathname(ModuleName + '.swiftmodule' + sourceSuffix)
libDestFilename = Pathname(SharedLibraryPrefix + ModuleLinkName + SharedLibrarySuffix + suffix)
moduleDestFilename = Pathname(ModuleName + '.swiftmodule' + suffix)

libSourcePath = libInstallDirPath + libSourceFilename
moduleSourcePath = moduleInstallDirPath + moduleSourceFilename
libDestPath = libInstallDirPath + libDestFilename
moduleDestPath = moduleInstallDirPath + moduleDestFilename

try_exec("ln -fs #{libSourcePath.escaped()} #{libDestPath.escaped}", 2)
try_exec("ln -fs #{moduleSourcePath.escaped()} #{moduleDestPath.escaped}", 2)
}
else
$stderr.puts("Invalid Version")
end
end

0 comments on commit d2c2d20

Please sign in to comment.