Namcap

提供: ArchWiki
ナビゲーションに移動 検索に移動

Namcap は、パッケージを作るときによくある間違いがバイナリパッケージやソース PKGBUILD に存在しないかチェックするツールです。自動的に有効にすることもできます。Namcap は Jason Chu によって開発されました。

変更点: git リポジトリの NEWS ファイルに前のバージョンからの変更点が簡単に説明されています。

開発ブランチ: https://git.archlinux.org/namcap.git/

namcap についてバグを報告したり機能リクエストをする場合は、Arch Linux のバグトラッカーPackages:Extra セクションにバグを作成して適当に重要度を設定してください。バグを報告するときは、問題が発生するパッケージの具体例とバージョン番号を忘れずに付け加えることをお願いします。

(バグを修正したり、新しい namcap モジュールの) パッチを作った場合、arch-projects メーリングリストに送ることができます。Namcap の開発は git によって行われているため、git フォーマットにそったパッチが好ましいとされます。

インストール

namcap パッケージをインストールしてください。

使用方法

PKGBUILD やバイナリの pkg.tar.xz で namcap を実行する:

$ namcap FILENAME

追加情報のメッセージを見たい場合は、-i フラグを付けて namcap を実行します:

$ namcap -i FILENAME

詳しい使い方は man ページの namcap(1) を見てください。

出力の解釈

Namcap は出力を分類するためにタグシステムを使っています。現在、タグには エラー (error, E), ワーニング (warning, W), インフォメーション (informational, I) の3種類があります。エラーは問題が重大で、すぐに修正したほうがよいでしょう。ほとんどの場合、セキュリティの欠陥や、ライセンスが設定されてない、またはパーミッション関連の問題がエラーになります。

通常 namcap は人間が読める形で説明を出力します (場合によっては問題を修正するための方法の提案も付きます)。プログラムが簡単にパース出来るように出力させたい場合は、namcap に -m (machine-readable) フラグを渡して下さい (この機能は現在開発ブランチにあります)。

タグ

シンボリックリンク

  • symlink-found (informational) パッケージ内にシンボリックリンクが存在しています。
  • hardlink-found (informational) パッケージ内にハードリンクが存在しています。
  • dangling-symlink (error) パッケージ内に存在しないファイルのシンボリックリンクが存在しています。
  • dangling-hardlink (error) パッケージ内に存在しないファイルのハードリンクが存在しています。

依存関係

  • link-level-dependence (informational) パッケージが動的リンクしているライブラリについての情報。
  • dependency-is-testing-release (warning) 依存パッケージが [testing] リポジトリにあります。パッケージを公式の Arch Linux リポジトリ (core, extra, community) のためにビルドする場合、[testing] のパッケージを利用するビルドをしてはいけません。[core] や [extra] のパッケージの場合、[testing] を使ってビルドするパッケージは [testing] リポジトリに置くべきです。
  • dependency-covered-by-link-dependence (informational) 依存パッケージのリンクしている依存パッケージによって依存関係が満たされています。つまりこれは依存パッケージが余分だということです。
  • dependency-detected-not-included (error) ファイルが参照している先に depends 行に記載されていない依存パッケージが含まれています。optdepends 行に依存パッケージが載っている場合はこのエラーは無視して下さい。
  • dependency-already-satisfied (warning) 依存関係が既に満たされています (例えばあるパッケージの依存パッケージがすでに依存として記載されている)。つまり余分な依存パッケージです。pacman に含まれている pactree ツールを使うことでパッケージの依存関係ツリーを見ることができます。
  • dependency-not-needed (warning) 依存パッケージがプログラム内に存在するどのファイルからも (namcap が推論できる限りでは) 必要とされていません。ただしスクリプトのパッケージ (python や perl パッケージなど) の場合はこの警告は正しくない場合があり、各自で依存関係を調べて下さい。
  • depends-by-namcap-sight (informational) namcap による依存パッケージのリスト。

ライセンス

  • missing-license (error) パッケージにライセンスが明記されていません。PKGBUILD の license=() 行にライセンスを記述してください。詳しくは Arch パッケージングスタンダードを見て下さい。ライセンスが含まれていないと著作権侵害になる場合が多いため、出来る限り早くこのエラーを解決するのが非常に重要です。
  • missing-custom-license-dir (error) ライセンスが custom となっているのにパッケージングガイドラインで指定されている /usr/share/licenses/ にライセンスディレクトリが存在しません。
  • missing-custom-license-file (error) ライセンスが custom となっているのにライセンスファイルが /usr/share/licenses/$pkgname に存在しません。
  • not-a-common-license (error) ライセンスが custom ではないのにかかわらず Arch Linux ディストリビューションにある licenses パッケージに標準的なライセンスとして含まれていません。

ファイル

このセクションでは、ファイルの不適切なパーミッションや、FHS ガイドラインに従ってインストールされてないファイルなどに関するタグを説明しています。

  • script-link-detected (informational) 示されているファイルはスクリプトです。
  • file-in-non-standard-dir (warning) ファイルが FHS ガイドライン によって定義されている標準ディレクトリ以外に存在します。認定されているディレクトリは: bin/, etc/, usr/bin/, usr/sbin/, usr/lib, usr/include/, usr/share/, opt/, lib/, sbin/, srv/, var/lib/, var/opt/, var/spool/, var/lock/, var/state/, var/run/, var/log/
  • elffile-not-in-allowed-dirs (error) ELF ファイルは以下のディレクトリに配置しなくてはなりません: /lib, /bin, /sbin, /usr/bin, /usr/sbin, /lib, /usr/lib, /opt/$pkgname/
  • empty-directory (warning) パッケージ内のディレクトリが空です。
  • non-fhs-man-page (error) FHS ガイドライン によってマニュアルページのためのディレクトリとされている /usr/share/man 以外の場所にパッケージがマニュアルページをインストールしています。
  • potential-non-fhs-man-page (warning) マニュアルページが /usr/share/man にインストールされていません。ただし namcap は man ページを確実に認識できるわけではありません。
  • FHS ガイドライン によってアーキテクチャと無関係なデータをインストールする場所とされている /usr/share/info 以外の場所にパッケージが info ページをインストールしています。
  • potential-non-fhs-info-page (warning) インフォページが /usr/share/info にインストールされていません。ただし namcap は info ページを確実に認識できるわけではありません。
  • incorrect-permissions (error) ファイルの所有者が不適切です。バイナリパッケージ内のファイルの所有者は root/root にしてください。
  • file-not-world-readable (warning) ファイルが誰にも読まれないようになっています。通常はこうなっていません。
  • file-world-writable (warning) 誰でもファイルに書き込みができるようになっています。同じく、典型から外れます。
  • directory-not-world-executable (warning) ディレクトリに誰からも実行可能なビットが設定されていません。ユーザー権限で実行されているプログラムからディレクトリにアクセスできなくなります。
  • incorrect-library-permissions (warning) 静的ライブラリファイル (.a) のパーミッションが 644 になっていません (root で読み書き可能、誰でも読み取り可能)。
  • libtool-file-present (warning) 通常は存在しないはずの libtool (.la) ファイルが存在します。PKGBUILD の options 行に !libtool オプションを追加することで自動的に削除できます。
  • perllocal-pod-present (error) perl パッケージに perllocal.pod ファイルが存在してはいけません。詳しくは Perl パッケージガイドラインを見て下さい。
  • scrollkeeper-dir-exists (error) scrollkeeper ディレクトリがパッケージに存在します。scrollkeeper は post_{install,upgrade,remove} まで実行してはいけません。
  • info-dir-file-present (error) info ディレクトリファイル /usr/share/info/dir がパッケージに存在します。このファイルが存在してはいけません。
  • gnome-mime-file (error) 自動生成された GNOME mime ファイルがパッケージ内に存在してはいけません。

その他

  • insecure-rpath (error) (実行ファイルの) RPATH が /usr/lib の外にあります。安全でない場所に RPATH があるとセキュリティに問題が発生する可能性があります。詳しくは FS#14049 を参照。

PKGBUILD

PKGBUILD に関連するタグです。いくつかはバイナリパッケージにも適用されます。

  • variable-not-array (warning) 文字列ではなく bash 配列であるべき変数です。配列として変数を定義してください: arch, license, depends, makedepends, optdepends, provides, conflicts, replaces, backup, source, noextract, md5sums
  • backups-preceding-slashes (error) backup 行に載っているファイルがスラッシュ ('/') で始まっています。
  • package-name-in-uppercase (error) パッケージの名前に大文字を含めてはいけません。
  • specific-host-type-used (warning) 特定のホストタイプ (i686 あるいは x86_64 など) を使う代わりに汎用の $CARCH 変数を使ってください。
  • extra-var-begins-without-underscore (warning) PKGBUILD マニュアルに定義されている標準変数でないのに、アンダースコアから始まっていません。
  • file-referred-in-startdir (error) $startdir$startdir/pkg$startdir/src の外側にファイルが参照されています。
  • missing-md5sums (error) ソースファイルに対応する MD5sum が存在しません。pacman-contrib パッケージに含まれる updpkgsums を使って PKGBUILD にチェックサムを追加することができます。
  • not-enough-md5sums (error) MD5sum よりも多くのソースファイルが PKGBUILD に指定されています。
  • too-many-md5sums (error) ソースファイルよりも多くの MD5sum が PKGBUILD に記述されています。
  • improper-md5sum (error) 不正な MD5sum です。MD5sum は32字の文字列になります。
  • specific-sourceforge-mirror (warning) PKGBUILD が特定の sourceforge ミラーを使っています。代わりに http://downloads.sourceforge.net を使って下さい。
  • using-dl-sourceforge (warning) source 行で今はもう使われなくなった http://dl.sourceforge.net ドメインが使用されています。代わりに http://downloads.sourceforge.net を使って下さい。
  • missing-contributor (warning) contributor タグが見つかりません。
  • missing-maintainer (warning) maintainer タグが見つかりません。
  • missing-url (error) パッケージに上流のホームページが設定されていません。url 変数を使って下さい。
  • pkgname-in-description (warning) 説明にパッケージ名が含まれていません。
  • recommend-use-pkgdir (informational) $startdir/pkg は廃止されました、代わりに $pkgdir を使って下さい。
  • recommend-use-srcdir (informational) $startdir/src は廃止されました、代わりに $srcdir を使って下さい。

未リリース

現在、開発版に新規タグは存在しません。

namcap モジュールの作成

このセクションは namcap 内部の話であり新しい namcap モジュールの作り方を説明しています。

namcap のメインプログラム namcap.py はパラメータとしてパッケージのファイル名あるいは PKGBUILD を認識して pkginfo オブジェクトを作成します。そして __tarball____pkgbuild__ に定義されているルールのリストにオブジェクトが渡されます。

  • __tarball__ にはバイナリパッケージを処理するルールが定義されます。
  • __pkgbuild__ には PKGBUILD を処理するルールが定義されます。

モジュールを作成したら、Namcap/__init__.py に定義されている適切な配列 (__tarball__ または __pkgbuild__) にモジュールを追加してください。

namcap のサンプルモジュール:

namcap/url.py
  import pacman

  class package:
  	def short_name(self):
		return "url"
	def long_name(self):
		return "Verifies url is included in a PKGBUILD"
	def prereq(self):
		return ""
	def analyze(self, pkginfo, tar):
		ret = [[],[],[]]
		if not hasattr(pkginfo, 'url'):
			ret[0].append(("missing-url", ()))
		return ret
	def type(self):
		return "pkgbuild"

Mostly, the code is self-explanatory. The following are the list of the methods that each namcap module must have:

  • short_name(self) Returns a string containing a short name of the module. Usually, this is the same as the basename of the module file.
  • long_name(self) Returns a string containing a concise description of the module. This description is used when listing all the rules using namcap -r list.
  • prereq(self) Return a string containing the prerequisites needed for the module to operate properly. Usually "" for modules processing PKGBUILDs and "tar" for modules processing package files. "extract" should be specified if the package contents should be extracted to a temporary directory before further processing.
  • analyze(self, pkginfo, tar) Should return a list comprising in turn of three lists: of error tags, warning tags and information tags respectively. Each member of these tag lists should be a tuple consisting of two components: the short, hyphenated form of the tag with the appropriate format specifiers (%s, etc.) The first word of this string must be the tag name. The human readable form of the tag should be put in the tags file. The format of the tags file is described below; and the parameters which should replace the format specifier tokens in the final output.
  • type(self) "pkgbuild" for a module processing PKGBUILDs, "tarball" for a module processing a binary package file.

The tags file consists of lines specifying the human readable form of the hyphenated tags used in the namcap code. A line beginning with a '#' is treated as a comment. Otherwise the format of the file is:

 machine-parseable-tag %s :: This is machine parseable tag %s

Note that a double colon (::) is used to separate the hyphenated tag from the human readable description.

Namcap レポート

namcap-reports は core, extra, community ツリーに対して namcap を実行して自動的に生成されるレポートです。

仕組み:

  • namcap is run against the entire ABS tree to make namcap.log.
  • The packages in core, extra and community are put in files named core, extra and community respectively (using pacman -Slq).
  • namcap-report.py takes the code and prepares the report and RSS feeds, which is then copied to the webserver.