Playing with the AST rewriter.
[qt-creator-color-themes.git] / replaceVersion.sh
blob0bb38a68a94a600a12a5ccfb5d14aa6f1b8c04a0
1 #! /usr/bin/env bash
3 ## Command line parameters
4 if [[ $# != 2 ]]; then
5 cat <<USAGE
6 usage:
7 $0 <old> <new>
8 example:
9 $0 '1.2.3' '1.2.4'
10 USAGE
11 exit 1
15 ## Process and show version
16 OLD=`sed 's/\./\\\\./g' <<<"$1"`
17 NEW=`sed 's/\./\\\\./g' <<<"$2"`
19 OLD_MAJOR=`sed 's/^\([0-9]\+\)\.[0-9]\+\.[0-9]\+$/\1/' <<<"$1"`
20 NEW_MAJOR=`sed 's/^\([0-9]\+\)\.[0-9]\+\.[0-9]\+$/\1/' <<<"$2"`
22 OLD_MINOR=`sed 's/^[0-9]\+\.\([0-9]\+\)\.[0-9]\+$/\1/' <<<"$1"`
23 NEW_MINOR=`sed 's/^[0-9]\+\.\([0-9]\+\)\.[0-9]\+$/\1/' <<<"$2"`
25 OLD_RELEASE=`sed 's/^[0-9]\+\.[0-9]\+\.\([0-9]\+\)$/\1/' <<<"$1"`
26 NEW_RELEASE=`sed 's/^[0-9]\+\.[0-9]\+\.\([0-9]\+\)$/\1/' <<<"$2"`
28 OLD_DOT_FOUR="${OLD_MAJOR}\\.${OLD_MINOR}\\.${OLD_RELEASE}\\.0"
29 NEW_DOT_FOUR="${NEW_MAJOR}\\.${NEW_MINOR}\\.${NEW_RELEASE}\\.0"
31 OLD_COMMA_FOUR="${OLD_MAJOR},${OLD_MINOR},${OLD_RELEASE},0"
32 NEW_COMMA_FOUR="${NEW_MAJOR},${NEW_MINOR},${NEW_RELEASE},0"
34 echo "#==============================================="
35 echo "# Plain '${OLD}' -> '${NEW}'"
36 echo "#-----------------------------------------------"
37 echo "# Major '${OLD_MAJOR}' -> '${NEW_MAJOR}'"
38 echo "# Minor '${OLD_MINOR}' -> '${NEW_MINOR}'"
39 echo "# Release '${OLD_RELEASE}' -> '${NEW_RELEASE}'"
40 echo "#-----------------------------------------------"
41 echo "# Dots '${OLD_DOT_FOUR}' -> '${NEW_DOT_FOUR}'"
42 echo "# Comma '${OLD_COMMA_FOUR}' -> '${NEW_COMMA_FOUR}'"
43 echo "#==============================================="
44 echo
47 ## Make script safe to call from anywhere by going home first
48 SCRIPT_DIR=`dirname "${PWD}/$0"`
49 echo "Entering directory \`${SCRIPT_DIR}'"
50 pushd "${SCRIPT_DIR}" &>/dev/null || exit 1
53 ## Patch *.pluginspec
54 while read i ; do
55 echo "Patching \`$i'"
56 TMPFILE=`mktemp`
57 sed -e 's/version="'"${OLD}"'"/version="'"${NEW}"'"/' \
58 -e 's/compatVersion="'"${OLD}"'"/compatVersion="'"${NEW}"'"/' \
59 "${i}" > "${TMPFILE}"
60 mv -f "${TMPFILE}" "${i}"
61 done < <(find . -name '*.pluginspec')
64 ## Patch coreconstants.h
65 TMPFILE=`mktemp`
66 CORE_CONSTANT_H="${SCRIPT_DIR}/src/plugins/coreplugin/coreconstants.h"
67 echo "Patching \`${CORE_CONSTANT_H}'"
68 sed \
69 -e 's/^\(#define IDE_VERSION_MAJOR \)'"${OLD_MAJOR}"'/\1'"${NEW_MAJOR}"'/' \
70 -e 's/^\(#define IDE_VERSION_MINOR \)'"${OLD_MINOR}"'/\1'"${NEW_MINOR}"'/' \
71 -e 's/^\(#define IDE_VERSION_RELEASE \)'"${OLD_RELEASE}"'/\1'"${NEW_RELEASE}"'/' \
72 "${CORE_CONSTANT_H}" > "${TMPFILE}"
73 mv -f "${TMPFILE}" "${CORE_CONSTANT_H}"
76 ## Patch installer.rc
77 TMPFILE=`mktemp`
78 INSTALLER_RC="${SCRIPT_DIR}/../ide/nightly_builds/installer/installer.rc"
79 echo "Patching \`${INSTALLER_RC}'"
80 sed \
81 -e "s/"${OLD_DOT_FOUR}"/"${NEW_DOT_FOUR}"/" \
82 -e "s/"${OLD_COMMA_FOUR}"/"${NEW_COMMA_FOUR}"/" \
83 "${INSTALLER_RC}" > "${TMPFILE}"
84 p4 edit `sed -e 's/\/\.\//\//g' -e 's/\/[^\/]\+\/\.\.\//\//g' <<<"${INSTALLER_RC}"`
85 mv -f "${TMPFILE}" "${INSTALLER_RC}"
88 ## Patch installer.rc
89 TMPFILE=`mktemp`
90 INFO_PLIST="${SCRIPT_DIR}/src/app/Info.plist"
91 echo "Patching \`${INFO_PLIST}'"
92 sed \
93 -e "s/"${OLD}"/"${NEW}"/" \
94 "${INFO_PLIST}" > "${TMPFILE}"
95 mv -f "${TMPFILE}" "${INFO_PLIST}"
98 ## Go back to original $PWD
99 echo "Leaving directory \`${SCRIPT_DIR}'"
100 popd &>/dev/null || exit 1
101 exit 0