devtoolの使い方 (4):修正(modify)とアップグレード(upgrade)

この投稿は連載:「devtoolの使い方」(全4回)の第4回です。

前回まででdevtool addを使った新規作成を確認しました。今回は残るコマンド modify, upgradeについて解説していきます。

add, modify, upgradeのおさらい

少しおさらいをしておきます。devtoolの開始の仕方として3種類ありますがそれぞれの意味は下記のとおりでした。

  • add : レシピを新規作成する(解説済)
  • modify : 既存のレシピに修正をかける
  • upgrade : レシピのパッケージのバージョンを更新する

今回はmodifyとupgradeについて見ていきます。

modify

ソースコードを修正する際に使用します。パッチの作成にはQuiltと呼ばれるツールを使用することもできますが、現在はdevtoolを使用することが推奨されています。

modifyについてもaddと同様に始め方が3種類あります。違いはaddの際とほぼ同様です。

  • 左 (devtool modify recipe):ソースツリーがローカルになく展開が必要な場合
  • 中央(devtool modify recipe srctree):ソースツリーがローカルになく展開が必要だが、ソースの展開先を指定したい場合
  • 右 (devtool modify -n recipe srctree):すでにソースツリーがローカルに存在している場合

実際に作成したslレシピのソースを簡単に修正してみます。現時点でレシピを修正中の状態(devtool statusでslレシピが見える)ならいったんresetしておきます。また、workspaceにソースが展開され直すため、slのソースも消しておきます。

devtool reset sl
rm -r ${BUILDDIR}/workspace/sources/sl
devtool modify sl

まったく役に立たない修正ですがSLの車体に名前を入れてみます。

diff --git a/sl.h b/sl.h
index fbf6938..c7f1553 100644
--- a/sl.h
+++ b/sl.h
@@ -52,7 +52,7 @@
 #define COAL03 "    _________________         "
 #define COAL04 "   _|                \\_____A  "
 #define COAL05 " =|                        |  "
-#define COAL06 " -|                        |  "
+#define COAL06 " -|       Kumadasu         |  "
 #define COAL07 "__|________________________|_ "
 #define COAL08 "|__________________________|_ "
 #define COAL09 "   |_D__D__D_|  |_D__D__D_|   "

下記コマンドでビルド及び転送して動作確認できます。名前の入った荷台がQEMU上で走り去ることが確認できます。

devtool build sl
devtool deploy-target sl [email protected]

次はaddの時と同様にしてfinishコマンドでレイヤを指定して修正を完了します。

cd ${BUILDDIR}/workspace/sources/sl
git commit "Add name on the cargo."
cd ${BUILDDIR}
devtool finish sl meta-learning-devtool

実際の出力は下記の通りです。パッチファイルとbbappendファイルが生成されました。

sakate@walle:~/git/poky/build$ devtool finish sl meta-learning-devtool/
Parsing recipes..done.
NOTE: Writing append file /home/sakate/git/poky/build/meta-learning-devtool/recipes-sl/sl/sl_%.bbappend
NOTE: Copying /tmp/devtool970ac7qx/tmph846o90g/0001-Add-name-on-the-cargo.patch to /home/sakate/git/poky/build/meta-learning-devtool/recipes-sl/sl/sl/0001-Add-name-on-the-cargo.patch
NOTE: Cleaning sysroot for recipe sl...
NOTE: Leaving source tree /home/sakate/git/poky/build/workspace/sources/sl as-is; if you no longer need it then please delete it manually

modify完了後のmeta-learning-devtoolは下記のようになります。元はbbファイルとpatchが1つでしたが、bbappend, patchがそれぞれ増えていますね。

sakate@walle:~/git/poky/build$ tree meta-learning-devtool/
meta-learning-devtool/
├── COPYING.MIT
├── README
├── conf
│   └── layer.conf
└── recipes-sl
    └── sl
        ├── sl
        │   ├── 0001-Add-name-on-the-cargo.patch
        │   └── 0001-Change-toolchain-for-recipe.patch
        ├── sl_%.bbappend
        └── sl_git.bb

4 directories, 7 files

upgrade(失敗)

アップストリームのソースコードのバージョンが上がった場合に使用します。slコマンドのバージョンが上がったりはしていませんが、仮に上がったと想定して進めてみます。

アップストリームのバージョンが変わったということはこれまでに作成したパッチは再適用が必要であったり、すでに取り込み済みで不要になっていたりするため、これらを解決する必要があります。これらの大変さがあるため、upgradeはmodifyよりも大きな変更という印象を受けます。

upgradeの場合は少し複雑なためか公式の解説図がadd/modifyと違って始め方が一通りになっています。説明を読んでいると必ずしもそうではないように見えます。

devtool upgrade –help

  • devtool upgrade -V version recipe

一応上のコマンドが基本のようなのですが、他のオプションも必要になるのでhelpを載せておきます。

sakate@walle:~/git/poky/build/workspace/sources/sl$ devtool upgrade --help
usage: devtool upgrade [-h] [--version VERSION] [--srcrev SRCREV]
                       [--srcbranch SRCBRANCH] [--branch BRANCH] [--no-patch]
                       [--same-dir | --no-same-dir] [--keep-temp]
                       recipename [srctree]

Upgrades an existing recipe to a new upstream version. Puts the upgraded
recipe file into the workspace along with any associated files, and extracts
the source tree to a specified location (in case patches need rebasing or
adding to as a result of the upgrade).

arguments:
  recipename            Name of recipe to upgrade (just name - no version,
                        path or extension)
  srctree               Path to where to extract the source tree. If not
                        specified, a subdirectory of
                        /home/sakate/git/poky/build/workspace/sources will be
                        used.

options:
  -h, --help            show this help message and exit
  --version VERSION, -V VERSION
                        Version to upgrade to (PV)
  --srcrev SRCREV, -S SRCREV
                        Source revision to upgrade to (required if fetching
                        from an SCM such as git)
  --srcbranch SRCBRANCH, -B SRCBRANCH
                        Branch in source repository containing the revision to
                        use (if fetching from an SCM such as git)
  --branch BRANCH, -b BRANCH
                        Name for new development branch to checkout (default
                        "devtool")
  --no-patch            Do not apply patches from the recipe to the new source
                        code
  --same-dir, -s        Build in same directory as source
  --no-same-dir         Force build in a separate build directory
  --keep-temp           Keep temporary directory (for debugging)

一部のオプションを説明します。

  • –version, -V:PVとありますが、Package Versionの意味でソフトウェアそのもののバージョンの意味になります。例えばslにversion2.0が出ればPV=2.0が対応します。レシピそのもののリビジョンPRとは異なります。PVが変わった場合、PRはr0にリセットされます。
  • –srcrev, -S:gitなどのSCMを使用している場合はこのオプションでソースのリビジョンを指定します。
  • –srcbranch, -B:こちらも-Sと同様でブランチをしていします。
  • –no-patch:新しいソースコードにパッチを適用しないオプションです。アップストリームのソースコードが大きく変化している、もしくは、アップストリームに取り込まれたパッチが多くコンフリクトの解消が大変な場合に活用するのだと考えられます。

devtool upgradeによる更新

試しにslコマンドでupgradeを試してみましょう。tagに5.02というバージョンがあるのでこれを試してみます。といってもtagを指定する方法が見つからないのでコミットのハッシュを指定します。最新版と比較するといくらか差分があるようです。

rm -r ${BUILDDIR}/workspace/sources/sl
devtool upgrade -V 5.02 -S 0fd8d6f6484cddc2b58ffa501b9ae0bf0b3f0742 sl

うまくいきません

すみません、うまくいきません。うまく行かないというか、git rebaseをしようとしているようなので、このままだとコンフリクトを解消すると今のバージョンになってしまいそうです。通常の場合はこれでコンフリクトを解消してもらえれば大丈夫だと思います。今回はあえて古いバージョンに戻そうとしているので、このままではうまく行きません。

sakate@walle:~/git/poky/build$ devtool upgrade -V 5.02 -S 0fd8d6f6484cddc2b58ffa501b9ae0bf0b3f0742 sl
Parsing recipes..done.
NOTE: Fetching sl...
NOTE: Unpacking...
NOTE: Patching...
WARNING: Command 'git rebase 0fd8d6f6484cddc2b58ffa501b9ae0bf0b3f0742' failed:
First, rewinding head to replay your work on top of it...
Applying: Fix typo: HIGHT->HEIGHT
Applying: return 0 from main()
Applying: properly declare our extern variables.
Applying: Improve Makefile, this is a part of patch from Hiroyuki Yamamoto
Using index info to reconstruct a base tree...
M   Makefile
Falling back to patching base and 3-way merge...
Auto-merging Makefile
CONFLICT (content): Merge conflict in Makefile
Failed to merge in the changes.
Patch failed at 0004 Improve Makefile, this is a part of patch from Hiroyuki Yamamoto
The copy of the patch that failed is found in:
   /home/sakate/git/poky/build/workspace/sources/sl/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

You will need to resolve conflicts in order to complete the upgrade.
NOTE: Using source tree as build directory since that would be the default for this recipe
NOTE: Upgraded source extracted to /home/sakate/git/poky/build/workspace/sources/sl
NOTE: New recipe is /home/sakate/git/poky/build/workspace/recipes/sl/sl_git.bb
devtool reset sl
rm -r ${BUILDDIR}/workspace/sources/sl
devtool upgrade -V 5.02 -S 0fd8d6f6484cddc2b58ffa501b9ae0bf0b3f0742 --no-patch sl

今度はパッチを適用しないオプションを加えて実施してみました。今度はうまくいきました。

sakate@walle:~/git/poky/build$ devtool upgrade -V 5.02 -S 0fd8d6f6484cddc2b58ffa501b9ae0bf0b3f0742 --no-patch sl
Parsing recipes..done.
NOTE: Fetching sl...
NOTE: Unpacking...
NOTE: Patching...
WARNING: By user choice, the following patches will NOT be applied
WARNING: 0001-Change-toolchain-for-recipe.patch
WARNING: 0001-Add-name-on-the-cargo.patch
NOTE: Using source tree as build directory since that would be the default for this recipe
NOTE: Upgraded source extracted to /home/sakate/git/poky/build/workspace/sources/sl
NOTE: New recipe is /home/sakate/git/poky/build/workspace/recipes/sl/sl_git.bb

作成したパッチは適用されなかったようです。

このままビルドすると、ツールチェーンが原因のエラーが発生します。Makefileに過去に生成したpatchファイルを適用しようとしましたが、Makefileそのものに変更が加わっていたため今回も手動で修正を加え、git commitしました。

diff --git a/Makefile b/Makefile
index 73a60b3..3a38b8d 100644
--- a/Makefile
+++ b/Makefile
@@ -6,8 +6,5 @@
 #      Last Modified: 2014/03/31
 #==========================================
 
-CC=gcc
-CFLAGS=-O
-
 sl: sl.c sl.h
-       $(CC) $(CFLAGS) -o sl sl.c -lncurses
+       $(CC) $(CFLAGS) ${LDFLAGS} -o sl sl.c -lncurses

これでビルドが通るようになり、deployもできるようになりました。荷台に名前をつける変更は適用していないので、この時点では名前をつける前のSLになります。

git commit -m "Change toolchain for recipe"
devtool build sl
devtool deploy-target sl [email protected]

 

cd ${BUILDDIR}
devtool finish sl meta-learning-devtool/

実行結果は下記です。なんだかうまくいっているように見えてうまく行っていないですね。本当はsl_5.02.bbのようなファイル名のレシピになって欲しかったのですが・・・。正しいやり方はよくわかりません。bitbake slも通らなくなりました。先のMakefileのパッチが適用できないようです。コミットメッセージを同じしてしまったので0001-Change-toolchain-for-recipe.patchをupdateしているメッセージが出ている点がもしかすると良くなかったのかもしれません。

sakate@walle:~/git/poky/build$ devtool finish sl meta-learning-devtool/
Parsing recipes..done.
NOTE: Updating patch 0001-Change-toolchain-for-recipe.patch
NOTE: Updating recipe sl_git.bb
NOTE: Removing file /home/sakate/git/poky/build/meta-learning-devtool/recipes-sl/sl/sl/0001-Add-name-on-the-cargo.patch
NOTE: Moving recipe file to /home/sakate/git/poky/build/meta-learning-devtool/recipes-sl/sl
NOTE: Cleaning sysroot for recipe sl...
NOTE: Leaving source tree /home/sakate/git/poky/build/workspace/sources/sl as-is; if you no longer need it then please delete it manually

upgradeを試すときは元のレシピが消えないように気をつけて実施してみてください。パッチファイルはそのままですがレシピはPVなどのバージョンが入るようになって少し中途半端な状態でbitbakeでビルドできない状態になりました。

upgradeのサンプルとしてslはあまり適切ではないようにも思いますので、一旦ここでこの記事は終わりにします。upgradeがうまく使えたりしましたらコメント欄などでお知らせいただけると嬉しいです。

次回はdevtoolを含めたWorkflow周りについて調べていこうと思います。

シリーズ:devtoolの使い方<< devtoolの使い方 (3):QEMUによる動作確認(deploy-target)と作成完了(finish)

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

5 × five =

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください