Skip to content
184 changes: 153 additions & 31 deletions source-repo-scripts/bump_dependency.bash
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,61 @@ for ((i = 0; i < "${#SORTED_LIBRARIES[@]}"; i++)); do
for ((j = 0; j < "${#SORTED_LIBRARIES[@]}"; j++)); do

DEP_LIB=${SORTED_LIBRARIES[$j]#"gz-"}
DEP_LIBDOT="${DEP_LIB//l-/l.}"
DEP_VER=${SORTED_VERSIONS[$j]}
DEP_PREV_VER="$((${DEP_VER}-1))"

find . -type f -print0 | xargs -0 sed -i "s ${DEP_LIB}${DEP_PREV_VER} ${DEP_LIB}${DEP_VER} g"
# Remove version number from cmake find_package calls
# Replace lines like "find_package(gz-cmake2"
# with "find_package(gz-cmake"
# Replace lines like "find_package(gz-cmake2)"
# with "find_package(gz-cmake)"
# Replace lines like "find_package(gz-cmake2 2.0.0)"
# with "find_package(gz-cmake)"
find . -type f ! -path './.git/*' -print0 | xargs -0 sed -i \
-e "s@\(find_package.*${DEP_LIBDOT}\)${DEP_PREV_VER}\$@\1@g" \
-e "s@\(find_package.*${DEP_LIBDOT}\)${DEP_VER}\$@\1@g" \
-e "s@\(find_package.*${DEP_LIBDOT}\)${DEP_PREV_VER}\([^0-9]\)@\1\2@g" \
-e "s@\(find_package.*${DEP_LIBDOT}\)${DEP_VER}\([^0-9]\)@\1\2@g" \
-e "s@\(find_package.*${DEP_LIBDOT}\)${DEP_PREV_VER} \+${DEP_PREV_VER}[^ )]*@\1@g" \
-e "s@\(find_package.*${DEP_LIBDOT}\)${DEP_VER} \+${DEP_VER}[^ )]*@\1@g"

# Replace lines like "gz_find_package(gz-math6 VERSION 6.5.0)"
# with "gz_find_package(gz-math7)"
# Preserves other args and handles edge cases:
# like "gz_find_package(gz-math6 VERSION 6.5.0 REQUIRED)"
# with "gz_find_package(gz-math6 REQUIRED)"
# like "gz_find_package(gz-math6 REQUIRED COMPONENTS VERSION 6.10 eigen3)"
# with "gz_find_package(gz-math7 REQUIRED COMPONENTS eigen3)"
find . -type f ! -path './.git/*' -print0 | xargs -0 sed -i \
-e "s@\(find_package.*${DEP_LIBDOT}\)${DEP_PREV_VER}\(.*\) \+VERSION \+${DEP_PREV_VER}[^ )]*@\1\2@g"

# Remove version number from cmake target names
# Replace lines like "target_link_libraries(test_cmake gz-math8::gz-math8)"
# with "target_link_libraries(test_cmake gz-math::gz-math)"
# Replace lines like "gz-transport14::core"
# with "gz-transport::core"
# Replace lines like "gz-transport14::gz-transport14"
# with "gz-transport::gz-transport"
find . -type f ! -path './.git/*' -print0 | xargs -0 sed -i \
-e "s@\(target_link_libraries.*${DEP_LIBDOT}\)${DEP_PREV_VER}@\1@g" \
-e "s@\(target_link_libraries.*${DEP_LIBDOT}\)${DEP_PREV_VER}@\1@g" \
-e "s@\(target_link_libraries.*${DEP_LIBDOT}\)${DEP_VER}@\1@g" \
-e "s@\(target_link_libraries.*${DEP_LIBDOT}\)${DEP_VER}@\1@g" \
-e "s@\(${DEP_LIBDOT}\)${DEP_PREV_VER}\(::.*${DEP_LIBDOT}\)${DEP_PREV_VER}@\1\2@g" \
-e "s@\(${DEP_LIBDOT}\)${DEP_VER}\(::.*${DEP_LIBDOT}\)${DEP_VER}@\1\2@g" \
-e "s@\(${DEP_LIBDOT}\)${DEP_PREV_VER}::@\1::@g" \
-e "s@\(${DEP_LIBDOT}\)${DEP_VER}::@\1::@g"

# Replace lines like 'pkg-config --cflags --libs gz-math8'
# with 'pkg-config --cflags --libs gz-gui'
# Replace lines like 'pkg-config --cflags --libs gz-math9'
# with 'pkg-config --cflags --libs gz-gui'
find . -type f ! -path './.git/*' -print0 | xargs -0 sed -i \
-e "s@\(pkg-config.*${DEP_LIBDOT}\)${PREV_VER}\([^0-9]\)@\1\2@g" \
-e "s@\(pkg-config.*${DEP_LIBDOT}\)${VER}\([^0-9]\)@\1\2@g"

find . -type f ! -path './.git/*' -print0 | xargs -0 sed -i "s \(${DEP_LIBDOT}\)${DEP_PREV_VER} \1${DEP_VER} g"
done

commitAndPR ${RELEASE_ORG} main ""
Expand Down Expand Up @@ -414,23 +465,44 @@ for ((i = 0; i < "${#SORTED_LIBRARIES[@]}"; i++)); do
echo -e "${GREEN}${LIB}: Updating ${FORMULA}${DEFAULT}"
URL="https://github.com/${ORG}/${LIB}.git"

# regex for fuel-tools
LIBDOT="${LIB//l-/l.}"
# First remove numbers from package name in specific parts of test block
# Replace lines like "find_package(gz-cmake2)"
# with "find_package(gz-cmake)"
sed -i "s@\(find_package.*${LIB}\)${PREV_VER}\([^0-9]\)@\1\2@g" $FORMULA
sed -i "s@\(find_package.*${LIBDOT}\)${PREV_VER}\([^0-9]\)@\1\2@g" $FORMULA

# Replace lines like "target_link_libraries(test_cmake gz-math8::gz-math8)"
# with "target_link_libraries(test_cmake gz-math::gz-math)"
sed -i "s@\(target_link_libraries.*${LIB}\)${PREV_VER}@\1@g" $FORMULA
sed -i "s@\(target_link_libraries.*${LIB}\)${PREV_VER}@\1@g" $FORMULA
sed -i "s@\(target_link_libraries.*${LIBDOT}\)${PREV_VER}@\1@g" $FORMULA
sed -i "s@\(target_link_libraries.*${LIBDOT}\)${PREV_VER}@\1@g" $FORMULA

# Remove version number from cmake target names
# Replace lines like "gz-transport14::gz-transport14"
# with "gz-transport::gz-transport"
sed -i "s@\(${LIBDOT}\)${PREV_VER}\(::${LIBDOT}\)${PREV_VER}@\1\2@g" $FORMULA
sed -i "s@\(${LIBDOT}\)${VER}\(::${LIBDOT}\)${VER}@\1\2@g" $FORMULA
# Replace lines like "gz-transport14::core"
# with "gz-transport::core"
sed -i "s@\(${LIBDOT}\)${PREV_VER}::@\1::@g" $FORMULA
sed -i "s@\(${LIBDOT}\)${VER}::@\1::@g" $FORMULA


# Replace lines like 'system python.opt_libexec/"bin/python", "-c", "import gz.sim10"'
# with 'system python.opt_libexec/"bin/python", "-c", "import gz.sim"'
sed -i "s@\(python.*import .*${LIB}\)${PREV_VER}@\1@g" $FORMULA
sed -i "s@\(python.*import .*${LIBDOT#"gz-"}\)${PREV_VER}@\1@g" $FORMULA

# Replace lines like '(lib/"#{python_name}/site-packages/gz/msgs11").install_symlink Dir[lib/"python/gz/msgs11/*"]'
# with '(lib/"#{python_name}/site-packages/gz/msgs").install_symlink Dir[lib/"python/gz/msgs/*"]'
sed -i "s@\(site-packages/.*${LIBDOT#"gz-"}\)${PREV_VER}\(.*install_symlink.*${LIBDOT#"gz-"}\)${PREV_VER}@\1\2@g" $FORMULA

# Replace lines like 'system "pkg-config", "gz-gui10", "--cflags"'
# with 'system "pkg-config", "gz-gui", "--cflags"'
sed -i "s@\(pkg-config.*${LIB}\)${PREV_VER}@\1@g" $FORMULA
sed -i "s@\(pkg-config.*${LIBDOT}\)${PREV_VER}@\1@g" $FORMULA

# Replace lines like '"-lgz-plugin3-loader",
# with '"-lgz-plugin-loader",
sed -i "s@\(-l.*${LIBDOT}\)${PREV_VER}@\1@g" $FORMULA

# libN
sed -i -E "s ((${LIB#"gz-"}))${PREV_VER} \1${VER} g" $FORMULA
Expand Down Expand Up @@ -481,6 +553,16 @@ for ((i = 0; i < "${#SORTED_LIBRARIES[@]}"; i++)); do
sed -i "s@\(target_link_libraries.*${DEP_LIB}\)${DEP_PREV_VER}@\1@g" $FORMULA
sed -i "s@\(target_link_libraries.*${DEP_LIB}\)${DEP_PREV_VER}@\1@g" $FORMULA

# Remove version number from cmake target names
# Replace lines like "gz-transport14::gz-transport14"
# with "gz-transport::gz-transport"
sed -i "s@\(${DEP_LIB}\)${DEP_PREV_VER}\(::${DEP_LIB}\)${DEP_PREV_VER}@\1\2@g" $FORMULA
sed -i "s@\(${DEP_LIB}\)${DEP_VER}\(::${DEP_LIB}\)${DEP_VER}@\1\2@g" $FORMULA
# Replace lines like "gz-transport14::core"
# with "gz-transport::core"
sed -i "s@\(${DEP_LIB}\)${DEP_PREV_VER}::@\1::@g" $FORMULA
sed -i "s@\(${DEP_LIB}\)${DEP_VER}::@\1::@g" $FORMULA

# Replace lines like 'system python.opt_libexec/"bin/python", "-c", "import gz.sim10"'
# with 'system python.opt_libexec/"bin/python", "-c", "import gz.sim"'
sed -i "s@\(python.*import .*${DEP_LIB}\)${DEP_PREV_VER}@\1@g" $FORMULA
Expand Down Expand Up @@ -531,11 +613,11 @@ for ((i = 0; i < "${#SORTED_LIBRARIES[@]}"; i++)); do
startFromCleanBranch ${BUMP_BRANCH} main

# Check if main branch of that library is the correct version
PROJECT_NAME="${LIB}${VER}"
PROJECT_NAME="${LIB//-/.}${VER}"
PROJECT="project.*(${PROJECT_NAME}"
echo -e "${GREEN} checking versioned project name ${PROJECT_NAME}${DEFAULT}"
if ! grep -q ${PROJECT} "CMakeLists.txt"; then
PROJECT_NAME="${LIB}"
PROJECT_NAME="${LIB//-/.}"
PROJECT="project.*(${PROJECT_NAME}[^0-9]"
echo -e "${GREEN} checking unversioned project name ${PROJECT_NAME}${DEFAULT}"
if ! grep -q ${PROJECT} "CMakeLists.txt"; then
Expand All @@ -548,21 +630,26 @@ for ((i = 0; i < "${#SORTED_LIBRARIES[@]}"; i++)); do
for ((j = 0; j < "${#SORTED_LIBRARIES[@]}"; j++)); do

DEP_LIB=${SORTED_LIBRARIES[$j]#"gz-"}
# Run with . instead of -, to support multiple variations of fuel-tools
DEP_LIB=${DEP_LIB//-/.}

DEP_VER=${SORTED_VERSIONS[$j]}
DEP_PREV_VER="$((${DEP_VER}-1))"

# Remove version number from cmake find_package calls
# Replace lines like "find_package(gz-cmake2"
# with "find_package(gz-cmake"
# Replace lines like "find_package(gz-cmake2)"
# with "find_package(gz-cmake)"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s@\(find_package.*${DEP_LIB}\)${DEP_PREV_VER}\([^0-9]\)@\1\2@g"

# Replace lines like "find_package(gz-cmake2 2.0.0)"
# with "find_package(gz-cmake)"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s@\(find_package.*${DEP_LIB}\)${DEP_PREV_VER} \+${DEP_PREV_VER}[^ )]*@\1@g"

# Replace lines like "find_package(gz-cmake2 2.0.0)"
# with "find_package(gz-cmake)"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s@\(find_package.*${DEP_LIB}\)${DEP_PREV_VER} \+${DEP_PREV_VER}[^ )]*@\1@g"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' ! -path './.git/*' -print0 | xargs -0 sed -i \
-e "s@\(find_package.*${DEP_LIB}\)${DEP_PREV_VER}\$@\1@g" \
-e "s@\(find_package.*${DEP_LIB}\)${DEP_VER}\$@\1@g" \
-e "s@\(find_package.*${DEP_LIB}\)${DEP_PREV_VER}\([^0-9]\)@\1\2@g" \
-e "s@\(find_package.*${DEP_LIB}\)${DEP_VER}\([^0-9]\)@\1\2@g" \
-e "s@\(find_package.*${DEP_LIB}\)${DEP_PREV_VER} \+${DEP_PREV_VER}[^ )]*@\1@g" \
-e "s@\(find_package.*${DEP_LIB}\)${DEP_VER} \+${DEP_VER}[^ )]*@\1@g"

# Replace lines like "gz_find_package(gz-math6 VERSION 6.5.0)"
# with "gz_find_package(gz-math7)"
Expand All @@ -571,40 +658,75 @@ for ((i = 0; i < "${#SORTED_LIBRARIES[@]}"; i++)); do
# with "gz_find_package(gz-math6 REQUIRED)"
# like "gz_find_package(gz-math6 REQUIRED COMPONENTS VERSION 6.10 eigen3)"
# with "gz_find_package(gz-math7 REQUIRED COMPONENTS eigen3)"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s@\(find_package.*${DEP_LIB}\)${DEP_PREV_VER}\(.*\) \+VERSION \+${DEP_PREV_VER}[^ )]*@\1\2@g"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' ! -path './.git/*' -print0 | xargs -0 sed -i \
-e "s@\(find_package.*${DEP_LIB}\)${DEP_PREV_VER}\(.*\) \+VERSION \+${DEP_PREV_VER}[^ )]*@\1\2@g"

# Remove version number from cmake target names
# Replace lines like "target_link_libraries(test_cmake gz-math8::gz-math8)"
# with "target_link_libraries(test_cmake gz-math::gz-math)"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s@\(target_link_libraries.*${DEP_LIB}\)${DEP_PREV_VER}@\1@g"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s@\(target_link_libraries.*${DEP_LIB}\)${DEP_PREV_VER}@\1@g"

# Remove version number from cmake target names
# Replace lines like "gz-transport14::core"
# with "gz-transport::core"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s@\(${DEP_LIB}\)${DEP_PREV_VER}::@\1::@g"
# Replace lines like "gz-transport14::gz-transport14"
# with "gz-transport::gz-transport"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s@\(${DEP_LIB}\)${DEP_PREV_VER}\(::${DEP_LIB}\)${DEP_PREV_VER}@\1\2@g"

find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' ! -path './.git/*' -print0 | xargs -0 sed -i \
-e "s@\(target_link_libraries.*${DEP_LIB}\)${DEP_PREV_VER}@\1@g" \
-e "s@\(target_link_libraries.*${DEP_LIB}\)${DEP_PREV_VER}@\1@g" \
-e "s@\(target_link_libraries.*${DEP_LIB}\)${DEP_VER}@\1@g" \
-e "s@\(target_link_libraries.*${DEP_LIB}\)${DEP_VER}@\1@g" \
-e "s@\(${DEP_LIB}\)${DEP_PREV_VER}\(::.*${DEP_LIB}\)${DEP_PREV_VER}@\1\2@g" \
-e "s@\(${DEP_LIB}\)${DEP_VER}\(::.*${DEP_LIB}\)${DEP_VER}@\1\2@g" \
-e "s@\(${DEP_LIB}\)${DEP_PREV_VER}::@\1::@g" \
-e "s@\(${DEP_LIB}\)${DEP_VER}::@\1::@g"

# Remove version number from python imports
# Replace lines like 'from gz.sim10 import *'
# with 'from gz.sim import *'
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s@\(from.*${DEP_LIB}\)${DEP_PREV_VER}\( import\)@\1\2@g"
# Replace lines like 'import gz.sim10"
# with 'import gz.sim"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s@\(import.*${DEP_LIB}\)${DEP_PREV_VER}@\1@g"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' ! -path './.git/*' -print0 | xargs -0 sed -i \
-e "s@\(from.*${DEP_LIB}\)${DEP_PREV_VER}\(.* import\)@\1\2@g" \
-e "s@\(from.*${DEP_LIB}\)${DEP_PREV_VER}\(.* import\)@\1\2@g" \
-e "s@\(from.*${DEP_LIB}\)${DEP_VER}\(.* import\)@\1\2@g" \
-e "s@\(import.*${DEP_LIB}\)${DEP_PREV_VER}@\1@g" \
-e "s@\(import.*${DEP_LIB}\)${DEP_VER}@\1@g"

# Replace lines like "project(gz-transport15 VERSION 15.0)
# with "project(gz-transport VERSION 15.0)
find . -type f -name 'CMakeLists.txt' -print0 | xargs -0 sed -i \
-e "s@\(project.*${DEP_LIB}\)${DEP_PREV_VER}\( VERSION\)@\1\2@g" \
-e "s@\(project.*${DEP_LIB}\)${DEP_VER}\( VERSION\)@\1\2@g"

# Delete lines like "set(GZ_MATH_VER ${gz-math8_VERSION_MAJOR})"
# Remove references to variables like "${GZ_MATH_VER}"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' ! -path './.git/*' -print0 | xargs -0 sed -i \
-e "/set([A-Z_]*_VER \${[a-z_-]*${DEP_LIB}${DEP_PREV_VER}_VERSION_MAJOR}/d" \
-e "/set([A-Z_]*_VER \${[a-z_-]*${DEP_LIB}${DEP_VER}_VERSION_MAJOR}/d" \
-e "s@\${GZ_${DEP_LIB^^}_VER}@@g"
if [ "${DEP_LIB}" = "sdformat" ]; then
# Delete lines like "set(SDF_VER ${sdformat15_VERSION_MAJOR})"
# Remove references to variables like "${SDF_VER}"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' ! -path './.git/*' -print0 | xargs -0 sed -i \
-e "/set(SDF_VER \${sdformat[0-9]*_VERSION_MAJOR}/d" \
-e "s@\${SDF_VER}@@g"
fi

# Replace lines like "<depend>gz-transport14</depend>"
# with "<depend>gz-transport</depend>"
find . -type f -name 'package.xml' -print0 | xargs -0 sed -i "s@\(<depend>.*${DEP_LIB}\)${DEP_PREV_VER}<@\1<@g"
# Replace lines like "<build_depend>gz-cmake4</depend>"
# with "<build_depend>gz-cmake</depend>"
# Replace lines like "<name>gz-transport14</name>"
# with "<name>gz-transport</name>"
find . -type f -name 'package.xml' -print0 | xargs -0 sed -i \
-e "s@\(<[a-z_]*depend>.*${DEP_LIB}\)${DEP_PREV_VER}<@\1<@g" \
-e "s@\(<[a-z_]*depend>.*${DEP_LIB}\)${DEP_VER}<@\1<@g" \
-e "s@\(<name>.*${DEP_LIB}\)${DEP_PREV_VER}<@\1<@g" \
-e "s@\(<name>.*${DEP_LIB}\)${DEP_VER}<@\1<@g"

# Rule: *plugin2 -> *plugin3
# Replace lines like: "find_package(gz-cmake2)"
# with: "find_package(gz-cmake3)"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s ${DEP_LIB}${DEP_PREV_VER} ${DEP_LIB}${DEP_VER} g"

# Second run with _ instead of -, to support multiple variations of fuel-tools
DEP_LIB=${DEP_LIB//-/_}
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' -print0 | xargs -0 sed -i "s ${DEP_LIB}${DEP_PREV_VER} ${DEP_LIB}${DEP_VER} g"
find . -type f ! -name 'Changelog.md' ! -name 'Migration.md' ! -path './.git/*' -print0 | xargs -0 sed -i \
-e "s \(${DEP_LIB}\)${DEP_PREV_VER} \1${DEP_VER} g"
done

commitAndPR ${ORG} main
Expand Down