ruby - 安装 ImageMagick 并在应用图标覆盖时再次启动你的车道错误

标签 ruby xcode ruby-on-rails-3 xcode-server

为了提供一些背景信息,我目前正在使用一个名为 badge 的程序将图标覆盖应用于我的应用程序图标。在我的计算机上本地运行良好,但是当我在集成之前在 xcode bot 中运行命令徽章时,出现以下错误:

Install ImageMagick and start your lane again!

我已经在 _xcsbuildd(Xcode 服务器)用户上多次运行 brew update && brew install imagemagick 命令来安装 ImageMagick,但我仍然遇到错误。查看/Library/Ruby/Gems/2.0.0/gems/badge-0.7.1/lib/badge目录下的runner.rb文件,找到代码抛出异常。我有 Unresolved 问题,希望能给我下一个调试数据点。

1.) require require 'fastimage' require 'timeout' require 'mini_magick' 在文件系统中指向哪里?有什么方法可以在调用时回显位置,以便我确认它在正确的目录中吗?

2.) 看起来 runner.rb 有一个名为 check_imagemagick! 的方法来确定是否安装了 imagemagick 如果我要做出有根据的猜测..有人可以解释一下这个逻辑在做什么?

return if `which convert`.include?('convert')
return if `which gm`.include?('gm')

这是来自 runner.rb 文件的完整代码:

require 'fastimage'
require 'timeout'
require 'mini_magick'

module Badge
  class Runner
    @@retry_count = Badge.shield_io_retries

    def run(path, options)

      check_imagemagick!
      glob = "/**/*.appiconset/*.{png,PNG}"
      glob = options[:glob] if options[:glob]

      UI.message "FP:" + glob

      UI.message "P:" + path

      app_icons = Dir.glob("#{path}#{glob}")
      UI.verbose "Verbose active...".blue
      UI.verbose "Parameters: #{options.inspect}".blue

      alpha_channel = false
      if options[:alpha_channel]
        alpha_channel = true
      end

      if app_icons.count > 0
        UI.message "Start adding badges...".green

        shield = nil
        response_error = false
        begin
          timeout = Badge.shield_io_timeout
          timeout = options[:shield_io_timeout] if options[:shield_io_timeout]
          Timeout.timeout(timeout.to_i) do
            shield = load_shield(options[:shield]) if options[:shield]
          end
        rescue Timeout::Error
          UI.error "Error loading image from shield.io timeout reached. Skipping Shield. Use --verbose for more info".red
        rescue OpenURI::HTTPError => error
          response = error.io
          UI.error "Error loading image from shield.io response Error. Skipping Shield. Use --verbose for more info".red
          UI.error response.status if $verbose
          response_error = true
        end

        if @@retry_count <= 0
          UI.error "Cannot load image from shield.io skipping it...".red
        elsif response_error
          UI.message "Waiting for #{timeout.to_i}s and retry to load image from shield.io tries remaining: #{@@retry_count}".red
          sleep timeout.to_i
          @@retry_count -= 1
          return run(path, options)
        end

        icon_changed = false
        app_icons.each do |full_path|
          icon_path = Pathname.new(full_path)
          icon = MiniMagick::Image.new(full_path)

          result = MiniMagick::Image.new(full_path)

          if !options[:no_badge]
            result = add_badge(options[:custom], options[:dark], icon, options[:alpha], alpha_channel, options[:badge_gravity])
            icon_changed = true
          end
          if shield
            result = add_shield(icon, result, shield, alpha_channel, options[:shield_gravity], options[:shield_no_resize])
            icon_changed = true
          end

          if icon_changed
            result.format "png"
            result.write full_path 
          end
        end
        if icon_changed
          UI.message "Badged \\o/!".green
        else
          UI.message "Did nothing... Enable --verbose for more info.".red
        end
      else
        UI.error "Could not find any app icons...".red
      end
    end

    def add_shield(icon, result, shield, alpha_channel, shield_gravity, shield_no_resize)
      UI.message "'#{icon.path}'"
      UI.verbose "Adding shield.io image ontop of icon".blue

      current_shield = MiniMagick::Image.open(shield.path)

      if icon.width > current_shield.width && !shield_no_resize
        current_shield.resize "#{icon.width}x#{icon.height}<"
      else
        current_shield.resize "#{icon.width}x#{icon.height}>"
      end

      result = composite(result, current_shield, alpha_channel, shield_gravity || "north")
    end

    def load_shield(shield_string)
      url = Badge.shield_base_url + Badge.shield_path + shield_string + ".png"
      file_name = shield_string + ".png"

      UI.verbose "Trying to load image from shield.io. Timeout: #{Badge.shield_io_timeout}s".blue
      UI.verbose "URL: #{url}".blue

      shield = Tempfile.new(file_name).tap do |file|
        file.binmode
        file.write(open(url).read)
        file.close
      end
    end

    def check_imagemagick!
        return if `which convert`.include?('convert')
        return if `which gm`.include?('gm')

        UI.error("You have to install ImageMagick or GraphicsMagick to use `badge`")
        UI.error("")
        UI.error("Install it using (ImageMagick):")
        UI.command("brew update && brew install imagemagick")
        UI.error("")
        UI.error("Install it using (GraphicsMagick):")
        UI.command("brew update && brew install graphicsmagick")
        UI.error("")
        UI.error("If you don't have homebrew, visit http://brew.sh")

        UI.user_error!("Install ImageMagick and start your lane again!")
    end

    def add_badge(custom_badge, dark_badge, icon, alpha_badge, alpha_channel, badge_gravity)
      UI.message "'#{icon.path}'"
      UI.verbose "Adding badge image ontop of icon".blue
      if custom_badge && File.exist?(custom_badge) # check if custom image is provided
        badge = MiniMagick::Image.open(custom_badge)
      else
        if alpha_badge
          badge = MiniMagick::Image.open(dark_badge ? Badge.alpha_dark_badge : Badge.alpha_light_badge)
        else
          badge = MiniMagick::Image.open(dark_badge ? Badge.beta_dark_badge : Badge.beta_light_badge)
        end
      end

      badge.resize "#{icon.width}x#{icon.height}"
      result = composite(icon, badge, alpha_channel, badge_gravity || "SouthEast")
    end

    def composite(image, overlay, alpha_channel, gravity)
      image.composite(overlay, 'png') do |c|
        c.compose "Over"
        c.alpha 'On' unless !alpha_channel
        c.gravity gravity
      end
    end
  end
end

我很感激任何帮助。希望我很清楚。在此期间,我将复习一下 Ruby 基础知识。

最佳答案

我不是 XCode 大师,但听起来您没有正确配置 XCode 服务器或机器人。

which convert 

应该返回“convert”二进制文件的路径,同样适用于

which gm

尝试在您的 XCode 服务器上运行这些命令,看看您得到了什么。

只是一个猜测,但您可能需要将这些二进制文件的路径添加到机器人的环境变量中。

关于ruby - 安装 ImageMagick 并在应用图标覆盖时再次启动你的车道错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42262203/

相关文章:

ios - 为什么我在 Storyboard (Xcode) 中所做的更改没有反射(reflect)在我的应用程序上?

ios - 如何在测试目标中添加/打开捆绑文件

ruby-on-rails - Rails 三重连接

ruby-on-rails - 新遗物导致内存泄漏/膨胀?

ruby - Gemfile - 将生产 gems 与开发 gems 分开

ruby-on-rails - 如何修复运行 Test::Unit 测试时产生的警告

Ruby to_a 方法卡住了

iphone - UIBackgroundModes 键未显示在 Info.plist 下拉列表中

ruby-on-rails-3 - 从现在到午夜之间的 rails 3 find()

ruby - 检查字符串是否包含多个项目,以逗号或空格分隔?