Skip to content

Commit

Permalink
Initial commit (#1)
Browse files Browse the repository at this point in the history
* Initial commit

* Update README.md
  • Loading branch information
Frugghi committed Feb 18, 2021
1 parent 32b8b55 commit d5407c7
Show file tree
Hide file tree
Showing 15 changed files with 537 additions and 8 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/gem-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish

on:
workflow_dispatch:

jobs:
build_publish:
name: Build and Publish
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- name: Build gem
run: gem build *.gemspec
- name: Publish to GitHub Package Registry
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: Bearer ${GITHUB_TOKEN}\n" > $HOME/.gem/credentials
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
OWNER: microsoft
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
unit_tests:
name: Unit Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- name: Install dependencies
run: |
bundle config deployment true
bundle install
- name: Run tests
run: bundle exec rake tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/test/tmp/
/test/version_tmp/
/tmp/
.DS_Store

# Used by dotenv library to load environment variables.
# .env
Expand Down
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in cocoapods-pod-linkage.gemspec
gemspec

group :development do
gem 'cocoapods'
end
119 changes: 119 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
PATH
remote: .
specs:
cocoapods-pod-linkage (0.0.1)
cocoapods (~> 1.0)

GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.3)
activesupport (5.2.4.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
claide (1.0.3)
cocoapods (1.10.1)
addressable (~> 2.6)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.10.1)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.4.0, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.4.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.6.6)
nap (~> 1.0)
ruby-macho (~> 1.4)
xcodeproj (>= 1.19.0, < 2.0)
cocoapods-core (1.10.1)
activesupport (> 5.0, < 6)
addressable (~> 2.6)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
netrc (~> 0.11)
public_suffix
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.4.0)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
cocoapods-trunk (1.5.0)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.1.8)
diff-lcs (1.4.4)
escape (0.0.4)
ethon (0.12.0)
ffi (>= 1.3.0)
ffi (1.14.2)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.8.9)
concurrent-ruby (~> 1.0)
json (2.5.1)
minitest (5.14.3)
mocha (1.12.0)
molinillo (0.6.6)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
public_suffix (4.0.6)
rake (13.0.3)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
ruby-macho (1.4.0)
thread_safe (0.3.6)
typhoeus (1.4.0)
ethon (>= 0.9.0)
tzinfo (1.2.9)
thread_safe (~> 0.1)
xcodeproj (1.19.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)

PLATFORMS
ruby

DEPENDENCIES
cocoapods
cocoapods-pod-linkage!
mocha (~> 1.11)
rake (~> 13.0)
rspec (~> 3.9)

BUNDLED WITH
2.1.4
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
# Project
# CocoaPods Pod Linkage plugin

> This repo has been populated by an initial template to help get you started. Please
> make sure to update the content to build a great experience for community-building.
This project is a [CocoaPods](https://github.com/CocoaPods/CocoaPods) plugin that allows to set a `:linkage` option for a specific pod.

As the maintainer of this project, please make a few updates:
## Usage

- Improving this README.MD file to provide a great experience
- Updating SUPPORT.MD with content about this project's support experience
- Understanding the security reporting process in SECURITY.MD
- Remove this section from the README
Add to your Podfile
```Ruby
plugin 'cocoapods-pod-linkage'
```

Then, use the `:linkage` option to change the linking style of that pod
```Ruby
target :MyTarget do
use_frameworks! :linkage => :static

pod 'MyStaticPod', '1.2.3'
pod 'MyDynamicPod', '1.2.3', :linkage => :dynamic
end
```

## Run tests for this plugin

To run the tests, use
```shell
rake tests
```

## Contributing

Expand Down
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:tests) do |t|
t.pattern = Dir.glob("spec/**/*_spec.rb")
t.rspec_opts = "--format documentation"
end

task :default => :tests
24 changes: 24 additions & 0 deletions cocoapods-pod-linkage.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cocoapods-pod-linkage/gem_version.rb'

Gem::Specification.new do |spec|
spec.name = 'cocoapods-pod-linkage'
spec.version = CocoapodsPodLinkage::VERSION
spec.authors = ['Microsoft Corporation']
spec.summary = %q{CocoaPods plugin for configuring the linkage type of a specific pod.}
spec.homepage = 'https://github.com/microsoft/cocoapods-pod-linkage'
spec.license = 'MIT'

spec.files = Dir["lib/**/*"] + %w(README.md LICENSE)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_runtime_dependency 'cocoapods', '~> 1.0'

spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.9'
spec.add_development_dependency 'mocha', '~> 1.11'
end
2 changes: 2 additions & 0 deletions lib/cocoapods-pod-linkage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'cocoapods-pod-linkage/gem_version'
require 'cocoapods-pod-linkage/patched_analyzer'
3 changes: 3 additions & 0 deletions lib/cocoapods-pod-linkage/gem_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module CocoapodsPodLinkage
VERSION = "0.0.1"
end
108 changes: 108 additions & 0 deletions lib/cocoapods-pod-linkage/patched_analyzer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
require 'cocoapods'

class Pod::Installer::Analyzer

alias_method :original_generate_pod_targets, :generate_pod_targets

def generate_pod_targets(resolver_specs_by_target, target_inspections)
targets = original_generate_pod_targets(resolver_specs_by_target, target_inspections)

pod_targets = []
targets.each { |target|
explicit_linkage = target.target_definitions.map { |t| t.explicit_pod_linkage[target.pod_name] }.compact.first

# We need to update the target only if we specified an explicit linkage
if explicit_linkage
override_target = ((explicit_linkage == :static && target.build_as_dynamic?) || (explicit_linkage == :dynamic && target.build_as_static?))

# Create the correct Pod::BuildType because Pod::PodTarget doesn't expose it
if target.build_as_framework?
build_type = Pod::BuildType.new(:linkage => explicit_linkage, :packaging => :framework)
else
build_type = Pod::BuildType.new(:linkage => explicit_linkage, :packaging => :library)
end

# Pods are de-duplicated before this function, we need to merge them remove the scope suffix
scope_suffix = target.scope_suffix
if scope_suffix == 'static' || scope_suffix == 'dynamic'
override_target = true
scope_suffix = nil
end

if override_target
# Create the new target
target = Pod::PodTarget.new(
target.sandbox,
build_type,
target.user_build_configurations,
target.archs,
target.platform,
target.specs,
target.target_definitions,
target.file_accessors,
scope_suffix,
target.swift_version
)

# If we already have a target with the same name we just merge the target defitions
# TODO: Check that all the other properties are really the same!
existing_target = pod_targets.find { |t| t.label == target.label }
if existing_target
Pod::UserInterface.message "- Merging #{target.pod_name} target definitions"

target = Pod::PodTarget.new(
existing_target.sandbox,
build_type,
existing_target.user_build_configurations,
existing_target.archs,
existing_target.platform,
existing_target.specs,
existing_target.target_definitions + target.target_definitions,
existing_target.file_accessors,
existing_target.scope_suffix,
existing_target.swift_version
)

pod_targets.delete existing_target
else
Pod::UserInterface.message "- Updating #{target.pod_name}"
end
end
end

pod_targets.append target
}

all_specs = resolver_specs_by_target.values.flatten.map(&:spec).uniq.group_by(&:name)
compute_pod_target_dependencies(pod_targets, all_specs)
end

end

module Pod
class Podfile
class TargetDefinition

def detect_explicit_pod_linkage(name, requirements)
@explicit_pod_linkage ||= {}
options = requirements.last || {}
@explicit_pod_linkage[Specification.root_name(name)] = options[:linkage] if options.is_a?(Hash) && options[:linkage]
options.delete(:linkage) if options.is_a?(Hash)
requirements.pop if options.empty?
end

def explicit_pod_linkage
pod_linkage = @explicit_pod_linkage || {}
pod_linkage.merge!(parent.explicit_pod_linkage) { |key, v1, v2| v1 } if !parent.nil? && parent.is_a?(TargetDefinition)
pod_linkage
end

original_parse_inhibit_warnings = instance_method(:parse_inhibit_warnings)
define_method(:parse_inhibit_warnings) do |name, requirements|
detect_explicit_pod_linkage(name, requirements)
original_parse_inhibit_warnings.bind(self).call(name, requirements)
end

end
end
end
1 change: 1 addition & 0 deletions lib/cocoapods_plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'cocoapods-pod-linkage'
Loading

0 comments on commit d5407c7

Please sign in to comment.