require_relative 'wire-library/wire-runtime-swift/pod_helpers.rb'

Pod::Spec.new do |s|
  version = get_version

  s.name          = 'WireCompiler'
  s.version       = version
  s.license       = { :type => 'apache2', :file => 'LICENSE.txt' }
  s.homepage      = 'https://github.com/square/wire'
  s.authors       = { 'Eric Firestone' => '@firetweet' }
  s.summary       = 'gRPC and protocol buffer compiler for Android, Kotlin, Java, and Swift.'
  s.source        = { :git => 'https://github.com/square/wire.git', :tag => version }
  s.module_name   = 'WireCompiler'

  s.prepare_command = <<-CMD
    ./gradlew -p wire-library :wire-compiler:assemble
    cp ./wire-library/wire-compiler/build/libs/wire-compiler-*-jar-with-dependencies.jar ./compiler.jar
  CMD

  s.preserve_paths = 'compiler.jar'
end

require_relative 'wire-library/wire-runtime-swift/pod_helpers.rb'

Pod::Spec.new do |s|
  version = get_version

  s.name          = 'WireCompiler'
  s.version       = version
  s.license       = { :type => 'apache2', :file => 'LICENSE.txt' }
  s.homepage      = 'https://github.com/square/wire'
  s.authors       = { 'Eric Firestone' => '@firetweet' }
  s.summary       = 'gRPC and protocol buffer compiler for Android, Kotlin, Java, and Swift.'
  s.source        = { :git => 'https://github.com/square/wire.git', :tag => version }
  s.module_name   = 'WireCompiler'

  s.prepare_command = <<-CMD
    ./gradlew -p wire-library :wire-compiler:assemble
    MOST_RECENT_ARTIFACT="$(ls -t ./wire-library/wire-compiler/build/libs/wire-compiler-*-jar-with-dependencies.jar | head -n1)"
    cp "$MOST_RECENT_ARTIFACT" ./compiler.jar
  CMD

  s.preserve_paths = 'compiler.jar'
end

Copy a specific compiler artifact in Swift
Copy a specific compiler artifact in Swift

Previously the copy would fail if there happened to be multiple artifacts in the build directory because `cp` with a glob-star fails if it matches multiple sources with a single destination. Instead we now copy the most recently modified artifact. We don't use the `version` variable because it's possible that the Podspec's version is different from the version of the Gradle artifact.
