章 7. Sanitization of the source

內容目錄

7.1. Fix with Files-Excluded
7.2. Fix with debian/rules clean
7.3. Fix with extend-diff-ignore
7.4. Fix with tar-ignore
7.5. Fix with git clean -dfx

There are a few cases which require to sanitize the source to prevent contaminating the generated Debian source package.

以下幾種方法均可避免引入不必要的內容。

This is suitable for avoiding non DFSG contents in the upstream source tarball.

  • debian/copyright 檔案中的 Files-Excluded 一節中列出需要移除的檔案。
  • debian/watch 檔案中列出下載上游原始碼套件(tarball)所使用的 URL。
  • 執行 uscan 命令以下載新的上游原始碼套件(tarball)。

    • Alternatively, use the gbp import-orig --uscan --pristine-tar command.
  • mk-origtargz invoked from uscan removes excluded files from the upstream tarball and repack it as a clean tarball.
  • 最後得到 tarball 的版本編號會附加一個額外的字尾 +dfsg

See COPYRIGHT FILE EXAMPLES in mk-origtargz(1).

This is suitable for avoiding auto-generated files and removes them in the debian/rules clean target

[注意]注意

The debian/rules clean target is called before the dpkg-source --build command by the dpkg-buildpackage command and the dpkg-source --build command ignores removed files.

This is for the non-native Debian package.

The problem of extraneous diffs can be fixed by ignoring changes made to parts of the source tree by adding the extend-diff-ignore=…​ line in the debian/source/options file.

debian/source/options to exclude the config.sub, config.guess and Makefile files: 

# Don't store changes on autogenerated files
extend-diff-ignore = "(^|/)(config\.sub|config\.guess|Makefile)$"

[注意]注意

即使您無法刪除檔案,這種做法總可以正常工作。您無需在每次構建之前手動刪除檔案並手動進行恢復。

[提示]提示

如果您轉而使用 debian/source/local-options 檔案,您可以在生成的原始碼套件中隱藏該項設定。這種做法在本地非標準版本控制系統和您的打包工作有衝突時可能有用。

This is for the native Debian package.

You can exclude some files in the source tree from the generated tarball by tweaking the file glob by adding the tar-ignore=…​ lines in the debian/source/options or debian/source/local-options files.

[注意]注意

If, for example, the source package of a native package needs files with the file extension .o as a part of the test data, the setting in 節 4.5, “devscripts setup” is too aggressive. You can work around this problem by dropping the -I option for DEBUILD_DPKG_BUILDPACKAGE_OPTS in 節 4.5, “devscripts setup” while adding the tar-ignore=…​ lines in the debian/source/local-options file for each package.

The problem of extraneous contents in the second build can be avoided by restoring the source tree by committing the source tree to the Git repository before the first build.

您可以在第二次構建套件之前恢復最初的原始碼樹。例如:

 $ git reset --hard
 $ git clean -dfx

這裡工作的原理是 dpkg-source 命令會忽略原始碼樹中典型的版本控制系統相關的檔案,相關的設定可以在 節 4.5, “devscripts setup”DEBUILD_DPKG_BUILDPACKAGE_OPTS 設定中找到。

[提示]提示

If the source tree is not managed by a VCS, you should run git init; git add -A .; git commit before the first build.