Merge pull request #584 from LouisBoudreau/cocoapods

Add Cocoapods source
This commit is contained in:
Jon Ruskin 2022-12-21 20:09:28 -07:00 коммит произвёл GitHub
Родитель 631302e7e9 bca6a2ac73
Коммит bdfad9f550
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
14 изменённых файлов: 594 добавлений и 0 удалений

21
.github/workflows/test.yml поставляемый
Просмотреть файл

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

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

15
docs/sources/cocoapods.md Normal file
Просмотреть файл

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

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

@ -19,5 +19,6 @@ module Licensed
require "licensed/sources/gradle"
require "licensed/sources/mix"
require "licensed/sources/yarn"
require "licensed/sources/cocoapods"
end
end

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

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

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

@ -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
script/source-setup/cocoapods Executable file
Просмотреть файл

@ -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
test/fixtures/cocoapods/Podfile поставляемый Normal file
Просмотреть файл

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

355
test/fixtures/cocoapods/ios.xcodeproj/project.pbxproj поставляемый Normal file
Просмотреть файл

@ -0,0 +1,355 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objects = {
/* Begin PBXContainerItemProxy section */
E3999824D112043DE8E88846 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = EFF3EB6186DBCF3E4AC26B8F /* Project object */;
proxyType = 1;
remoteGlobalIDString = C67C026B3ECC938BFEAA06A4;
remoteInfo = ios;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
07598229C97B25EC09E1E750 /* ios.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = ios.app; sourceTree = BUILT_PRODUCTS_DIR; };
56F698D1A2EE3DA1EA36472F /* iosTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = iosTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXGroup section */
56DF4E8E10A8991E1530FAE8 /* iosTests */ = {
isa = PBXGroup;
children = (
);
path = iosTests;
sourceTree = "<group>";
};
98DCE871D516BA368C096FB6 /* Products */ = {
isa = PBXGroup;
children = (
07598229C97B25EC09E1E750 /* ios.app */,
56F698D1A2EE3DA1EA36472F /* iosTests.xctest */,
);
name = Products;
sourceTree = "<group>";
};
AD5CE3D685274DEA767D3FBA /* ios */ = {
isa = PBXGroup;
children = (
);
path = ios;
sourceTree = "<group>";
};
DCC682D4A34A47286DC3668D = {
isa = PBXGroup;
children = (
AD5CE3D685274DEA767D3FBA /* ios */,
56DF4E8E10A8991E1530FAE8 /* iosTests */,
98DCE871D516BA368C096FB6 /* Products */,
);
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
3D1E8D49A855CF3E46D3D051 /* iosTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = B09050E69F79472FFA774918 /* Build configuration list for PBXNativeTarget "iosTests" */;
buildPhases = (
4ADB27C84D37D42F473C6F1A /* Sources */,
);
buildRules = (
);
dependencies = (
68B12C96D49C4EB6B147E614 /* PBXTargetDependency */,
);
name = iosTests;
productName = iosTests;
productReference = 56F698D1A2EE3DA1EA36472F /* iosTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
C67C026B3ECC938BFEAA06A4 /* ios */ = {
isa = PBXNativeTarget;
buildConfigurationList = 254407FBAE608B768D0F34E8 /* Build configuration list for PBXNativeTarget "ios" */;
buildPhases = (
1A12E8A67ABB0C6B7845294E /* Sources */,
);
buildRules = (
);
dependencies = (
);
name = ios;
productName = ios;
productReference = 07598229C97B25EC09E1E750 /* ios.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
EFF3EB6186DBCF3E4AC26B8F /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1200;
TargetAttributes = {
};
};
buildConfigurationList = 78809F4A16F4117614361355 /* Build configuration list for PBXProject "ios" */;
compatibilityVersion = "Xcode 11.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Base,
en,
);
mainGroup = DCC682D4A34A47286DC3668D;
projectDirPath = "";
projectRoot = "";
targets = (
C67C026B3ECC938BFEAA06A4 /* ios */,
3D1E8D49A855CF3E46D3D051 /* iosTests */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
1A12E8A67ABB0C6B7845294E /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
4ADB27C84D37D42F473C6F1A /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
68B12C96D49C4EB6B147E614 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = C67C026B3ECC938BFEAA06A4 /* ios */;
targetProxy = E3999824D112043DE8E88846 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
1588C5088418414A4D125A34 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ios.app/ios";
};
name = Release;
};
3F06443FC191E03534A2DE7A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ios.app/ios";
};
name = Debug;
};
94AAA1C5A9C82E2F2012CF9C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
AB1A811F5CA8792139DE10E5 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
};
name = Release;
};
CBFC39C2A51BF6D75162C1D0 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"DEBUG=1",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
F406B4E41AD59D4051593F2C /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
254407FBAE608B768D0F34E8 /* Build configuration list for PBXNativeTarget "ios" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F406B4E41AD59D4051593F2C /* Debug */,
94AAA1C5A9C82E2F2012CF9C /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
78809F4A16F4117614361355 /* Build configuration list for PBXProject "ios" */ = {
isa = XCConfigurationList;
buildConfigurations = (
CBFC39C2A51BF6D75162C1D0 /* Debug */,
AB1A811F5CA8792139DE10E5 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
B09050E69F79472FFA774918 /* Build configuration list for PBXNativeTarget "iosTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
3F06443FC191E03534A2DE7A /* Debug */,
1588C5088418414A4D125A34 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
/* End XCConfigurationList section */
};
rootObject = EFF3EB6186DBCF3E4AC26B8F /* Project object */;
}

7
test/fixtures/cocoapods/ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata сгенерированный поставляемый Normal file
Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

10
test/fixtures/cocoapods/ios.xcworkspace/contents.xcworkspacedata сгенерированный поставляемый Normal file
Просмотреть файл

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:ios.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>

19
test/fixtures/cocoapods/project.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,19 @@
name: ios
options:
deploymentTarget: "13.0"
targets:
iosTests:
type: bundle.unit-test
platform: iOS
sources:
- path: iosTests
dependencies:
- target: ios
ios:
type: application
platform: iOS
deploymentTarget: "13.0"
sources:
- path: ios

5
test/fixtures/command/cocoapods.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,5 @@
expected_dependency: Chatto
source_path: test/fixtures/cocoapods
cache_path: test/fixtures/cocoapods/.licenses
sources:
cocoapods: true

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

@ -0,0 +1,60 @@
# frozen_string_literal: true
require "test_helper"
require "tmpdir"
if Licensed::Shell.tool_available?("pod")
describe Licensed::Sources::Cocoapods do
let(:fixtures) { File.expand_path("../../fixtures/cocoapods", __FILE__) }
let(:config) { Licensed::AppConfiguration.new({ "source_path" => Dir.pwd }) }
let(:source) { Licensed::Sources::Cocoapods.new(config) }
describe "enabled?" do
it "is true if Podfiles exist" do
Dir.chdir(fixtures) do
assert source.enabled?
end
end
it "is false if Podfiles do not exist" do
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
refute source.enabled?
end
end
end
end
describe "dependencies" do
it "finds Cocoapods dependencies" do
Dir.chdir(fixtures) do
dep = source.dependencies.find { |d| d.name == "Alamofire" }
assert dep
assert_equal "5.4.3", dep.version
end
end
it "handle multiple subspecs from the same root dependencies" do
Dir.chdir fixtures do
assert source.dependencies.detect { |dep| dep.name == "MaterialComponents/Cards" }
assert source.dependencies.detect { |dep| dep.name == "MaterialComponents/Buttons" }
end
end
it "supports pods from git" do
Dir.chdir(fixtures) do
dep = source.dependencies.detect { |d| d.name == "Chatto" }
end
end
end
describe "targets" do
it "includes only dependencies from target if configured" do
Dir.chdir fixtures do
config["cocoapods"] = { "targets" => ["iosTests"] }
assert source.dependencies.detect { |dep| dep.name == "lottie-ios" }
assert_nil source.dependencies.detect { |dep| dep.name == "Alamofire" }
end
end
end
end
end