Skip to content

Commit

Permalink
Backport a39cf2e3b242298fbf5fafdb8aa9b5d4562061ef
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Marchenko committed Apr 9, 2024
1 parent 62e6dfa commit 7d6a7ee
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
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 @@ -171,6 +171,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

0 comments on commit 7d6a7ee

Please sign in to comment.