03.6 模块源

本页面将深入介绍每种源类型并附带示例。

源文件在构建开始前被复制或下载到源目录。源目录位于 flatpak-builder 的状态目录下,默认情况下在主机上相对于清单根目录的 .flatpak-builder 位置。

源的 type 属性决定了在构建之前或期间如何处理该源。

大多数源支持 path 和 url 属性,其中 path 相对于清单的根目录,url 是源的直接链接。

url 属性要求使用 sha256 或 sha512 指定校验和。

有几个所有源类型通用的属性:only-arches、skip-arches 和 dest。

归档源

类型为 archive 的源。它们在构建开始时被下载到下载目录并提取到构建目录中。

modules:
  - name: foo
    buildsystem: meson
    sources:
      - type: archive
        url: https://example.org/foo-1.0.tar.xz
        sha256: 26c9007c655483438d83f17070190fc4b6bccb8ff5efc30fcedbb7d162681a7f

支持的归档类型:rpm、tar、tar-gzip、tar-bzip2、tar-xz、tar-zst、zip、7z 等。

Git 源

类型为 git 的源,需要主机上安装 git。

modules:
  - name: foo
    buildsystem: meson
    sources:
      - type: git
        url: https://example.org/repo/foo.git
        tag: <git 标签>
        commit: <提交哈希>

文件源

类型为 file 的源。它们被复制到源目录中,不做任何修改。

modules:
  - name: foo
    buildsystem: simple
    build-commands:
     - install -Dm0644 org.example.foo.metainfo.xml -t ${FLATPAK_DEST}/share/metainfo/
    sources:
      - type: file
        url: https://example.org/foo-v1.0.deb
        sha256: <sha256 校验和>
      - type: file
        path: org.example.foo.metainfo.xml

补丁源

类型为 patch 的源,用于补丁文件。

modules:
  - name: foo
    sources:
      - type: git
        url: https://example.org/foo.git
        tag: v1.0.0
        commit: 63c01f14391aef7d7691c7c63a610d47512147ed
      - type: patch
        path: patches/test-patch.patch

Shell 和 Script 源

Shell 源(type: shell)用于在提取过程中修改源。Script 源(type: script)用于创建自包含的 /bin/sh 脚本。

额外数据(Extra Data)

额外数据常用于专有应用程序,通过在用户安装时下载原始分发者提供的二进制包来避免重新分发。

modules:
  - name: foo
    buildsystem: simple
    build-commands:
      - install -Dm755 apply_extra ${FLATPAK_DEST}/bin/apply_extra
    sources:
      - type: extra-data
        filename: foo.snap
        url: https://example.org/foo_v1.2.snap
        sha256: 842ab8e69c94e985ba188cc22848c0515e9fa114380adcc08572d3fb9cfa19db
        size: 123101184
      - type: script
        dest-filename: apply_extra
        commands:
          - unsquashfs -quiet -no-progress foo.snap
          - mv squashfs-root/usr/lib/foo/* .
          - rm -r squashfs-root foo.snap

目录源

类型为 dir 的目录源最适合在 CI 中使用,用于构建最新更改并避免多次下载。

modules:
  - name: foo
    buildsystem: simple
    sources:
      - type: dir
        path: icons