File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -265,7 +265,7 @@ bin/$(TFGEN): provider/*.go provider/go.* .make/upstream
265265# Apply patches to the upstream submodule, if it exists
266266upstream : .make/upstream
267267# Re-run if the upstream commit or the patches change
268- .make/upstream : $(wildcard patches/* ) $(wildcard .git/modules/ upstream/HEAD )
268+ .make/upstream : $(wildcard patches/* ) $(shell ./ upstream.sh file_target )
269269ifneq ("$(wildcard upstream) ","")
270270 ./upstream.sh init
271271endif
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ COMMANDS
2323 check_in Write checkedout commits back to patches, add upstream
2424 and patches changes to the git staging area and exit
2525 checkout mode.
26+ file_target Print a file path to depend on in make.
2627 help Print this help message, plus examples.
2728
2829OPTIONS
@@ -334,6 +335,23 @@ re-initializing using updated patches and updated upstream base.
334335EOF
335336}
336337
338+ # file_target prints a file path to depend on in make to trigger an init when required.
339+ # Also updates the file timestamp if the submodule needs updating.
340+ file_target () {
341+ path=.git/modules/upstream/HEAD
342+ # Don't print a file if it doesn't exist - it's probably not initialized yet.
343+ if [[ ! -f " ${path} " ]]; then
344+ exit 0
345+ fi
346+ # If the submodule is changed, touch the file to trigger a re-init.
347+ desired_commit=$( git ls-tree HEAD upstream | cut -d ' ' -f3 | cut -f1 || true)
348+ current_commit=$( cat " ${path} " )
349+ if [[ " ${desired_commit} " != " ${current_commit} " ]]; then
350+ touch " ${path} "
351+ fi
352+ echo " ${path} "
353+ }
354+
337355if [[ -z ${original_cmd} ]]; then
338356 echo " Error: command is required."
339357 echo
@@ -372,6 +390,9 @@ case ${original_cmd} in
372390 check_in|checkin)
373391 check_in " $@ "
374392 ;;
393+ file_target)
394+ file_target " $@ "
395+ ;;
375396 * )
376397 echo " Error: unknown command \" ${original_cmd} \" ."
377398 echo
You can’t perform that action at this time.
0 commit comments