Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8301753: AppendFile/WriteFile has differences between make 3.81 and 4+ #2969

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions make/common/MakeIO.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ ifeq ($(HAS_FILE_FUNCTION), true)
else
# Use printf to get consistent behavior on all platforms.
WriteFile = \
$(shell $(PRINTF) "%s" $(call ShellQuote, $1) > $2)
$(shell $(PRINTF) "%s\n" $(strip $(call ShellQuote, $1)) > $2)
endif

# Param 1 - Text to write
Expand All @@ -268,5 +268,5 @@ ifeq ($(HAS_FILE_FUNCTION), true)
else
# Use printf to get consistent behavior on all platforms.
AppendFile = \
$(shell $(PRINTF) "%s" $(call ShellQuote, $1) >> $2)
$(shell $(PRINTF) "%s\n" $(strip $(call ShellQuote, $1)) >> $2)
endif
56 changes: 56 additions & 0 deletions test/make/TestMakeBase.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,62 @@ ifneq ($(READ_WRITE_VALUE), $(READ_WRITE_RESULT))
$(error Expected: >$(READ_WRITE_VALUE)< - Result: >$(READ_WRITE_RESULT)<)
endif

TEST_STRING_1 := 1234
TEST_STRING_2 := 1234$(NEWLINE)
TEST_STRING_3 := 1234$(NEWLINE)$(NEWLINE)

# Writing a string ending in newline should not add a newline, but if it does
# not, a newline should be added. We check this by verifying that the size of the
# file is 5 characters for both test strings.
TEST_FILE_1 := $(OUTPUT_DIR)/write-file-1
TEST_FILE_2 := $(OUTPUT_DIR)/write-file-2
TEST_FILE_3 := $(OUTPUT_DIR)/write-file-3

$(call WriteFile, $(TEST_STRING_1), $(TEST_FILE_1))
$(call WriteFile, $(TEST_STRING_2), $(TEST_FILE_2))
$(call WriteFile, $(TEST_STRING_3), $(TEST_FILE_3))

TEST_FILE_1_SIZE := $(strip $(shell $(WC) -c < $(TEST_FILE_1)))
TEST_FILE_2_SIZE := $(strip $(shell $(WC) -c < $(TEST_FILE_2)))
TEST_FILE_3_SIZE := $(strip $(shell $(WC) -c < $(TEST_FILE_3)))

ifneq ($(TEST_FILE_1_SIZE), 5)
$(error Expected file size 5 for WriteFile 1, got $(TEST_FILE_1_SIZE))
endif
ifneq ($(TEST_FILE_2_SIZE), 5)
$(error Expected file size 5 for WriteFile 2, got $(TEST_FILE_2_SIZE))
endif
ifneq ($(TEST_FILE_3_SIZE), 5)
$(error Expected file size 5 for WriteFile 3, got $(TEST_FILE_3_SIZE))
endif

# Also test append (assumes WriteFile works as expected)
$(call WriteFile, $(TEST_STRING_1), $(TEST_FILE_1))
$(call AppendFile, $(TEST_STRING_1), $(TEST_FILE_1))
$(call AppendFile, $(TEST_STRING_1), $(TEST_FILE_1))

$(call WriteFile, $(TEST_STRING_2), $(TEST_FILE_2))
$(call AppendFile, $(TEST_STRING_2), $(TEST_FILE_2))
$(call AppendFile, $(TEST_STRING_2), $(TEST_FILE_2))

$(call WriteFile, $(TEST_STRING_3), $(TEST_FILE_3))
$(call AppendFile, $(TEST_STRING_3), $(TEST_FILE_3))
$(call AppendFile, $(TEST_STRING_3), $(TEST_FILE_3))

TEST_FILE_1_SIZE := $(strip $(shell $(WC) -c < $(TEST_FILE_1)))
TEST_FILE_2_SIZE := $(strip $(shell $(WC) -c < $(TEST_FILE_2)))
TEST_FILE_3_SIZE := $(strip $(shell $(WC) -c < $(TEST_FILE_3)))

ifneq ($(TEST_FILE_1_SIZE), 15)
$(error Expected file size 15 for AppendFile 1, got $(TEST_FILE_1_SIZE))
endif
ifneq ($(TEST_FILE_2_SIZE), 15)
$(error Expected file size 15 for AppendFile 2, got $(TEST_FILE_2_SIZE))
endif
ifneq ($(TEST_FILE_3_SIZE), 15)
$(error Expected file size 15 for AppendFile 3, got $(TEST_FILE_3_SIZE))
endif

################################################################################
# Test creating dependencies on make variables

Expand Down