Code Monkey home page Code Monkey logo

Comments (4)

amorde avatar amorde commented on June 4, 2024 1

@bpoplauschi this plugin might be of use to you (note that I haven't used it myself so I cannot vouchers for anything)

https://github.com/leavez/cocoapods-binary

from rome.

absolutlabs avatar absolutlabs commented on June 4, 2024

Hello

I didn't create a pull request because this is the first time I write in ruby so the code might be ( / may be / is ) ugly 😜

It only build new pods (those without corresponding .framework in /Rome folder).

If a new version of a pod is downloaded, it won't be built unless the framework has been previously manually deleted.

post_install.rb

require 'fourflusher'

CONFIGURATION = "Release"
PLATFORMS = { 'iphonesimulator' => 'iOS',
            'appletvsimulator' => 'tvOS',
            'watchsimulator' => 'watchOS' }


def build_for_iosish_platform(sandbox, build_dir, destination, target, device, simulator)
  deployment_target = target.platform_deployment_target
  target_label = target.cocoapods_target_label

  spec_names = target.specs.map { |spec| [spec.root.name, spec.root.module_name] }.uniq
  spec_names.each do |root_name, module_name|

    executable_path = "#{build_dir}/#{root_name}"
    device_lib = "#{build_dir}/#{CONFIGURATION}-#{device}/#{root_name}/#{module_name}.framework/#{module_name}"
    device_framework_lib = File.dirname(device_lib)
    simulator_lib = "#{build_dir}/#{CONFIGURATION}-#{simulator}/#{root_name}/#{module_name}.framework/#{module_name}"
    rome_lib = "#{destination}/#{module_name}.framework"

    if (module_name.start_with?('Pods-') || File.directory?(rome_lib))
        Pod::UI.puts "• Using #{root_name}"
    else
        Pod::UI.puts "→ Building #{root_name}"
        xcodebuild(sandbox, root_name, device, deployment_target)
        xcodebuild(sandbox, root_name, simulator, deployment_target)

        next unless File.file?(device_lib) && File.file?(simulator_lib)

        lipo_log = `lipo -create -output #{executable_path} #{device_lib} #{simulator_lib}`
        puts lipo_log unless File.exist?(executable_path)

        FileUtils.mv executable_path, device_lib
        FileUtils.mv device_framework_lib, build_dir
        FileUtils.rm simulator_lib if File.file?(simulator_lib)
        FileUtils.rm device_lib if File.file?(device_lib)

        end
    end
end


def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil)
  args = %W(-project #{sandbox.project_path.basename} -scheme #{target} -configuration #{CONFIGURATION} -sdk #{sdk})
  platform = PLATFORMS[sdk]
  args += Fourflusher::SimControl.new.destination(:oldest, platform, deployment_target) unless platform.nil?
  Pod::Executable.execute_command 'xcodebuild', args, true
end


Pod::HooksManager.register('cocoapods-rome', :post_install) do |installer_context|
  Pod::UI.puts "Rome"

  sandbox_root = Pathname(installer_context.sandbox_root)
  sandbox = Pod::Sandbox.new(sandbox_root)

  build_dir = sandbox_root.parent + 'build'
  destination = sandbox_root.parent + 'Rome'

  FileUtils.mkdir_p build_dir
  FileUtils.mkdir_p destination

  installer_context.umbrella_targets.each do |umbrella|
    umbrella.specs.each do |spec|
      consumer = spec.consumer(umbrella.platform_name)
      file_accessor = Pod::Sandbox::FileAccessor.new(sandbox.pod_dir(spec.root.name), consumer)
      if(file_accessor.vendored_frameworks.count > 0)
        file_accessor.vendored_frameworks.each do |framework|
          Pod::UI.puts "• Copying #{spec.root.name}"
          FileUtils.cp_r framework, destination, :remove_destination => true
        end
      end
    end
  end

  Dir.chdir(sandbox.project_path.dirname) do
  targets = installer_context.umbrella_targets.select { |t| t.specs.any? }
  targets.each do |target|
    case target.platform_name
      when :ios then build_for_iosish_platform(sandbox, build_dir, destination, target, 'iphoneos', 'iphonesimulator')
      when :osx then xcodebuild(sandbox, target.cocoapods_target_label)
      when :tvos then build_for_iosish_platform(sandbox, build_dir, destination, target, 'appletvos', 'appletvsimulator')
      when :watchos then build_for_iosish_platform(sandbox, build_dir, destination, target, 'watchos', 'watchsimulator')
      else raise "Unknown platform '#{target.platform_name}'" end
    end
  end

  raise Pod::Informative, 'The build directory was not found in the expected location.' unless build_dir.directory?

  frameworks = Pathname.glob("#{build_dir}/**/*.framework").reject { |f| f.to_s =~ /Pods.*\.framework/ }

  installer_context.umbrella_targets.each do |umbrella|
    umbrella.specs.each do |spec|
      consumer = spec.consumer(umbrella.platform_name)
      file_accessor = Pod::Sandbox::FileAccessor.new(sandbox.pod_dir(spec.root.name), consumer)
      frameworks += file_accessor.vendored_libraries
    end
  end
  frameworks.uniq!

  frameworks.each do |framework|
    FileUtils.cp_r framework, destination, :remove_destination => true
  end

   build_dir.rmtree if build_dir.directory?

end

Far from perfect, but it will do the trick :)

I hope it won't break anything :D

from rome.

neonichu avatar neonichu commented on June 4, 2024

I'm not a big fan of making this based solely on the presence of the .framework on the filesystem — that's just bound to confuse people.

from rome.

bpoplauschi avatar bpoplauschi commented on June 4, 2024

@neonichu Hi there. I see this is an old discussion, but do you have any suggestion about being able to recompile just the pods that are new or upgraded? Basically similar to what pod install does without the Rome plugin?
In our case, we are using a caching system to store all the precompiled binaries and would like to change them only if needed. As the system is now, running pod install will rebuild everything and all the binaries will be different (of course).

from rome.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.