Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions scripts/make_git_package.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/usr/bin/env bash
#
# Note env variables: DESTDIR, BUILDROOT, GOCACHE, BUILDDIR
# Env vars:
# Required (set by mkosi):
# DESTDIR, BUILDROOT, BUILDDIR, GOCACHE
# Optional (caller-controlled):
# MAKE_GIT_PACKAGE_CACHE_KEY_EXTRA — extra input to the cache key.
# Set by callers in mkosi.build to invalidate cached binaries
# when build-env state outside $build_cmd changes. See the
# env_hash computation in make_git_package below.

make_git_package() {
local package="$1"
Expand Down Expand Up @@ -29,7 +36,18 @@ make_git_package() {
local git_describe=$( git -C "$build_dir" describe --always --long --tags )
printf "${git_describe#$package/}" > "$BUILDDIR/$package.git"

local cache_dir="$BUILDDIR/${package}-${git_describe#${package}/}"
local env_hash=$(
{
# We hash the build_cmd into the cache dire to catch
# RUSTFLAGS / GOFLAGS / cargo profile / command shape changes.
printf '%s' "$build_cmd"
# Callers can also inject additional inputs. Useful for things like
# RUST_VERSION (if installed via rustup), so that changing
# the Rust toolchain invalidates cached Rust binaries.
printf '%s' "${MAKE_GIT_PACKAGE_CACHE_KEY_EXTRA:-}"
} | sha256sum | cut -c1-12
)
local cache_dir="$BUILDDIR/${package}-${git_describe#${package}/}-${env_hash}"

# Use cached artifacts if available
if [ -n "$cache_dir" ] && [ -d "$cache_dir" ] && [ "$(ls -A "$cache_dir" 2>/dev/null)" ]; then
Expand Down