Skip to content

Commit

Permalink
Merge pull request #584 from LouisBoudreau/cocoapods
Browse files Browse the repository at this point in the history
Add Cocoapods source
  • Loading branch information
jonabc authored Dec 22, 2022
2 parents 631302e + bca6a2a commit bdfad9f
Show file tree
Hide file tree
Showing 14 changed files with 594 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,24 @@ jobs:
run: script/source-setup/yarn/berry
- name: Run tests
run: script/test yarn/berry

cocoapods:
runs-on: ubuntu-latest
needs: core
strategy:
matrix:
cocoapods: [ '1.11.3' ]
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- name: Set up Cocoapods
run: gem install cocoapods -v ${{ matrix.cocoapods }}
- name: Bootstrap
run: script/bootstrap
- name: Set up fixtures
run: script/source-setup/cocoapods
- name: Run tests
run: script/test cocoapods
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ test/fixtures/cargo/*

test/fixtures/swift/.build

test/fixtures/cocoapods/Podfile.lock
test/fixtures/cocoapods/Pods

vendor/licenses
.licenses_test
*.gem
Expand Down
15 changes: 15 additions & 0 deletions docs/sources/cocoapods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# CocoaPods

The cocoapods source will detect dependencies when `Podfile` and `Podfile.lock` are found at an app's `source_path`.

It uses the `pod` CLI commands to enumerate dependencies and gather metadata on each package.

### Evaluating dependencies from a specific target

The `cocoapods.targets` property is used to specify which targets to analyze dependencies from. By default, dependencies from all targets will be analyzed.

```yml
cocoapods:
targets:
- ios
```
1 change: 1 addition & 0 deletions lib/licensed/sources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ module Sources
require "licensed/sources/gradle"
require "licensed/sources/mix"
require "licensed/sources/yarn"
require "licensed/sources/cocoapods"
end
end
61 changes: 61 additions & 0 deletions lib/licensed/sources/cocoapods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true
require "json"
require "pathname"
require "uri"
require "cocoapods-core"

module Licensed
module Sources
class Cocoapods < Source
def enabled?
return unless Licensed::Shell.tool_available?("pod")

config.pwd.join("Podfile").exist? && config.pwd.join("Podfile.lock").exist?
end

def enumerate_dependencies
pods.map do |pod|
name = pod.name
path = dependency_path(pod.root_name)
version = lockfile.version(name).version

Dependency.new(
path: path,
name: name,
version: version,
metadata: { "type" => Cocoapods.type }
)
end
end

private

def pods
return lockfile.dependencies if targets.nil?

targets_to_validate = podfile.target_definition_list.filter { |t| targets.include?(t.label) }
if targets_to_validate.any?
targets_to_validate.map(&:dependencies).flatten
else
raise Licensed::Sources::Source::Error, "Unable to find any target in the Podfile matching the ones provided in the config."
end
end

def targets
@targets ||= config.dig("cocoapods", "targets")&.map { |t| "Pods-#{t}" }
end

def lockfile
@lockfile ||= Pod::Lockfile.from_file(config.pwd.join("Podfile.lock"))
end

def podfile
@podfile ||= Pod::Podfile.from_file(config.pwd.join("Podfile"))
end

def dependency_path(name)
config.pwd.join("Pods/#{name}")
end
end
end
end
2 changes: 2 additions & 0 deletions licensed.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ Gem::Specification.new do |spec|
spec.add_dependency "parallel", ">= 0.18.0"
spec.add_dependency "reverse_markdown", ">= 1", "< 3"
spec.add_dependency "json", ">= 2.6.2"
spec.add_dependency "cocoapods-core", "~> 1.0"

spec.add_development_dependency "rake", ">= 12.3.3"
spec.add_development_dependency "minitest", "~> 5.8"
spec.add_development_dependency "mocha", "~> 2.0"
spec.add_development_dependency "rubocop-github", "~> 0.6"
spec.add_development_dependency "byebug", "~> 11.1.3"
spec.add_development_dependency "cocoapods", "~> 1.0"
end
17 changes: 17 additions & 0 deletions script/source-setup/cocoapods
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

if [ -z "$(which pod)" ]; then
echo "A local pod installation is required for cocoapods development." >&2
exit 127
fi

# setup test fixtures
BASE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
cd $BASE_PATH/test/fixtures/cocoapods

if [ "$1" == "-f" ]; then
pod install --clean-install
fi

pod install
18 changes: 18 additions & 0 deletions test/fixtures/cocoapods/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Uncomment the next line to define a global platform for your project
platform :ios, '13.0'

target 'ios' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

pod "Alamofire", "5.4.3"
pod "MaterialComponents/Buttons", "124.2.0"
pod "MaterialComponents/Cards", "124.2.0"
pod "Chatto", git: "https://github.com/badoo/Chatto", tag: "4.1.0"

target 'iosTests' do
inherit! :search_paths

pod "lottie-ios", "3.3.0"
end
end
Loading

0 comments on commit bdfad9f

Please sign in to comment.