Skip to content

Commit

Permalink
Make build cache a function of the glfw C sources
Browse files Browse the repository at this point in the history
This is a workaround for the issue described in go-gl#269. Go unfortunately doesn't
consider the C source files as part of its build cache calculation. Therefore,
invalidate it by writing a hash which is computed across the full C source
directory.

This hash is only updated when `go generate` is called, but this will at least
help the majority of users, when glfw is updated. This is encoded in
grab-upstream.sh which is used for updating the sources.

This hash is intended to be protected from divergance by CI, too.

Resolves go-gl#269.
  • Loading branch information
pwaller committed Mar 6, 2021
1 parent d2be909 commit b8ba9a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
15 changes: 15 additions & 0 deletions scripts/glfw_tree_rebuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

# This script computes the hash of the directory called "glfw", relative to $PWD
# at time of invocation, and writes it into the upstreamTreeSHA constant in
# glfw_tree_rebuild.go. Invoke this in a directory containing
# glfw_tree_rebuild.go.

export GIT_INDEX_FILE=$(mktemp)
rm $GIT_INDEX_FILE
git update-index
git add glfw
HASH=$(git write-tree)
rm $GIT_INDEX_FILE

sed -Ei 's/const upstreamTreeSHA = "[0-9a-f]+"/const upstreamTreeSHA = "'${HASH}'"/' glfw_tree_rebuild.go
6 changes: 4 additions & 2 deletions scripts/grab-upstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ EOF

rm v3.3/glfw/glfw/README.md
ln -sr v3.3/glfw/glfw/src/wayland-xdg-decoration-{unstable-v1-,}client-protocol.h

go generate ./v3.3/glfw/glfw_tree_rebuild.go
}

if test -n "$(git status --porcelain ./*/glfw/glfw)"; then
if test -n "$(git status --porcelain ./*/glfw)"; then

git status ./*/glfw/glfw
git status ./*/glfw

{
echo
Expand Down
10 changes: 10 additions & 0 deletions v3.3/glfw/glfw_tree_rebuild.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package glfw

//go:generate ../../scripts/glfw_tree_rebuild.sh

// This is a recursive hash of the full contents of the upstream glfw, as
// generated by git (doesn't need to be committed) when you run `go generate` on
// this package. This exists to invalidate the build cache (see [0]), which is
// unaffected by C source inputs.
// [0] https://github.com/go-gl/glfw/issues/269
const upstreamTreeSHA = "02493b10419e99f1293bfbb4fd805aadd527607e"

0 comments on commit b8ba9a2

Please sign in to comment.