LoginSignup
3
1

More than 3 years have passed since last update.

PlatformIO のライブラリを登録してみた

Posted at

PlatformIO に自作ライブラリを登録してみたのですが、意外とすんなりいかなかったので、手順をまとめてみました。

ライブラリを作成する

おおよそ公式ドキュメント通りです。
このディレクトリを tar ball でかためて公開することになるので、試行錯誤したファイルなどを残さないように注意しましょう。
.git/ ディレクトリは無視してくれるようです。

例として ExampleLibrary を作るものとすると、ディレクトリ構成はおおよそこんなかんじでしょうか。

ExampleLibrary/
├── LICENSE
├── README.md
├── examples
│   └── main.c
├── include
│   └── Example.h
├── library.json
└── src
    └── Example.c

library.json

これも公式ドキュメント通りで、最短だとこんなかんじでしょうか。

{
  "name": "ExampleLibrary",
  "version": "0.0.1",
  "description": "Example Library Project",
  "keywords": "example",
  "repository":
  {
    "type": "git",
    "url": "https://github.com/example/ExampleLibrary.git"
  },
  "authors":
  [
    {
      "name": "John Smith",
      "email": "john@example.com",
      "url": "https://github.com/example",
      "maintainer": true
    }
  ],
  "license": "MIT",
  "homepage": "https://github.com/example/ExampleLibrary",
  "frameworks": "*",
  "platforms": "*"
}

自分がハマったのは "name" と "version" フィールドです。

"name" に空白を入れる、バージョン名を x.y.z-n の形式にする、というのをやってしまったのですが、これをすると色々と壊れるようです。

またバージョンは、慣れないうちは 0.0.1 とか付けておくと良さそうです。
公開したパッケージは pio package unpublish で取り下げることができるのですが、パッケージ自体はサーバに残るようで、同じバージョンで再度 publish してもエラーになります。
つまり失敗すると同じバージョン名で publish できなくなります。

公開するファイルの確認

以下を実行すると同じディレクトリに tar ball ができるので、公開前に余計なファイルが紛れ込んでいないかなど確認することができます。

pio package pack ExampleLibrary/ 

アカウント作成

ライブラリの公開には PlatformIO.org にアカウントが必要です。
このアカウントは CLI から作成します。(Webからは作れないようです)

$ pio account register
Username: example
Email: john@example.com
Password: 
Repeat for confirmation: 
Firstname: Jhon
Lastname: Smith

完了するとメールが届くので、そのメール内のリンクを開いてconfirmします。

公開!

公開する前にログインしておく必要があります。

$ pio account login
Username or email: example
Password: 
Successfully logged in!
pio package publish $PWD/ExampleLibrary

ここで指定するディレクトリパスは絶対パスを指定します。(相対パスだとエラーになります)

3
1
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
3
1