choc 0.1.0.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/choc +90 -0
  3. data/lib/choc_tools.rb +56 -0
  4. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26718439279c2f1972b848ff47c8531a0bd82952
4
+ data.tar.gz: 6e9d7377ec743cbe44b288eab66751c0e66b93d4
5
+ SHA512:
6
+ metadata.gz: 43aca6fcd812d8043b70a3f0c15755df1baff31e90565543d918e8a3bfc7b0c34885f7c5b68144ea6898ab59ba096cdb4fbc223b49b441db24b92bcaf9afb276
7
+ data.tar.gz: adf1a0c65990f6f237382c1b1ed636bd7228f39df38505a3268ce4c4a9e7048d1d632cd2f3746df408bbd6b392d632e96318b5ab915ce781242910f1af82f36e
data/bin/choc ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'choc_tools'
4
+ require 'optparse'
5
+ require 'securerandom'
6
+ require 'fileutils'
7
+
8
+ $verbose = false
9
+
10
+ cmd_parser = OptionParser.new do |opts|
11
+ opts.banner = <<-USAGE
12
+ Usage: choc <input_file> [<object_file_name>...]
13
+ Example: choc libProprietaryUniversal.a AFHTTPClient.o Foo.o Bar.o Baz.o
14
+
15
+ USAGE
16
+ opts.on("-h", "--help", "Display this help screen") do
17
+ puts opts
18
+ exit
19
+ end
20
+
21
+ opts.on("-v", "--verbose", "Verbose Mode") do
22
+ $verbose = true
23
+ end
24
+ end
25
+
26
+ $target_dir = "/tmp/choc/#{SecureRandom.uuid}"
27
+
28
+ begin
29
+ args = cmd_parser.parse(ARGV)
30
+
31
+ if args.count < 2
32
+ puts "Invalid parameters"
33
+ puts cmd_parser
34
+ exit 1
35
+ end
36
+
37
+ # Get the filename and objects.
38
+ filename = args[0]
39
+ objs = args.slice(1, args.length - 1)
40
+
41
+ # Check existence
42
+ if not File.exists?(filename)
43
+ puts "File #{filename} not found"
44
+ exit 1
45
+ end
46
+
47
+ # Check if file is universal binary
48
+ if `file #{filename}`.split("\n")[0].index("Mach-O universal binary") == nil
49
+ puts "File #{filename} is not a universal binary"
50
+ exit 1
51
+ end
52
+
53
+ # First decide the platform and create the processing directory
54
+ puts "Creating #{$target_dir}..."
55
+ FileUtils.mkdir_p $target_dir
56
+ platforms = Choc::extract_platforms(filename)
57
+ puts "Platforms found in #{filename}: #{platforms.to_a.join(',')}"
58
+ puts "Processing..."
59
+ platforms.to_a.each do |platform|
60
+ libname = Choc::platform_libname(filename, platform, $target_dir)
61
+ platform_targetdir = "#{$target_dir}/#{platform}"
62
+ puts "Extracting #{platform} to #{libname}" if $verbose
63
+ Choc::extract_lib(filename, platform, $target_dir)
64
+ puts "Extracting object files..." if $verbose
65
+ FileUtils.mkdir_p platform_targetdir
66
+ Choc::extract_objects(libname, platform_targetdir)
67
+ puts "Deleting unneeded object files..." if $verbose
68
+ objs.each do |obj|
69
+ objfilename = "#{platform_targetdir}/#{obj}"
70
+ puts "Deleting #{objfilename} for #{platform}..." if $verbose
71
+ FileUtils.rm(objfilename) if File.exists?(objfilename)
72
+ end
73
+
74
+ # Repack Back
75
+ Choc::arlib(libname, platform_targetdir)
76
+ end
77
+
78
+ # Make Universal
79
+ Choc::make_uberlib(filename, $target_dir)
80
+
81
+ # Clean Up
82
+ puts "Cleaning Up..."
83
+ FileUtils.rm_r($target_dir)
84
+
85
+
86
+ rescue OptionParser::InvalidOption => e
87
+ puts e
88
+ puts cmd_parser
89
+ exit 1
90
+ end
data/lib/choc_tools.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'set'
2
+ module Choc
3
+ def self.extract_platforms(filename)
4
+ output = `lipo -info #{filename}`
5
+ if ($?.exitstatus == 0)
6
+ return output.chop.split(':').last.strip.split(' ').to_set
7
+ else
8
+ return nil
9
+ end
10
+ end
11
+
12
+ def self.platform_libname(filename, platform, dest)
13
+ outname = "#{dest}/#{File.basename(filename, '.*')}-#{platform}#{File.extname(filename)}"
14
+ return outname
15
+ end
16
+
17
+ def self.extract_lib(filename, platform, dest)
18
+ plats = Choc::extract_platforms(filename)
19
+ valid = plats.include?(platform)
20
+ outname = Choc::platform_libname(filename, platform, dest)
21
+
22
+ if valid
23
+ cmd = "lipo -thin #{platform} #{filename} -o #{outname}"
24
+ return system(cmd)
25
+ else
26
+ return nil
27
+ end
28
+ end
29
+
30
+ def self.list_objects(platform_lib)
31
+ ar_out = `ar -t #{platform_lib}`
32
+ return ar_out.split("\n").select { |filename| File.extname(filename) == ".o" }
33
+ end
34
+
35
+ def self.extract_objects(platform_lib, dest)
36
+ cmd = "cd #{dest} && ar -x #{platform_lib}"
37
+ return system(cmd)
38
+ end
39
+
40
+ def self.arlib(platform_lib, object_dir)
41
+ if File.exists?(platform_lib)
42
+ FileUtils.rm platform_lib
43
+ end
44
+ cmd = "ar rcs #{platform_lib} #{object_dir}/*.o"
45
+ return system(cmd)
46
+ end
47
+
48
+ def self.make_uberlib(destlib, srcdir)
49
+ platforms = ["i386", "x86_64", "armv7", "armv7s", "arm64"]
50
+ all_platform_libs = platforms.map { |p| Choc::platform_libname(destlib, p, srcdir) }
51
+ platform_libs = all_platform_libs.select { |l| File.exists?(l) }
52
+ cmd = "lipo -create #{platform_libs.join(" ")} -o #{destlib}"
53
+ return system(cmd)
54
+ end
55
+ end
56
+
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: choc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Didiet Noor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Remove object files from your universal cocoa libs
14
+ email: lynxluna@gmail.com
15
+ executables:
16
+ - choc
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/choc
21
+ - lib/choc_tools.rb
22
+ homepage: http://github.com/lynxluna/choc
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">"
38
+ - !ruby/object:Gem::Version
39
+ version: 1.3.1
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.2.2
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Chop your Cocoa libs
46
+ test_files: []