Skip to content

Commit

Permalink
only copy build artifacts (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonaskolb authored Dec 1, 2022
1 parent af4e0b5 commit 751840e
Showing 1 changed file with 29 additions and 11 deletions.
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

0 comments on commit 751840e

Please sign in to comment.