Skip to content

Instantly share code, notes, and snippets.

@bgrins
Created November 15, 2019 22:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgrins/27f0dc8de967722921e7adbbdaf41e26 to your computer and use it in GitHub Desktop.
Save bgrins/27f0dc8de967722921e7adbbdaf41e26 to your computer and use it in GitHub Desktop.
#!/bin/bash
# this switches turn some bugs into errors
#set -o errexit -o pipefail -o noclobber -o nounset
MOZILLA_CENTRAL=$PWD
if [ ! -f $MOZILLA_CENTRAL/test.mozbuild ]; then
echo "Error: this doesn't look like an m-c directory."
exit 1
fi
# Generate a list of directories to ignore using the built in list
# plus files ignored by VCS, plus other whitelisted ones here.
THIRD_PARTY_LIST="$(sed 's/^/\//' $MOZILLA_CENTRAL/tools/rewriting/ThirdPartyPaths.txt)"
GIT_IGNORE_LIST="$(sed '/^#/d;/^$/d' $MOZILLA_CENTRAL/.gitignore)"
IGNORE_LIST="${THIRD_PARTY_LIST}
${GIT_IGNORE_LIST}
/testing/web-platform/"
IGNORE_ARGS=""
while read -r line; do
IGNORE_ARGS="$IGNORE_ARGS --iglob '!$line'"
done <<< "$IGNORE_LIST"
TAG_OLD="stringbundle"
TAG_NEW="moz-$TAG_OLD"
OPEN_TAG_OLD="<$TAG_OLD "
XUL_OPEN_TAG_OLD="<xul:$TAG_OLD "
OPEN_TAG_NEW="<$TAG_NEW "
XUL_OPEN_TAG_NEW="<xul:$TAG_NEW "
CLOSE_TAG_OLD="</$TAG_OLD>"
XUL_CLOSE_TAG_OLD="</xul:$TAG_OLD>"
CLOSE_TAG_NEW="</$TAG_NEW>"
XUL_CLOSE_TAG_NEW="</xul:$TAG_NEW>"
echo "Replacing $OPEN_TAG_OLD $OPEN_TAG_NEW"
MATCHING_FILES=$(eval "rg -l -g '*.{xhtml,xul}' '$OPEN_TAG_OLD|$XUL_OPEN_TAG_OLD' $IGNORE_ARGS $MOZILLA_CENTRAL | sort")
echo "$MATCHING_FILES" | wc -l
while read FILE ; do
perl -pi \
-e "s|$OPEN_TAG_OLD|$OPEN_TAG_NEW|g;" \
-e "s|$XUL_OPEN_TAG_OLD|$XUL_OPEN_TAG_NEW|g;" \
-e "s|$CLOSE_TAG_OLD|$CLOSE_TAG_NEW|g;" \
-e "s|$XUL_CLOSE_TAG_OLD|$XUL_CLOSE_TAG_NEW|g;" \
$FILE
done <<< "$MATCHING_FILES"
echo "Printing out some js lines that i'm going to replace. You may need to revert some of them:"
eval "rg -g '*.{js,jsm}' '\"$TAG_OLD\"' $IGNORE_ARGS $MOZILLA_CENTRAL"
MATCHING_FILES=$(eval "rg -l -g '*.{js,jsm}' '\"$TAG_OLD\"' $IGNORE_ARGS $MOZILLA_CENTRAL | sort")
while read FILE ; do
perl -pi \
-e "s|\"$TAG_OLD\"|\"$TAG_NEW\"|g;" \
$FILE
done <<< "$MATCHING_FILES"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment