* Initial commit

* Update README.md
This commit is contained in:
Tommaso Madonia 2021-02-18 17:41:41 +00:00 коммит произвёл GitHub
Родитель 32b8b551f0
Коммит d5407c7b58
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
15 изменённых файлов: 537 добавлений и 8 удалений

28
.github/workflows/gem-push.yml поставляемый Normal file
Просмотреть файл

@ -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
.github/workflows/tests.yml поставляемый Normal file
Просмотреть файл

@ -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
.gitignore поставляемый
Просмотреть файл

@ -9,6 +9,7 @@
/test/tmp/
/test/version_tmp/
/tmp/
.DS_Store
# Used by dotenv library to load environment variables.
# .env

8
Gemfile Normal file
Просмотреть файл

@ -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
Gemfile.lock Normal file
Просмотреть файл

@ -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

Просмотреть файл

@ -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

8
Rakefile Normal file
Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -0,0 +1,2 @@
require 'cocoapods-pod-linkage/gem_version'
require 'cocoapods-pod-linkage/patched_analyzer'

Просмотреть файл

@ -0,0 +1,3 @@
module CocoapodsPodLinkage
VERSION = "0.0.1"
end

Просмотреть файл

@ -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
lib/cocoapods_plugin.rb Normal file
Просмотреть файл

@ -0,0 +1 @@
require 'cocoapods-pod-linkage'

Просмотреть файл

@ -0,0 +1,73 @@
require 'spec_helper'
module Pod
describe Installer::Analyzer do
before do
@podfile = Podfile.new
@root = Podfile::TargetDefinition.new('Pods', @podfile)
@parent = Podfile::TargetDefinition.new('MyApp', @root)
@sandbox = mock()
@analyzer = Installer::Analyzer.new(@sandbox, @podfile, nil, [], true, false, mock())
def @analyzer.compute_pod_target_dependencies(pod_targets, all_specs)
pod_targets
end
end
describe "#generate_pod_targets" do
let(:specification) { Specification.new(nil, 'MyPod') }
[
[:library, :static],
[:library, :dynamic],
[:framework, :static],
[:framework, :dynamic],
].each do |params|
it "updates a PodTarget with #{params[1]} linkage and #{params[0]} packaging" do
packaging = params[0]
linkage = params[1] == :static ? :dynamic : :static
original_pod_target = PodTarget.new(
@sandbox,
BuildType.new(:linkage => params[1], :packaging => packaging),
{},
[],
Platform.ios,
[specification],
[@parent]
)
updated_pod_target = PodTarget.new(
@sandbox,
BuildType.new(:linkage => linkage, :packaging => packaging),
{},
[],
Platform.ios,
[specification],
[@parent]
)
@parent.store_pod('MyPod', :linkage => linkage)
@analyzer.stubs(:original_generate_pod_targets).returns([original_pod_target])
expect(@analyzer.generate_pod_targets({}, {})).to include(lambda { |target|
target.pod_name == 'MyPod' &&
(
(packaging == :library && target.build_as_library?) ||
(packaging == :framework && target.build_as_framework?)
) &&
(
(linkage == :static && target.build_as_static?) ||
(linkage == :dynamic && target.build_as_dynamic?)
) &&
target.scope_suffix.nil? &&
target.target_definitions.include?(@parent)
})
end
end
end
end
end

Просмотреть файл

@ -0,0 +1,59 @@
require 'spec_helper'
module Pod
describe Podfile::TargetDefinition do
before do
@podfile = Podfile.new
@root = Podfile::TargetDefinition.new('Pods', @podfile)
@parent = Podfile::TargetDefinition.new('MyApp', @root)
@child = Podfile::TargetDefinition.new('MyAppTests', @parent)
end
describe "#store_pod" do
context 'when the target does not have a parent' do
it "doesn't set an explicit linkage by default" do
@parent.store_pod('MyPod')
expect(@parent.explicit_pod_linkage['MyPod']).to be_nil
end
it 'allows configuring an explicit linkage for a pod' do
@parent.store_pod('MyPod', :linkage => :static)
expect(@parent.explicit_pod_linkage['MyPod']).to eq(:static)
end
end
context 'when the target has a parent' do
it "doesn't set an explicit linkage by default" do
@child.store_pod('MyPod')
expect(@child.explicit_pod_linkage['MyPod']).to be_nil
end
it 'allows configuring an explicit linkage for a pod' do
@child.store_pod('MyPod', :linkage => :static)
expect(@child.explicit_pod_linkage['MyPod']).to eq(:static)
end
it 'inherits the explicit linkage for a pod from the parent' do
@parent.store_pod('MyPod', :linkage => :static)
expect(@child.explicit_pod_linkage['MyPod']).to eq(:static)
end
it 'allows to override the explicit linkage for a pod from the parent' do
@parent.store_pod('MyPod', :linkage => :static)
@child.store_pod('MyPod', :linkage => :dynamic)
expect(@child.explicit_pod_linkage['MyPod']).to eq(:dynamic)
end
end
end
end
end

54
spec/spec_helper.rb Normal file
Просмотреть файл

@ -0,0 +1,54 @@
require 'pathname'
ROOT = Pathname.new(File.expand_path('../../', __FILE__))
$:.unshift((ROOT + 'lib').to_s)
$:.unshift((ROOT + 'spec').to_s)
require 'bundler/setup'
require 'cocoapods'
RSpec.configure do |config|
config.mock_with :mocha
config.expect_with :rspec do |c|
c.syntax = :expect
end
end
Mocha.configure { |configuration|
configuration.stubbing_non_existent_method = :prevent
}
require 'cocoapods_plugin'
#-----------------------------------------------------------------------------#
module Pod
# Disable the wrapping so the output is deterministic in the tests.
#
UI.disable_wrap = true
# Redirects the messages to an internal store.
#
module UI
@output = ''
@warnings = ''
class << self
attr_accessor :output
attr_accessor :warnings
def puts(message = '')
@output << "#{message}\n"
end
def warn(message = '', actions = [])
@warnings << "#{message}\n"
end
def print(message)
@output << message
end
end
end
end