2019-02-07 03:04:17 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-12-15 19:15:03 +08:00
|
|
|
SWIFTDOC_VERSION = "1.0.0-beta.5"
|
|
|
|
SWIFTLINT_VERSION = "0.40.2"
|
2020-09-16 15:06:54 +08:00
|
|
|
|
2020-12-27 02:03:25 +08:00
|
|
|
require 'rake/testtask'
|
2018-12-03 16:37:36 +08:00
|
|
|
require 'rubygems'
|
|
|
|
require 'cucumber'
|
|
|
|
require 'cucumber/rake/task'
|
2019-02-07 01:40:40 +08:00
|
|
|
require 'mkmf'
|
2019-06-21 04:25:50 +08:00
|
|
|
require 'fileutils'
|
|
|
|
require "google/cloud/storage"
|
|
|
|
require "encrypted/environment"
|
|
|
|
require 'colorize'
|
2019-09-20 05:46:10 +08:00
|
|
|
require 'highline'
|
2019-10-08 21:14:31 +08:00
|
|
|
require 'tmpdir'
|
2020-07-14 23:32:15 +08:00
|
|
|
require 'json'
|
2020-09-16 15:06:54 +08:00
|
|
|
require 'zip'
|
2020-11-08 23:12:01 +08:00
|
|
|
require 'macho'
|
2018-12-03 16:37:36 +08:00
|
|
|
|
2020-12-27 02:03:25 +08:00
|
|
|
desc("Runs the Fourier tests")
|
|
|
|
Rake::TestTask.new do |t|
|
|
|
|
t.name = "test_fourier"
|
|
|
|
t.libs += [File.expand_path('./tools/fourier/test', __dir__)]
|
|
|
|
test_root = File.expand_path('./tools/fourier/test', __dir__)
|
|
|
|
t.test_files = FileList[File.join(test_root, '**', '*_test.rb')]
|
|
|
|
t.verbose = false
|
|
|
|
t.warning = false
|
|
|
|
end
|
|
|
|
|
2020-09-16 15:06:54 +08:00
|
|
|
desc("Updates swift-doc binary with the latest version available.")
|
|
|
|
task :swift_doc_update do
|
2020-09-25 17:54:33 +08:00
|
|
|
root_dir = File.expand_path(__dir__)
|
2020-09-16 15:06:54 +08:00
|
|
|
Dir.mktmpdir do |temporary_dir|
|
|
|
|
Dir.chdir(temporary_dir) do
|
|
|
|
system("curl", "-LO", "https://github.com/SwiftDocOrg/swift-doc/archive/#{SWIFTDOC_VERSION}.zip")
|
|
|
|
extract_zip("#{SWIFTDOC_VERSION}.zip", "swift-doc")
|
|
|
|
Dir.chdir("swift-doc/swift-doc-#{SWIFTDOC_VERSION}") do
|
|
|
|
system("make", "swift-doc")
|
|
|
|
end
|
2020-11-08 23:12:01 +08:00
|
|
|
release_dir = File.join(temporary_dir, "swift-doc/swift-doc-#{SWIFTDOC_VERSION}/.build/release/")
|
|
|
|
vendor_dir = File.join(root_dir, "vendor")
|
|
|
|
dst_binary_path = File.join(vendor_dir, "swift-doc")
|
|
|
|
bundle_paths = Dir[File.join(release_dir, "*.bundle")]
|
2020-12-15 19:15:03 +08:00
|
|
|
|
2020-11-08 23:12:01 +08:00
|
|
|
# Copy binary and bundles
|
|
|
|
binary_path = File.join(release_dir, "swift-doc")
|
|
|
|
File.delete(dst_binary_path) if File.exist?(dst_binary_path)
|
|
|
|
FileUtils.cp(binary_path, dst_binary_path)
|
|
|
|
bundle_paths.each do |bundle_path|
|
|
|
|
bundle_dst_path = File.join(vendor_dir, File.basename(bundle_path))
|
|
|
|
FileUtils.rm_rf(bundle_dst_path) if File.exist?(bundle_dst_path)
|
|
|
|
FileUtils.cp_r(bundle_path, bundle_dst_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Change the reference to lib_InternalSwiftSyntaxParser.dylib
|
|
|
|
# https://github.com/SwiftDocOrg/homebrew-formulae/blob/master/Formula/swift-doc.rb#L43
|
|
|
|
macho = MachO.open(dst_binary_path)
|
2020-12-15 19:15:03 +08:00
|
|
|
break unless (toolchain = macho.rpaths.find { |path| path.include?(".xctoolchain") })
|
2020-11-08 23:12:01 +08:00
|
|
|
syntax_parser_dylib_name = "lib_InternalSwiftSyntaxParser.dylib"
|
|
|
|
FileUtils.cp(File.join(toolchain, syntax_parser_dylib_name), File.join(vendor_dir, syntax_parser_dylib_name))
|
|
|
|
|
|
|
|
# Write version
|
|
|
|
File.write(File.join(root_dir, "vendor/.swiftdoc.version"), SWIFTDOC_VERSION)
|
2020-09-16 15:06:54 +08:00
|
|
|
end
|
|
|
|
end
|
2020-09-25 17:54:33 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
desc("Updates swift-lint binary with the latest version available.")
|
|
|
|
task :swift_lint_update do
|
|
|
|
root_dir = File.expand_path(__dir__)
|
|
|
|
Dir.mktmpdir do |temporary_dir|
|
|
|
|
Dir.chdir(temporary_dir) do
|
2020-12-15 19:15:03 +08:00
|
|
|
system("curl", "-LO",
|
|
|
|
"https://github.com/realm/SwiftLint/releases/download/#{SWIFTLINT_VERSION}/portable_swiftlint.zip")
|
2020-09-25 17:54:33 +08:00
|
|
|
extract_zip("portable_swiftlint.zip", "portable_swiftlint")
|
|
|
|
system("cp", "portable_swiftlint/swiftlint", "#{root_dir}/vendor/swiftlint")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
File.write(File.join(root_dir, "vendor/.swiftlint.version"), SWIFTLINT_VERSION)
|
2020-09-16 15:06:54 +08:00
|
|
|
end
|
|
|
|
|
2019-03-08 01:22:00 +08:00
|
|
|
desc("Formats the code style")
|
|
|
|
task :style_correct do
|
2020-08-05 03:56:47 +08:00
|
|
|
system(swiftlint_path, "autocorrect")
|
2020-08-05 20:57:06 +08:00
|
|
|
system(swiftformat_path, ".")
|
2019-02-07 01:40:40 +08:00
|
|
|
end
|
|
|
|
|
2020-01-18 09:56:45 +08:00
|
|
|
desc("Swift format check")
|
|
|
|
task :swift_format do
|
2020-08-05 03:56:47 +08:00
|
|
|
Kernel.system(swiftformat_path, "--lint", ".") || abort
|
|
|
|
end
|
|
|
|
|
|
|
|
desc("Swift lint check")
|
|
|
|
task :swift_lint do
|
|
|
|
Kernel.system(swiftlint_path) || abort
|
2020-01-18 09:56:45 +08:00
|
|
|
end
|
|
|
|
|
2019-02-07 03:04:17 +08:00
|
|
|
desc("Lints the Ruby code style")
|
|
|
|
task :style_ruby do
|
2019-03-08 01:22:00 +08:00
|
|
|
system("bundle", "exec", "rubocop")
|
2019-02-07 03:04:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
desc("Corrects the issues with the Ruby style")
|
|
|
|
task :style_ruby_correct do
|
2019-03-08 01:22:00 +08:00
|
|
|
system("bundle", "exec", "rubocop", "-a")
|
2019-02-07 03:04:17 +08:00
|
|
|
end
|
2019-02-07 01:40:40 +08:00
|
|
|
|
2020-09-25 17:45:22 +08:00
|
|
|
desc("Builds and archive a release version of tuist and tuistenv for local testing.")
|
|
|
|
task :local_package do
|
|
|
|
package
|
|
|
|
end
|
|
|
|
|
2019-09-20 05:46:10 +08:00
|
|
|
desc("Builds, archives, and publishes tuist and tuistenv for release")
|
2020-12-15 19:15:03 +08:00
|
|
|
task :release, [:version] do |_task, options|
|
2019-06-21 04:25:50 +08:00
|
|
|
decrypt_secrets
|
2020-11-01 16:19:09 +08:00
|
|
|
release(options[:version])
|
2019-09-20 05:46:10 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
desc("Publishes the installation scripts")
|
|
|
|
task :release_scripts do
|
|
|
|
decrypt_secrets
|
|
|
|
release_scripts
|
2019-06-21 04:25:50 +08:00
|
|
|
end
|
|
|
|
|
2020-03-27 20:53:40 +08:00
|
|
|
desc("Packages tuist, tags it with the commit sha and uploads it to gcs")
|
|
|
|
task :package_commit do
|
|
|
|
decrypt_secrets
|
|
|
|
package
|
|
|
|
|
|
|
|
bucket = storage.bucket("tuist-builds")
|
|
|
|
|
|
|
|
sha = %x(git rev-parse HEAD).strip.chomp
|
|
|
|
print_section("Uploading tuist-#{sha}")
|
|
|
|
file = bucket.create_file(
|
|
|
|
"build/tuist.zip",
|
|
|
|
"#{sha}.zip"
|
|
|
|
)
|
|
|
|
|
|
|
|
file.acl.public!
|
|
|
|
print_section("Uploaded 🚀")
|
|
|
|
end
|
|
|
|
|
2019-06-21 04:25:50 +08:00
|
|
|
desc("Encrypt secret keys")
|
|
|
|
task :encrypt_secrets do
|
|
|
|
Encrypted::Environment.encrypt_ejson("secrets.ejson", private_key: ENV["SECRET_KEY"])
|
|
|
|
end
|
|
|
|
|
2020-07-14 23:32:15 +08:00
|
|
|
desc("Benchmarks tuist against a specified versiom")
|
|
|
|
task :benchmark do
|
|
|
|
print_section("🛠 Building supporting tools")
|
|
|
|
|
|
|
|
# Build tuistbench
|
|
|
|
system(
|
2020-12-15 19:15:03 +08:00
|
|
|
"swift", "build",
|
|
|
|
"-c", "release",
|
2020-07-14 23:32:15 +08:00
|
|
|
"--package-path", "tools/tuistbench"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Build fixturegen
|
|
|
|
system(
|
2020-12-15 19:15:03 +08:00
|
|
|
"swift", "build",
|
|
|
|
"-c", "release",
|
2020-07-14 23:32:15 +08:00
|
|
|
"--package-path", "tools/fixturegen"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Generate large fixture
|
|
|
|
print_section("📁 Generating fixtures ...")
|
|
|
|
FileUtils.mkdir_p("generated_fixtures")
|
|
|
|
|
|
|
|
system(
|
|
|
|
"tools/fixturegen/.build/release/fixturegen",
|
|
|
|
"--path", "generated_fixtures/50_projects",
|
|
|
|
"--projects", "50",
|
|
|
|
)
|
|
|
|
|
|
|
|
system(
|
|
|
|
"tools/fixturegen/.build/release/fixturegen",
|
|
|
|
"--path", "generated_fixtures/2000_sources",
|
|
|
|
"--projects", "2",
|
|
|
|
"--sources", "2000",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Generate fixture list
|
|
|
|
fixtures = {
|
|
|
|
"paths" => [
|
|
|
|
"generated_fixtures/50_projects",
|
|
|
|
"generated_fixtures/2000_sources",
|
|
|
|
"fixtures/ios_app_with_static_frameworks",
|
|
|
|
"fixtures/ios_app_with_framework_and_resources",
|
|
|
|
"fixtures/ios_app_with_transitive_framework",
|
|
|
|
"fixtures/ios_app_with_xcframeworks",
|
2020-12-15 19:15:03 +08:00
|
|
|
],
|
2020-07-14 23:32:15 +08:00
|
|
|
}
|
2020-12-15 19:15:03 +08:00
|
|
|
File.open(".fixtures.generated.json", "w") do |f|
|
2020-07-14 23:32:15 +08:00
|
|
|
f.write(fixtures.to_json)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Build current version of tuist
|
|
|
|
print_section("🔨 Building release version of tuist ...")
|
|
|
|
system("swift", "build", "--product", "tuist", "--configuration", "release")
|
|
|
|
system("swift", "build", "--product", "tuistenv", "--configuration", "release")
|
|
|
|
system("swift", "build", "--product", "ProjectDescription", "--configuration", "release")
|
|
|
|
|
|
|
|
# Download latest tuist
|
|
|
|
print_section("⬇️ Downloading latest published version of tuist ...")
|
|
|
|
|
|
|
|
system(".build/release/tuistenv", "update")
|
|
|
|
puts("Reference tuist version:")
|
|
|
|
system(".build/release/tuistenv", "version")
|
|
|
|
|
|
|
|
print_section("⏱ Benchmarking ...")
|
|
|
|
system(
|
2020-12-15 19:15:03 +08:00
|
|
|
"tools/tuistbench/.build/release/tuistbench",
|
2020-07-14 23:32:15 +08:00
|
|
|
"-b", ".build/release/tuist",
|
|
|
|
"-r", ".build/release/tuistenv",
|
|
|
|
"-l", ".fixtures.generated.json",
|
|
|
|
"--format", "markdown"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-08-05 03:56:47 +08:00
|
|
|
def swiftformat_path
|
|
|
|
File.expand_path("bin/swiftformat", __dir__)
|
|
|
|
end
|
|
|
|
|
|
|
|
def swiftlint_path
|
|
|
|
File.expand_path("bin/swiftlint", __dir__)
|
|
|
|
end
|
|
|
|
|
2019-06-21 04:25:50 +08:00
|
|
|
def decrypt_secrets
|
|
|
|
Encrypted::Environment.load_from_ejson("secrets.ejson", private_key: ENV["SECRET_KEY"])
|
|
|
|
end
|
|
|
|
|
2019-09-20 05:46:10 +08:00
|
|
|
def release_scripts
|
|
|
|
bucket = storage.bucket("tuist-releases")
|
|
|
|
print_section("Uploading installation scripts to the tuist-releases bucket on GCS")
|
2019-09-30 16:42:00 +08:00
|
|
|
bucket.create_file("script/install", "scripts/install").acl.public!
|
|
|
|
bucket.create_file("script/uninstall", "scripts/uninstall").acl.public!
|
2019-09-20 05:46:10 +08:00
|
|
|
end
|
|
|
|
|
2019-06-21 04:25:50 +08:00
|
|
|
def package
|
|
|
|
print_section("Building tuist")
|
|
|
|
FileUtils.mkdir_p("build")
|
|
|
|
system("swift", "build", "--product", "tuist", "--configuration", "release")
|
2019-11-19 18:51:45 +08:00
|
|
|
system(
|
|
|
|
"swift", "build",
|
|
|
|
"--product", "ProjectDescription",
|
|
|
|
"--configuration", "release",
|
|
|
|
"-Xswiftc", "-enable-library-evolution",
|
|
|
|
"-Xswiftc", "-emit-module-interface",
|
|
|
|
"-Xswiftc", "-emit-module-interface-path",
|
|
|
|
"-Xswiftc", ".build/release/ProjectDescription.swiftinterface"
|
|
|
|
)
|
2019-06-21 04:25:50 +08:00
|
|
|
system("swift", "build", "--product", "tuistenv", "--configuration", "release")
|
2020-12-15 19:15:03 +08:00
|
|
|
|
2020-03-27 22:01:40 +08:00
|
|
|
build_templates_path = File.join(__dir__, ".build/release/Templates")
|
2020-09-17 18:03:27 +08:00
|
|
|
vendor_path = File.join(__dir__, ".build/release/vendor")
|
|
|
|
|
2020-03-27 22:01:40 +08:00
|
|
|
FileUtils.rm_rf(build_templates_path) if File.exist?(build_templates_path)
|
|
|
|
FileUtils.cp_r(File.expand_path("Templates", __dir__), build_templates_path)
|
2020-09-17 18:03:27 +08:00
|
|
|
FileUtils.cp_r(File.expand_path("vendor", __dir__), vendor_path)
|
2020-03-27 22:01:40 +08:00
|
|
|
|
|
|
|
File.delete("tuist.zip") if File.exist?("tuist.zip")
|
|
|
|
File.delete("tuistenv.zip") if File.exist?("tuistenv.zip")
|
2019-06-21 04:25:50 +08:00
|
|
|
|
|
|
|
Dir.chdir(".build/release") do
|
2019-09-19 05:55:46 +08:00
|
|
|
system(
|
|
|
|
"zip", "-q", "-r", "--symlinks",
|
|
|
|
"tuist.zip", "tuist",
|
2020-12-15 19:15:03 +08:00
|
|
|
"ProjectDescription.swiftmodule",
|
|
|
|
"ProjectDescription.swiftdoc",
|
|
|
|
"libProjectDescription.dylib",
|
|
|
|
"ProjectDescription.swiftinterface",
|
2020-09-16 15:06:54 +08:00
|
|
|
"Templates",
|
2020-09-17 18:03:27 +08:00
|
|
|
"vendor"
|
2019-09-19 05:55:46 +08:00
|
|
|
)
|
2019-06-21 04:25:50 +08:00
|
|
|
system("zip", "-q", "-r", "--symlinks", "tuistenv.zip", "tuistenv")
|
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.cp(".build/release/tuist.zip", "build/tuist.zip")
|
|
|
|
FileUtils.cp(".build/release/tuistenv.zip", "build/tuistenv.zip")
|
|
|
|
end
|
|
|
|
|
2020-11-01 16:19:09 +08:00
|
|
|
def release(version)
|
2020-12-15 19:15:03 +08:00
|
|
|
if version.nil?
|
2020-11-01 16:19:09 +08:00
|
|
|
version = cli.ask("Introduce the released version:")
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "Releasing #{version} 🚀"
|
2019-09-20 05:46:10 +08:00
|
|
|
|
|
|
|
package
|
|
|
|
|
|
|
|
bucket = storage.bucket("tuist-releases")
|
|
|
|
|
|
|
|
print_section("Uploading to the tuist-releases bucket on GCS")
|
|
|
|
|
|
|
|
bucket.create_file("build/tuist.zip", "#{version}/tuist.zip").acl.public!
|
|
|
|
bucket.create_file("build/tuistenv.zip", "#{version}/tuistenv.zip").acl.public!
|
|
|
|
|
|
|
|
bucket.create_file("build/tuist.zip", "latest/tuist.zip").acl.public!
|
|
|
|
bucket.create_file("build/tuistenv.zip", "latest/tuistenv.zip").acl.public!
|
2019-10-08 21:14:31 +08:00
|
|
|
Dir.mktmpdir do |tmp_dir|
|
|
|
|
version_path = File.join(tmp_dir, "version")
|
|
|
|
File.write(version_path, version)
|
|
|
|
bucket.create_file(version_path, "latest/version").acl.public!
|
|
|
|
end
|
2019-09-20 05:46:10 +08:00
|
|
|
end
|
|
|
|
|
2019-03-08 01:22:00 +08:00
|
|
|
def system(*args)
|
|
|
|
Kernel.system(*args) || abort
|
2019-03-08 22:20:12 +08:00
|
|
|
end
|
2019-06-21 04:25:50 +08:00
|
|
|
|
2019-09-20 05:46:10 +08:00
|
|
|
def cli
|
|
|
|
@cli ||= HighLine.new
|
|
|
|
end
|
|
|
|
|
2019-06-21 04:25:50 +08:00
|
|
|
def storage
|
|
|
|
@storage ||= Google::Cloud::Storage.new(
|
|
|
|
project_id: ENV["GCS_PROJECT_ID"],
|
|
|
|
credentials: {
|
|
|
|
type: ENV["GCS_TYPE"],
|
|
|
|
project_id: ENV["GCS_PROJECT_ID"],
|
|
|
|
private_key_id: ENV["GCS_PRIVATE_KEY_ID"],
|
|
|
|
private_key: ENV["GCS_PRIVATE_KEY"],
|
|
|
|
client_email: ENV["GCS_CLIENT_EMAIL"],
|
|
|
|
client_id: ENV["GCS_CLIENT_ID"],
|
|
|
|
auth_uri: ENV["GCS_AUTH_URI"],
|
|
|
|
token_uri: ENV["GCS_TOKEN_URI"],
|
|
|
|
auth_provider_x509_cert_url: ENV["GCS_AUTH_PROVIDER_X509_CERT_URL"],
|
|
|
|
client_x509_cert_url: ENV["GCS_CLIENT_X509_CERT_URL"],
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def print_section(text)
|
2020-06-05 20:04:08 +08:00
|
|
|
puts(text.bold.green)
|
2019-06-21 04:25:50 +08:00
|
|
|
end
|
2020-09-16 15:06:54 +08:00
|
|
|
|
|
|
|
def extract_zip(file, destination)
|
|
|
|
FileUtils.mkdir_p(destination)
|
|
|
|
|
|
|
|
Zip::File.open(file) do |zip_file|
|
|
|
|
zip_file.each do |f|
|
|
|
|
fpath = File.join(destination, f.name)
|
|
|
|
zip_file.extract(f, fpath) unless File.exist?(fpath)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|