Skip to content

Commit

Permalink
xds/third_party: fixed compatibility issue of regex in BSD for import…
Browse files Browse the repository at this point in the history
….sh sed command (grpc#5613)

* fixed issue import.sh sed expr with non-extended regex does not support \| in BSD

* fixed sed -i issue for cross platform
  • Loading branch information
voidzcy authored Apr 18, 2019
1 parent 7e219c3 commit affce63
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions xds/third_party/envoy/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,22 @@ do
# Import mangling.
-e 's#import "gogoproto/gogo.proto";##'
# Remove references to gogo.proto extensions.
-e 's#option (gogoproto\.[a-z_]\+) = \(true\|false\);##'
-e 's#\(, \)\?(gogoproto\.[a-z_]\+) = \(true\|false\),\?##'
-e 's#option \(gogoproto\.[a-z_]+\) = (true|false);##'
-e 's#(, )?\(gogoproto\.[a-z_]+\) = (true|false),?##'
# gogoproto removal can result in empty brackets.
-e 's# \[\]##'
# gogoproto removal can result in four spaces on a line by itself.
-e '/^ $/d'
)
sed -i "${commands[@]}" "$f"
# Use a temp file to workaround `sed -i` cross-platform compatibility issue.
tmpfile="$(mktemp)"
sed -E "${commands[@]}" "$f" > "$tmpfile"

# gogoproto removal can leave a comma on the last element in a list.
# This needs to run separately after all the commands above have finished
# since it is multi-line and rewrites the output of the above patterns.
sed -i -e '$!N; s#\(.*\),\([[:space:]]*\];\)#\1\2#; t; P; D;' "$f"
sed -E -e '$!N; s#(.*),([[:space:]]*\];)#\1\2#; t' -e 'P; D;' "$tmpfile" > "$f"
rm "$tmpfile"
done
popd

Expand Down

0 comments on commit affce63

Please sign in to comment.