JohnSundell / Marathon

[DEPRECATED] Marathon makes it easy to write, run and manage your Swift scripts ๐Ÿƒ
MIT License
1.86k stars 78 forks source link

Build Folder Missing key 'Object' #136

Closed ghost closed 6 years ago

ghost commented 7 years ago

Output

Roberts-iMac:Desktop robertnash$ marathon run /Users/robertnash/Code/Scripts/imageResize.swift 1.png 200 300 --verbose
๐Ÿƒ  $ cd "/Users/robertnash/.marathon/Scripts/Cache/-Users-robertnash-Code-Scripts-imageResize/" && readlink OriginalFile
   /Users/robertnash/Code/Scripts/imageResize.swift
   $ cd "/Users/robertnash/Desktop/" && /usr/bin/env xcrun --sdk macosx swift --version
   Apple Swift version 4.0 (swiftlang-900.0.65 clang-900.0.37)
   Target: x86_64-apple-macosx10.9
   $ cd "/Users/robertnash/.marathon/Scripts/Cache/-Users-robertnash-Code-Scripts-imageResize/" && /usr/bin/env xcrun --sdk macosx swift build -C /Users/robertnash/.marathon/Scripts/Cache/-Users-robertnash-Code-Scripts-imageResize/ --enable-prefetching 
   /bin/bash: line 1:   872 Illegal instruction: 4  /usr/bin/env xcrun --sdk macosx swift build -C /Users/robertnash/.marathon/Scripts/Cache/-Users-robertnash-Code-Scripts-imageResize/ --enable-prefetching
๐Ÿ’ฅ  Failed to compile script

Contents of /Users/robertnash/Code/Scripts/imageResize.swift Found here: https://github.com/JohnSundell/Marathon-Examples/tree/master/ImageResize

// marathon run ~/scripts/imageResize myImage.png 200 300

import Foundation
import CoreGraphics

// MARK: - Extensions
private extension CGContext {
    static func make(width: Int, height: Int) -> CGContext {
        return CGContext(
            data: nil,
            width: width,
            height: height,
            bitsPerComponent: 8,
            bytesPerRow: 0,
            space: CGColorSpaceCreateDeviceRGB(),
            bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue
        )!
    }
}

// MARK: - Parsing arguments
let arguments = CommandLine.arguments

guard arguments.count > 3 else {
    print("๐Ÿ‘ฎ  Expected 3 arguments: image path, target width & target height")
    exit(1)
}

let imagePath = arguments[1]

guard let targetWidth = Int(arguments[2]) else {
    print("๐Ÿ‘ฎ  '\(arguments[2])' is not a valid width")
    exit(1)
}

guard let targetHeight = Int(arguments[3]) else {
    print("๐Ÿ‘ฎ  '\(arguments[2])' is not a valid height")
    exit(1)
}

// MARK: - Performing image resize
let imageURL = URL(fileURLWithPath: imagePath)

guard let imageSource = CGImageSourceCreateWithURL(imageURL as CFURL, nil),
      let image = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) else {
    print("๐Ÿ’ฅ  Cannot find image at '\(imagePath)'")
    exit(1)
}

let context = CGContext.make(width: targetWidth, height: targetHeight)
context.draw(image, in: CGRect(x: 0, y: 0, width: targetWidth, height: targetHeight))

guard let resizedImage = context.makeImage() else {
    print("๐Ÿ’ฅ  Failed to resize image")
    exit(1)
}

// MARK: - Writing out resized image
let imageData = CFDataCreateMutable(nil, 0)!
let imageDestination = CGImageDestinationCreateWithData(imageData, kUTTypePNG, 1, nil)!
CGImageDestinationAddImage(imageDestination, resizedImage, nil)
CGImageDestinationFinalize(imageDestination)

try (imageData as Data).write(to: imageURL)

Further investigation cd marathon swift package generate-xcodeproj run

๐Ÿƒ  $ cd "/Users/robertnash/.marathon/Scripts/Cache/-Users-robertnash-Code-Scripts-imageResize/" && readlink OriginalFile
   /Users/robertnash/Code/Scripts/imageResize.swift
   $ cd "/Users/robertnash/Library/Developer/Xcode/DerivedData/Marathon-ehwqhwnfkzwydncqgjnzbxeyrven/Build/Products/Debug/" && /usr/bin/env xcrun --sdk macosx swift --version
   Apple Swift version 4.0 (swiftlang-900.0.65 clang-900.0.37)
   Target: x86_64-apple-macosx10.9
   $ cd "/Users/robertnash/.marathon/Scripts/Cache/-Users-robertnash-Code-Scripts-imageResize/" && /usr/bin/env xcrun --sdk macosx swift package generate-xcodeproj
   warning: unable to restore checkouts state: unable to restore state from /Users/robertnash/.marathon/Scripts/Cache/-Users-robertnash-Code-Scripts-imageResize/.build/repositories/checkouts-state.json; missingKey("object")
   Fetching https://github.com/JohnSundell/ShellOut.git
   Fetching https://github.com/JohnSundell/Files.git
   /bin/bash: line 1:  6391 Illegal instruction: 4  /usr/bin/env xcrun --sdk macosx swift package generate-xcodeproj

Contents of /Users/robertnash/.marathon/Scripts/Cache/-Users-robertnash-Code-Scripts-imageResize/.build/repositories/checkouts-state.json

{
  "repositories": [
    {
      "handle": {
        "repositoryURL": "https://github.com/JohnSundell/Files.git",
        "status": "available",
        "subpath": "Files.git-6739420172119258925"
      },
      "key": "https://github.com/JohnSundell/Files.git"
    },
    {
      "handle": {
        "repositoryURL": "https://github.com/JohnSundell/ShellOut.git",
        "status": "available",
        "subpath": "ShellOut.git--4208804319273938067"
      },
      "key": "https://github.com/JohnSundell/ShellOut.git"
    }
  ],
  "version": 1
}
ghost commented 6 years ago

Pulled latest code. Run 'make'. Successful installation but one warning.

warning: unable to restore checkouts state: unable to restore state from /Users/robertnash/Code/Marathon/.build/repositories/checkouts-state.json; missingKey("object")

I will delete the build folder and install from fresh.

ghost commented 6 years ago

Deleted build folder. I no longer get this issue.