Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
manuyavuz committed Feb 28, 2018
1 parent 394e6a5 commit e8e869b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
49 changes: 44 additions & 5 deletions lib/cocoapods-packager/builder.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Pod
class Builder
def initialize(file_accessors, source_dir, static_sandbox, dynamic_sandbox, spec, embedded, mangle, dynamic, config, bundle_identifier, exclude_deps, platform)
@file_accessors = file_accessors
def initialize(installer, source_dir, static_sandbox, dynamic_sandbox, spec, embedded, mangle, dynamic, config, bundle_identifier, exclude_deps, platform, prelink)
@installer = installer
@source_dir = source_dir
@static_sandbox = static_sandbox
@dynamic_sandbox = dynamic_sandbox
Expand All @@ -13,16 +13,19 @@ def initialize(file_accessors, source_dir, static_sandbox, dynamic_sandbox, spec
@bundle_identifier = bundle_identifier
@exclude_deps = exclude_deps
@platform = platform
@prelink = prelink
@static_sandbox_root = @static_sandbox.root.to_s
if @dynamic
@static_sandbox_root = "#{@static_sandbox_root}/#{@static_sandbox.root.to_s.split('/').last}"
@dynamic_sandbox_root = "#{@config.sandbox_root}/#{@dynamic_sandbox.root.to_s.split('/').last}"
end

@public_headers_root = @static_sandbox.public_headers.root
@file_accessors = @installer.pod_targets.select {|t| t.pod_name == @spec.name }.flat_map(&:file_accessors)
end

def build(package_type)
prepare_installer
if package_type == :library
build_static_library
elsif package_type == :static_framework
Expand All @@ -32,6 +35,29 @@ def build(package_type)
end
end

def prepare_installer
if @prelink
prelink_libs = vendored_libraries
prelink_libs += @installer.pod_targets.map do |target|
next if target.product_module_name == @spec.name

if target.should_build?
File.join(root, "lib#{target.product_module_name}.a")
end
end.compact
@installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == @spec.name
config.build_settings['GENERATE_MASTER_OBJECT_FILE'] = 'YES'
config.build_settings['PRELINK_FLAGS'] = '-objc_abi_version 2'
config.build_settings['PRELINK_LIBS'] = "#{prelink_libs.join(' ')}"
end
end
end
@installer.pods_project.save
end
end

def build_static_library
UI.puts("Building static library #{@spec} with configuration #{@config}")

Expand Down Expand Up @@ -275,15 +301,28 @@ def expand_paths(path_specs)
end
end

def static_libs_in_sandbox(build_dir = 'build')
def static_libraries(installer, root)
+ installer.pod_targets.map do |target|
+ next if target.product_module_name == @spec.name
+
+ if target.should_build?
+ File.join(root, "lib#{target.product_module_name}.a")
+ end
+ end.compact
+ end
def static_libs_in_dir(dir)
if @exclude_deps
UI.puts 'Excluding dependencies'
Dir.glob("#{@static_sandbox_root}/#{build_dir}/lib#{@spec.name}.a")
Dir.glob("#{dir}/lib#{@spec.name}.a")
else
Dir.glob("#{@static_sandbox_root}/#{build_dir}/lib*.a")
Dir.glob("#{dir}/lib*.a")
end
end

def static_libs_in_sandbox(build_dir = 'build')
static_libs_in_path("#{@static_sandbox_root}/#{build_dir}")
end

def vendored_libraries
if @vendored_libraries
@vendored_libraries
Expand Down
1 change: 1 addition & 0 deletions lib/cocoapods-packager/pod_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def install_pod(platform_name, sandbox)
static_installer.install!

unless static_installer.nil?
prelink_libs = vendored_libraries(static_installer, "$(PODS_ROOT)") | static_libraries(static_installer, "$(CONFIGURATION_BUILD_DIR)")
static_installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CLANG_MODULES_AUTOLINK'] = 'NO'
Expand Down
8 changes: 5 additions & 3 deletions lib/pod/command/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def self.options
['--embedded', 'Generate embedded frameworks.'],
['--library', 'Generate static libraries.'],
['--dynamic', 'Generate dynamic framework.'],
['--prelink', 'Perform a single object prelink'],
['--bundle-identifier', 'Bundle identifier for dynamic framework'],
['--exclude-deps', 'Exclude symbols from dependencies.'],
['--configuration', 'Build the specified configuration (e.g. Debug). Defaults to Release'],
Expand All @@ -30,6 +31,7 @@ def initialize(argv)
@library = argv.flag?('library')
@dynamic = argv.flag?('dynamic')
@mangle = argv.flag?('mangle', true)
@prelink = argv.flag?('prelink', false)
@bundle_identifier = argv.option('bundle-identifier', nil)
@exclude_deps = argv.flag?('exclude-deps', false)
@name = argv.shift_argument
Expand Down Expand Up @@ -142,9 +144,8 @@ def create_working_directory
end

def perform_build(platform, static_sandbox, dynamic_sandbox, static_installer)
file_accessors = static_installer.pod_targets.select {|t| t.pod_name == @spec.name }.flat_map(&:file_accessors)
builder = Pod::Builder.new(
file_accessors,
static_installer,
@source_dir,
static_sandbox,
dynamic_sandbox,
Expand All @@ -155,7 +156,8 @@ def perform_build(platform, static_sandbox, dynamic_sandbox, static_installer)
@config,
@bundle_identifier,
@exclude_deps,
platform
platform,
@prelink
)

builder.build(@package_type)
Expand Down

0 comments on commit e8e869b

Please sign in to comment.