Skip to content
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

Only copy required build artifacts #253

Merged
merged 1 commit into from
Dec 1, 2022
Merged
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
40 changes: 29 additions & 11 deletions Sources/MintKit/Mint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,14 @@ public class Mint {
stdOutOnError: true,
error: .packageBuildError(package))

let packageBuildPath = packageCheckoutPath + ".build/release"
let packageInstallPath = packagePath.installPath

// clear the install directory
try? packagePath.installPath.delete()
try packagePath.installPath.mkpath()
try? packageInstallPath.delete()
try packageInstallPath.mkpath()

try copyReleaseProduct(packagePath: packagePath, packageCheckoutPath: packageCheckoutPath)
try copyBuildArtifacts(from: packageBuildPath, to: packagePath.installPath, executables: executables)

let resourcesFile = packageCheckoutPath + "Package.resources"
if resourcesFile.exists {
Expand Down Expand Up @@ -393,16 +396,31 @@ public class Mint {
return true
}

private func copyReleaseProduct(packagePath: PackagePath, packageCheckoutPath: Path) throws {
let packageReleasePath = packageCheckoutPath + ".build/release"
if !packageReleasePath.exists {
throw MintError.invalidExecutable(packageReleasePath.string)
private func copyBuildArtifacts(from buildPath: Path, to installPath: Path, executables: [String]) throws {
var pathsToCopy: [Path] = []
for executable in executables {
let executablePath = buildPath + executable
if !executablePath.exists {
throw MintError.invalidExecutable(executablePath.lastComponent)
}
pathsToCopy.append(executablePath)
}
if verbose {
standardOut.print("Copying \(packageReleasePath.string) to \(packagePath.installPath)")

let copiedExtensions: Set = ["bundle", "resources", "dylib"]
for path in try buildPath.children() {
if let ext = path.extension, copiedExtensions.contains(ext) {
pathsToCopy.append(path)
}
}

for path in pathsToCopy {
let destinationPath = installPath + path.lastComponent
if verbose {
standardOut.print("Copying \(path) to \(destinationPath)")
}
// copy using shell instead of FileManager via PathKit because it removes executable permissions on Linux
try Task.run(bash: "cp -R \(path.string) \(destinationPath.string)")
}
// copy using shell instead of FileManager via PathKit because it removes executable permissions on Linux
try Task.run(bash: "cp -R \(packageReleasePath.string)/* \(packagePath.installPath.string)")
}

private func checkLinkPath() {
Expand Down