Problem
The versioned SQL file generation rule in control.mk.sh uses a > (truncate) followed by >> (append) pattern:
echo " @echo '/* DO NOT EDIT - AUTO-GENERATED FILE */' > \$(EXTENSION_${ext}_VERSION_FILE)"
echo " @cat sql/${ext}.sql >> \$(EXTENSION_${ext}_VERSION_FILE)"
This produces a Make rule like:
$(EXTENSION_foo_VERSION_FILE): sql/foo.sql foo.control
@echo '/* DO NOT EDIT - AUTO-GENERATED FILE */' > $(EXTENSION_foo_VERSION_FILE)
@cat sql/foo.sql >> $(EXTENSION_foo_VERSION_FILE)
If Make executes this rule more than once (e.g., parallel builds triggering the same target from different dependency chains), the second invocation's cat >> appends to the already-complete file, doubling its content.
Observed Impact
test_factory--1.0.0.sql was found with 527 lines (doubled) instead of the correct 264 lines. The second half was an exact copy of sql/test_factory.sql, consistent with the append running twice.
Suggested Fix
Use a subshell so the entire output is captured with a single > redirect:
$(EXTENSION_foo_VERSION_FILE): sql/foo.sql foo.control
@(echo '/* DO NOT EDIT - AUTO-GENERATED FILE */'; cat sql/foo.sql) > $(EXTENSION_foo_VERSION_FILE)
This is safe regardless of how many times the rule fires — each invocation writes the complete correct content via a single redirect.
Problem
The versioned SQL file generation rule in
control.mk.shuses a>(truncate) followed by>>(append) pattern:This produces a Make rule like:
If Make executes this rule more than once (e.g., parallel builds triggering the same target from different dependency chains), the second invocation's
cat >>appends to the already-complete file, doubling its content.Observed Impact
test_factory--1.0.0.sqlwas found with 527 lines (doubled) instead of the correct 264 lines. The second half was an exact copy ofsql/test_factory.sql, consistent with the append running twice.Suggested Fix
Use a subshell so the entire output is captured with a single
>redirect:This is safe regardless of how many times the rule fires — each invocation writes the complete correct content via a single redirect.