flatpak-builder icon indicating copy to clipboard operation
flatpak-builder copied to clipboard

Add support for external dir hasher

Open abergmeier opened this issue 2 years ago • 5 comments

Allows providing hash-cmd. Protocol is that cmd will be executed and output will be used to calculate dir checksum. If program fails - it falls back to rebuilding.

abergmeier avatar Dec 18 '23 10:12 abergmeier

@alexlarsson Mind to have a look? Seems like you said that checksumming dir was "not possible". Not sure what you meant.

abergmeier avatar Dec 18 '23 13:12 abergmeier

Can you give some real world examples of hash commands for an entire directory?

Also it is very common that a project uses a flatpak build dir inside of the same directory, which is impossible to say nothing changes, so maybe there should be a check for that.

TingPing avatar Dec 18 '23 17:12 TingPing

Can you give some real world examples of hash commands for an entire directory?

Also it is very common that a project uses a flatpak build dir inside of the same directory, which is impossible to say nothing changes, so maybe there should be a check for that.

I have most current experience with both Rust and Go. For both "a project uses a flatpak build dir inside of the same directory" is NOT an issue because they have either a very strict standard layout or mostly people adhere to best practices.

Thus the real world example for e.g. Golang would be:

build-options:
  env:
    GOBIN: /app/bin
    GOROOT: /usr/lib/sdk/golang
modules:
  - name: foo
    buildsystem: simple
    sources:
      - type: dir
        path: .
        hash-cmd: [go run ./cmd/dirhash cmd internal go.mod go.sum]
    build-commands: [
      "$GOROOT/bin/go build -C ./cmd/app -o foo",
      "install -Dm00755 gadget-app $FLATPAK_DEST/bin/foo",
    ]

dirhash here is a recursive hash program. Following best-practices in Go, source can be found in directories cmd, internal and pkg only. Also the only files in the root can be go.*. Note also that you do not need to handle vendor directory since it is a direct consequence of go.sum.

abergmeier avatar Dec 18 '23 19:12 abergmeier

The general question though is whether it would not be better to have a hash for every build-command...

abergmeier avatar Dec 18 '23 20:12 abergmeier

I don't think it should be per build-command. It is a departure from how f-b operates. Build commands aren't necessarily reproducible.

TingPing avatar Dec 19 '23 17:12 TingPing