Skip to content

Commit a66792d

Browse files
fix: use gnu-sed on mac instead of the built-in sed command
Signed-off-by: Mohammad Abdollahpour <mohammad.abdollahpour@oracle.com>
1 parent 3d5e35b commit a66792d

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ setup: force-upgrade setup-go setup-binaries setup-schemastore
9494
setup-go:
9595
go build -o $(PACKAGE_PATH)/bin/ $(REPO_PATH)/golang/cmd/...
9696
go build -o $(PACKAGE_PATH)/bin/cuevalidate.so -buildmode=c-shared $(REPO_PATH)/golang/internal/cue_validator/cue_validator.go
97-
setup-binaries: $(PACKAGE_PATH)/bin/slsa-verifier $(PACKAGE_PATH)/resources/mvnw $(PACKAGE_PATH)/resources/gradlew souffle
97+
setup-binaries: $(PACKAGE_PATH)/bin/slsa-verifier $(PACKAGE_PATH)/resources/mvnw $(PACKAGE_PATH)/resources/gradlew souffle gnu-sed
9898
$(PACKAGE_PATH)/bin/slsa-verifier:
9999
git clone --depth 1 https://github.com/slsa-framework/slsa-verifier.git -b v2.5.1
100100
cd slsa-verifier/cli/slsa-verifier && go build -o $(PACKAGE_PATH)/bin/
@@ -170,6 +170,12 @@ souffle:
170170
fi && \
171171
command -v souffle || true
172172

173+
# Install gnu-sed on mac using homebrew
174+
.PHONY: gnu-sed
175+
gnu-sed:
176+
if [ "$(OS_DISTRO)" == "Darwin" ]; then \
177+
brew install gnu-sed; \
178+
fi
173179

174180
# Install or upgrade an existing virtual environment based on the
175181
# package dependencies declared in pyproject.toml.

scripts/dev_scripts/copyright-checker.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ for f in $files; do
5252
fi
5353
done
5454

55+
SED="sed"
56+
# Use gnu-sed (gsed) on mac.
57+
if [[ "$(uname)" == "Darwin" ]]; then
58+
SED="gsed"
59+
fi
60+
5561
if [ ${#missing_copyright_files[@]} -ne 0 ]; then
5662
for f in "${missing_copyright_files[@]}"; do
5763

@@ -86,14 +92,14 @@ if [ ${#missing_copyright_files[@]} -ne 0 ]; then
8692
shebang_line=$(grep -m 1 -n "#!" "$f")
8793
if [[ -z "$shebang_line" ]];then
8894
# If there is no shebang, insert at the first line.
89-
sed -i "1s/^/$expected\n\n/" "$f"
95+
$SED -i "1s/^/$expected\n\n/" "$f"
9096
else
9197
# If there is a shebang, append to the end of the line.
92-
sed -i "$(echo "$shebang_line" | cut -d : -f 1)""s/$/\n\n$expected/" "$f"
98+
$SED -i "$(echo "$shebang_line" | cut -d : -f 1)""s/$/\n\n$expected/" "$f"
9399
fi
94100
else
95101
echo "Copyright header needs update for $f."
96-
sed -i "$line_number""s/^.*/$expected/" "$f"
102+
$SED -i "$line_number""s/^.*/$expected/" "$f"
97103
fi
98104
done
99105
echo "Copyright headers have been automatically added/updated. Please review and stage the changes before running git commit again."

0 commit comments

Comments
 (0)