LoginSignup
1
0

More than 1 year has passed since last update.

iOS アプリで使ってる OSS の情報をいい感じにとる

Last updated at Posted at 2021-12-06

CocoaPods で OSS を管理している iOS アプリで使っている OSS のリストを "いい感じ" に作ります。

お題

開発中の iOS アプリ内で使っている OSS を次の情報を含めてリストアップしたい。

  • OSS 名
  • バージョン
  • ライセンス
  • 公開サイト
  • 作者

変なのが混入してないかとか、なんやかんやあるんです、はい。

解答

こうする

解法

なんかいい感じのコマンドとかツールとかないか探した結果、スクリプトをちょこっと書くだけで済みそうだったのでそうしました。以下はその辺の説明です。

LicensePlist

OSS のリストと言えば LicensePlist が思い浮かびます。アプリ上で OSS の表示義務を果たすのにとてもありがたいツールです。

ただ、出力が、、、

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>PreferenceSpecifiers</key>
        <array>
                <dict>
                        <key>FooterText</key>
                        <string>The AWS Mobile SDK for iOS is generally licensed under the Apache 2.0 License, with the AWSLex/Bluefront folder under the AWS Customer Agreement (https://aws.amazon.com/agreement/ ).
</string>
                        <key>Type</key>
                        <string>PSGroupSpecifier</string>
                </dict>
        </array>
</dict>
</plist>

バージョン番号がないし、ライセンス表記もフリースタイルすぎるので、、、ね。

pod コマンド

そもそも CocoaPods で管理してるんで、pod コマンドでなんとかなるんちゃうの、と考えるのは至極自然です。でも世の中そんなに甘くはありませんでした。

今ご案内できる商品はこちらでございまーす。

$ pod search --simple --ios GoogleMaps
-> GoogleMaps (5.1.0)
   Google Maps SDK for iOS.
   pod 'GoogleMaps', '~> 5.1.0'
   - Homepage: https://developers.google.com/maps/documentation/ios/
   - Source:   https://dl.google.com/dl/cpdc/3cd76dc5e4525f42/GoogleMaps-5.1.0.tar.gz
   - Versions: 5.1.0, 5.0.0, 4.2.0, 4.1.0, 4.0.0, 3.10.0, 3.10.0-beta1, 3.9.0, 3.8.2, 3.8.0, 3.7.0, 3.6.0, 3.5.0, 3.4.0, 3.3.0, 3.2.0, 3.1.0, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 2.7.0, 2.6.0, 2.5.0, 2.4.0, 2.3.1, 2.3.0, 2.2.0, 2.1.1, 2.1.0, 2.0.1, 2.0.0, 1.13.2,
   1.13.1, 1.13.0, 1.12.3, 1.12.2, 1.12.1, 1.12.0, 1.11.1, 1.11.0, 1.10.5, 1.10.4, 1.10.3, 1.10.2, 1.10.1, 1.10.0, 1.9.2 [trunk repo]
   - Subspecs:
     - GoogleMaps/Base (5.1.0)
     - GoogleMaps/Maps (5.1.0)
     - GoogleMaps/M4B (5.1.0)

-> GoogleMapsDirection (0.1.1)
   Wrapper around GoogleMaps Direction API.
   pod 'GoogleMapsDirection', '~> 0.1.1'
   - Homepage: https://github.com/Djengo/GoogleMapsDirection
   - Source:   https://github.com/Djengo/GoogleMapsDirection.git
   - Versions: 0.1.1, 0.1.0, 0.0.2 [trunk repo]
...

いやいや、先頭のポッドの情報だけ欲しいんだけど。
ではこちらでいかがでしょうか?

$ pod trunk info GoogleMaps

GoogleMaps
    - Versions:
      - 1.10.0 (2015-05-27 21:46:03 UTC)
...
      - 5.1.0 (2021-06-28 18:50:55 UTC)
    - Owners:
      - Google <cocoapods@google.com>
...

これだとさっき出してた情報が削れちゃってるやん。
なるほどですねー。もしかして、お探しのものはこれですか?

$ pod spec cat GoogleMaps
{
  "authors": "Google, Inc.",
  "changelog": "https://dl.google.com/dl/cpdc/3cd76dc5e4525f42/GoogleMaps-5.1.0-CHANGELOG.md",
  "default_subspecs": [
    "Maps"
  ],
  "description": "Use the Google Maps SDK for iOS to enrich your app with interactive maps, immersive Street View panoramas, and detailed information from Google's Places database.",
  "homepage": "https://developers.google.com/maps/documentation/ios/",
  "license": {
    "text": "Copyright 2021 Google",
    "type": "Copyright"
  },
  "name": "GoogleMaps",
  "platforms": {
    "ios": "11.0"
  },
  "preserve_paths": [
    "Example/GoogleMapsDemos.xcodeproj/project.pbxproj",
...
    "SwiftExample/Podfile"
  ],
  "readme": "https://dl.google.com/dl/cpdc/3cd76dc5e4525f42/GoogleMaps-5.1.0-README.md",
  "source": {
    "http": "https://dl.google.com/dl/cpdc/3cd76dc5e4525f42/GoogleMaps-5.1.0.tar.gz"
  },
  "summary": "Google Maps SDK for iOS.",
  "version": "5.1.0",
  "subspecs": [
    {
...
    },
    {
      "dependencies": {
        "GoogleMaps/Maps": [

        ]
      },
      "name": "M4B",
      "vendored_frameworks": [
        "M4B/Frameworks/GoogleMapsM4B.framework"
      ]
    }
  ]
}

そうそう、こんな感じ。でも、コマンドの引数ってどうすんの?
それはもうお客様の方で Podfile.lock をパースするなりしてご用意いただくしか、、、

pod プラグイン

pod も何でもできる訳じゃないので、足りないものはプラグインで補充すればいいんですよ。

なんか期待しちゃうプラグインが 2 つ。試すしかない。

$ pod plugins
Downloading Plugins list...
...

-> Pod info
     Shows information on installed Pods.
     - Gem:     cocoapods-podfile_info
     - URL:     https://github.com/cocoapods/cocoapods-podfile_info

...

-> CocoaPods Query
     Shows all CocoaPods in a project filtered by search term (author name, source file, dependency, etc.)
     - Gem:     cocoapods-query
     - URL:     https://github.com/square/cocoapods-query
...

CocoaPods のプラグインは gem なので gem install でインストールします。CocoaPods は macOS ネイティブの Ruby の使用を推奨しているので、システムにインストールしちゃいます。

% pod podfile-info --all --csv

Pods used:

name,version,homepage,summary,license

何も出てこない。はい、残念。次。

$ pod query --to-yaml=pod-query.yml
Loading targets...
...
GoogleMaps
...

$ cat pod-query.yml
---
...
- :name: GoogleMaps
  :version: 4.2.0
  :authors:
  - :name: Google, Inc.
  :is_local: false
  :root_directory: "/***/Pods/GoogleMaps"
  :license:
    :text: Copyright 2021 Google
    :type: Copyright
  :summary: Google Maps SDK for iOS.
  :description: Use the Google Maps SDK for iOS to enrich your app with interactive
    maps, immersive Street View panoramas, and detailed information from Google's
    Places database.
  :homepage: https://developers.google.com/maps/documentation/ios/
  :uses_swift: false
  :readme_file: README.md
  :platforms:
  - :name: :ios
    :version: '10.0'
  :source_files: []
...

これやな。

最後の一手間

pod query の出力は情報過多なので、要らないものを削りたい。ていうか、このプラグインと同じデータの取り方をすれば欲しい情報だけを出力できるかも、と考えてソースコードを見てみます。150 行ほどありますが、知りたいことは all_targets() の 30 行ちょっとに集約されてます。これを参考にして冒頭のスクリプトができました。

という訳で、めでたし x2。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0