From 88177fe1e4a8b70249fc7fdd42312aeb8bf4b9f9 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Sun, 24 Apr 2022 23:12:42 -0700 Subject: [PATCH 01/21] Add header migration script Signed-off-by: methylDragon --- .../tools/header_migration_script.sh | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 jenkins-scripts/tools/header_migration_script.sh diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh new file mode 100644 index 000000000..cf9b413e4 --- /dev/null +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +migrate_ign_to_gz() { + # Migrate ignition to gz + if [[ $1 != *.in ]] ; then # But not macros for .in files + sed -i 's@\(#.*\) IGNITION_@\1 GZ_@g' $1 # e.g. IGNITION_UTILS__XXX -> GZ_UTILS__XXX + fi + + sed -i 's@(ignition@(gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) + sed -i 's@ignition/@gz/@g' $1 # e.g. include -> include + + # Do the moves + dirname $1 | sed 's@include/ignition@include/gz@g' | xargs -I {} mkdir -pv {} + echo $1 | sed 's@include/ignition@include/gz@g' | xargs -I {} git mv -f $1 {} && echo "Moved: $1 --> {}" + + # Leave redirection aliases + # Convert *.in into normal versions + echo $1 | sed 's@\(.*\)\.in@\1@g' | xargs -I {} touch {} +} +export -f migrate_ign_to_gz + + +redirection_alias() { + text="""\ +/* + * Copyright (C) 2022 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the \"License\"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an \"AS IS\" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <$(echo $1 | sed "s@.*ignition/\(.*\)@gz/\1@g")>\ +""" + + echo "$text" > $1 +} +export -f redirection_alias + +# MAIN ============================================================================================= +cd ign-utils +git reset --hard + +# Edit top level CMakeLists +sed -i 's@ign_configure_project(\(.*\))@ign_configure_project(\n REPLACE_IGNITION_INCLUDE_PATH gz/utils\n \1)@g' CMakeLists.txt + +# Migrate +find . -regex './include/ignition.*' -type f -print0 | xargs -0 -I {} bash -c 'migrate_ign_to_gz {}' _ + +# Provision redirection aliases +find . -regex './include/ignition.*' -type f -print0 | xargs -0 -I {} bash -c 'redirection_alias {}' _ +find . -regex "./include/ignition.*/CMakeLists.txt" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling ignition CMakeLists + +# Add header level CMakeLists.txt +touch ./include/CMakeLists.txt +echo "add_subdirectory(gz)" > ./include/CMakeLists.txt +echo "install(DIRECTORY ignition DESTINATION \${IGN_INCLUDE_INSTALL_DIR_FULL})" >> ./include/CMakeLists.txt + + +# TODOs +# Make Export.hh and utils.hh +# Parse libs +# Clone and autobranch/push From 5ce602d20db87f918dedf85e2a987c6e0d78e946 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Mon, 25 Apr 2022 15:38:17 -0700 Subject: [PATCH 02/21] Implement source, CMake, and header migration Signed-off-by: methylDragon --- .../tools/header_migration_script.sh | 180 ++++++++++++++---- 1 file changed, 145 insertions(+), 35 deletions(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index cf9b413e4..0473312dd 100644 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -1,27 +1,51 @@ #!/usr/bin/env bash +# Copyright (C) 2022 Open Source Robotics Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. -migrate_ign_to_gz() { - # Migrate ignition to gz - if [[ $1 != *.in ]] ; then # But not macros for .in files - sed -i 's@\(#.*\) IGNITION_@\1 GZ_@g' $1 # e.g. IGNITION_UTILS__XXX -> GZ_UTILS__XXX - fi - - sed -i 's@(ignition@(gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) - sed -i 's@ignition/@gz/@g' $1 # e.g. include -> include - - # Do the moves - dirname $1 | sed 's@include/ignition@include/gz@g' | xargs -I {} mkdir -pv {} - echo $1 | sed 's@include/ignition@include/gz@g' | xargs -I {} git mv -f $1 {} && echo "Moved: $1 --> {}" +# DESCRIPTION +# =========== +# This script will migrate headers and references to those headers in the source files for: +# - ign(ition) -> gz +# - Ign(ition) -> Gz +# +# It will, for all subdirectories under `src`, `test`, `examples`, and `include`: +# - Move the files +# - Edit source files to update references/new paths +# - Edit CMakeLists files to update references/new paths +# +# It will also leave redirection aliases for tick-tocking in the existing ign(ition) directories; +# As well as create a top level CMakeLists file to install those redirection aliases. +# +# WARNING +# ======= +# This script will NOT migrate variable and class names! It also won't migrate macro names with +# arguments. (It'll mainly try to target header guards for macro updates.) +# +# PRE-REQUISITES +# ============== +# Requires the 'gh' CLI to be installed. +# +# USAGE +# ===== +# Place the script in the root of the repo to be migrated, and run: +# $ ./header_migration_script.sh +# +# Author: methylDragon - # Leave redirection aliases - # Convert *.in into normal versions - echo $1 | sed 's@\(.*\)\.in@\1@g' | xargs -I {} touch {} -} -export -f migrate_ign_to_gz - -redirection_alias() { - text="""\ +# METHODS AND CONSTANTS ============================================================================ +export LICENSE="""\ /* * Copyright (C) 2022 Open Source Robotics Foundation * @@ -38,35 +62,121 @@ redirection_alias() { * limitations under the License. * */ - -#include <$(echo $1 | sed "s@.*ignition/\(.*\)@gz/\1@g")>\ """ - echo "$text" > $1 -} -export -f redirection_alias -# MAIN ============================================================================================= -cd ign-utils -git reset --hard +mv_headers() { + # Create necessary directories + dirname $1 | sed 's@include\(.*\)*/ignition@include\1/gz@g' | xargs -I {} mkdir -pv {} + + # Move anything in an include/.../ignition or include/ignition subdirectory + # Also handles: + # IgnitionXXX -> GzXXX + # IgnXXX -> GzXXX + if [[ $1 =~ include(.*)*/ignition ]] || [[ $1 =~ include(.*)*/Ign(ition)?[A-Z] ]] ; then + echo $1 | sed \ + -e 's@include\(.*\)*/ignition@include\1/gz@g' \ + -e 's@include\(.*\)*/Ign\(ition\)\?\([A-Z]\)@include\1/Gz\3@g' \ + | xargs -I {} bash -c "git mv -f $1 {} && echo '[MOVED] $1 --> {}'" _ + fi + + # Leave redirection aliases + # Converting *.in into normal versions (spoofing configuration of *.in files) + echo $1 | sed 's@\(.*\)\.in@\1@g' | xargs -I {} touch {} +} ; export -f mv_headers + + +migrate_sources() { # Different variations of ignition/ign -> gz in source files + # Note: DOES NOT MIGRATE CLASS OR VARIABLE NAMES + + if [[ $1 =~ \.c[^\.]*$|\.in[^\.]*$|\.h[^\.]*$ ]] ; then # Only do for source files + echo "[MIGRATING SOURCES] $1" + if [[ $1 != *.in ]] ; then # !! But not macros for .in files + # Only migrate non-macro definition calls + sed -i 's@\(#.*\) IGNITION_\([^(]*\)$@\1 GZ_\2@g' $1 # e.g. IGNITION_UTILS__XXX -> GZ_UTILS__XXX + sed -i 's@\(#.*\) IGN_\([^(]*\)\$@\1 GZ_\2@g' $1 # e.g. IGN_UTILS__XXX -> GZ_UTILS__XXX + fi + + # NOTE(CH3): We're not migrating class or variable names for now + # sed -i 's@Ignition\([A-Z]\)@Gz\1@g' $1 # e.g. IgnitionFormatter -> GzFormatter + + sed -i 's@ignition/@gz/@g' $1 # e.g. include -> include + sed -i 's@ignition_@gz_@g' $1 # e.g. ignition_xxx -> gz_xxx + sed -i 's@ign_@gz_@g' $1 # e.g. ign_xxx -> gz_xxx + # Handle Edge Cases + sed -i 's@${gz_headers}@${ign_headers}@g' $1 + fi +} ; export -f migrate_sources + + +migrate_cmake() { # Different variations of ignition/ign -> gz in CMake files + # This is special because we need to specifically avoid unmigrated ign-cmake macro calls + + if [[ $1 =~ CMakeLists.txt ]] ; then # Only do for CMakeLists files + echo "[MIGRATING CMAKE] $1" + + sed -i 's@(ignition@(gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) + + # NOTE(CH3): + # ^\(?!ign\(?ition\)_\) ignores lines that start with ign(nition)_ + # Which should avoid changing any ign-cmake macro calls + sed -i 's@^\(?!ign\(?ition\)_\)\(#.*\) IGNITION_@\1 GZ_@g' $1 # e.g. IGNITION_UTILS__XXX -> GZ_UTILS__XXX + sed -i 's@^\(?!ign\(?ition\)_\)\(#.*\) IGN_@\1 GZ_@g' $1 # e.g. IGN_UTILS__XXX -> GZ_UTILS__XXX + + sed -i 's@^\(?!ign\(?ition\)_\)Ignition\([A-Z]\)@Gz\1@g' $1 # e.g. IgnitionFormatter -> GzFormatter + + sed -i 's@^\(?!ign\(?ition\)_\)(ignition@(gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) + sed -i 's@^\(?!ign\(?ition\)_\)ignition/@gz/@g' $1 # e.g. include -> include + sed -i 's@^\(?!ign\(?ition\)_\)ignition_@gz_/@g' $1 # e.g. ignition_xxx -> gz_xxx + sed -i 's@^\(?!ign\(?ition\)_\)ign_@gz_/@g' $1 # e.g. ign_xxx -> gz_xxx + fi +} ; export -f migrate_cmake + + +populate_redirection_alias() { + echo "[REDIRECTING] $1" + echo "$LICENSE" > $1 + echo "#include <$(echo $1 | sed \ + -e 's@.*/include/@@g' \ + -e 's@ignition/@gz/@g' \ + -e 's@*Ign(ition)@Gz@g')>" >> $1 +} ; export -f populate_redirection_alias + +# MAIN ============================================================================================= # Edit top level CMakeLists sed -i 's@ign_configure_project(\(.*\))@ign_configure_project(\n REPLACE_IGNITION_INCLUDE_PATH gz/utils\n \1)@g' CMakeLists.txt -# Migrate -find . -regex './include/ignition.*' -type f -print0 | xargs -0 -I {} bash -c 'migrate_ign_to_gz {}' _ +# Move headers +find . -regex '.*include\(.*\)*' -type f -print0 | xargs -0 -I {} bash -c 'mv_headers {}' _ + +# Create Export.hh and .hh +find . -regex './include.*/ignition/[^/]*' -type d -print0 \ + | xargs -0 -I {} bash -c 'touch "{}/Export.hh" \ + && echo "[CREATED] {}/Export.hh"' _ +find . -regex './include.*/ignition/[^/]*' -type d -print0 \ + | xargs -0 -I {} bash -c 'touch "$(sed "s@\(.*\)/\(.*\)\$@\1/\2/\2.hh@g" <<< {})" \ + && echo "[CREATED] $(sed "s@\(.*\)/\(.*\)\$@\1/\2/\2.hh@g" <<< {})"' + +# Cleanup dangling files +find . -regex ".*/include.*/ignition.*/CMakeLists\.txt" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling .in config files +find . -regex ".*/include.*/ignition.*/.*\.in" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling ignition CMakeLists # Provision redirection aliases -find . -regex './include/ignition.*' -type f -print0 | xargs -0 -I {} bash -c 'redirection_alias {}' _ -find . -regex "./include/ignition.*/CMakeLists.txt" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling ignition CMakeLists +find . -regex '.*include.*/ignition.*\.h.*\|.*include\(.*\)*/Ign\(ition\)?[A-Z].*\.h.*' -type f -print0 \ + | xargs -0 -I {} bash -c 'populate_redirection_alias {}' _ + +# Migrate Gz sources +find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrate_sources {}' _ + +# Migrate Gz CMake files +find . -regex '.*include.*/gz.*\|.*include\(.*\)*/Gz.*' -type f -print0 | xargs -0 -I {} bash -c 'migrate_cmake {}' _ # Add header level CMakeLists.txt touch ./include/CMakeLists.txt echo "add_subdirectory(gz)" > ./include/CMakeLists.txt echo "install(DIRECTORY ignition DESTINATION \${IGN_INCLUDE_INSTALL_DIR_FULL})" >> ./include/CMakeLists.txt - # TODOs -# Make Export.hh and utils.hh -# Parse libs +# Parse libs from CLI # Clone and autobranch/push From 0a3215c14636205f90a58ff5c0b196c4dcf3a89f Mon Sep 17 00:00:00 2001 From: methylDragon Date: Mon, 25 Apr 2022 17:16:09 -0700 Subject: [PATCH 03/21] Rename methods, fix bugs, and implement successive commits and PR --- .../tools/header_migration_script.sh | 209 ++++++++++++++++-- 1 file changed, 189 insertions(+), 20 deletions(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index 0473312dd..bb230680b 100644 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -44,7 +44,7 @@ # Author: methylDragon -# METHODS AND CONSTANTS ============================================================================ +# CONSTANTS ======================================================================================== export LICENSE="""\ /* * Copyright (C) 2022 Open Source Robotics Foundation @@ -64,8 +64,161 @@ export LICENSE="""\ */ """ +DEFAULT="\e[39m" +DEFAULT_BG="\e[49m" + +GREY="\e[90m" +GREEN="\e[32m" +RED="\e[31m" +WHITE_BG="\e[107m" +BLUE_BG="\e[44m" +GREEN_BG="\e[42m" + +IGN_ORG="ignitionrobotics" +DEFAULT_COMMIT_MSG="DEFAULT_COMMIT_MSG" # Bumps in ${COLLECTION}" +DEFAULT_PR_TITLE="DEFAULT_PR_TITLE" +DEFAULT_PR_TEXT="DEFAULT_PR_TEXT" # See https://github.com/${TOOLING_ORG}/release-tools/issues/${ISSUE_NUMBER}" + + +# GIT ============================================================================================== +# Return the passed branch if provided, or main / master +getBaseBranch() { + + local BASE_BRANCH=$1 + + # If no base branch provided, use main or master + if [ -z "$BASE_BRANCH" ]; then + HAS_MAIN=$(git ls-remote --heads origin main) + if [[ ! -z ${HAS_MAIN} ]]; then + local BASE_BRANCH="main" + else + local BASE_BRANCH="master" + fi + fi + + echo "$BASE_BRANCH" +} + + +# Helper to checkout a clean branch +# Args: +# $1: Branch to open PR from +# $2: Branch to build on top of +startFromCleanBranch() { + + local PR_BRANCH=$1 + local BASE_BRANCH=$2 + local REPO=${PWD##*/} + + git fetch + git reset --hard + + # If PR branch exists, checkout and start fresh + + # Check local + HAS_PR_BRANCH=$(git branch --list ${PR_BRANCH}) + if [[ ! -z ${HAS_PR_BRANCH} ]]; then + echo -e "${GREEN}${REPO}: Checking out branch ${PR_BRANCH}${DEFAULT}" + git checkout $PR_BRANCH + return + fi + + # Check remote + HAS_PR_BRANCH=$(git ls-remote --heads origin ${PR_BRANCH}) + if [[ ! -z ${HAS_PR_BRANCH} ]]; then + echo -e "${GREEN}${REPO}: Checking out branch ${PR_BRANCH}${DEFAULT}" + git checkout $PR_BRANCH + git pull + return + fi + + local BASE_BRANCH=$(getBaseBranch $BASE_BRANCH) + + # Make sure base branch exists + HAS_BASE_BRANCH=$(git ls-remote --heads origin ${BASE_BRANCH}) + if [[ -z ${HAS_BASE_BRANCH} ]]; then + echo -e "${RED}${REPO}: Branch ${BASE_BRANCH} does not exist.${DEFAULT}" + return + fi + + # Create PR branch off base + echo -e "${GREEN}${REPO}: Checking out ${BASE_BRANCH}${DEFAULT}" + git checkout $BASE_BRANCH + git pull + echo -e "${GREEN}${REPO}: Creating new branch ${PR_BRANCH}${DEFAULT}" + git checkout -b $PR_BRANCH +} + + +# Commit and open PR +# Args: +# $1: Org name +# $2: Base branch to open PR against +# $3: Commit message +# $3: PR text +gitCommit() { + local REPO=${PWD##*/} + local ORG=$1 + local COMMIT_MSG=${2:-${DEFAULT_COMMIT_MSG}} + local ADD_ALL=${3:-0} + + if git diff --exit-code; then + echo -e "${GREEN}${REPO}: Nothing to commit for ${REPO}.${DEFAULT}" + return + fi + + # Sanity check that we're on a right branch + local CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + if [[ ! $CURRENT_BRANCH =~ header_migration.* ]] ; then + echo -e "${RED}${REPO}: Something's wrong, trying to commit to branch ${CURRENT_BRANCH}.${DEFAULT}" + return + fi + + echo -e "${GREEN_BG}${REPO}: Commit ${REPO}: ${COMMIT_MSG} ? (y/n)${DEFAULT_BG}" + read CONTINUE + if [ "$CONTINUE" = "y" ]; then + if (( $ADD_ALL )) ; then + git add -A + fi + + git commit -sam "${COMMIT_MSG}" + fi +} + -mv_headers() { +gitPushAndPR() { + local REPO=${PWD##*/} + local ORG=$1 + local BASE_BRANCH=$2 + local PR_TITLE=${3:-${DEFAULT_PR_TEXT}} + local PR_TEXT=${4:-${DEFAULT_PR_TEXT}} + + # Sanity check that we're on a right branch + local CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + if [[ ! $CURRENT_BRANCH =~ header_migration.* ]] ; then + echo -e "${RED}${REPO}: Something's wrong, trying to commit to branch ${CURRENT_BRANCH}.${DEFAULT}" + return + fi + + echo -e "${GREEN_BG}${REPO}: Push to ${REPO} (${CURRENT_BRANCH}) and PR branch: ${CURRENT_BRANCH} -> ${BASE_BRANCH}? (y/n)${DEFAULT_BG}" + read CONTINUE + if [ "$CONTINUE" = "y" ]; then + git push origin ${CURRENT_BRANCH} + gh pr create --title "${PR_TITLE}" --body "${PR_TEXT}" --repo ${ORG}/${REPO} --base ${BASE_BRANCH} + fi +} + + +# METHODS AND CONSTANTS ============================================================================ +reviewConfirm() { + echo -e "${GREEN_BG}Reviewed changes, ready to commit? (y/n)${DEFAULT_BG}" + read CONTINUE + if [ "$CONTINUE" = "y" ]; then + return + fi +} + +mvHeaders() { # Create necessary directories dirname $1 | sed 's@include\(.*\)*/ignition@include\1/gz@g' | xargs -I {} mkdir -pv {} @@ -83,10 +236,10 @@ mv_headers() { # Leave redirection aliases # Converting *.in into normal versions (spoofing configuration of *.in files) echo $1 | sed 's@\(.*\)\.in@\1@g' | xargs -I {} touch {} -} ; export -f mv_headers +} ; export -f mvHeaders -migrate_sources() { # Different variations of ignition/ign -> gz in source files +migrateSources() { # Different variations of ignition/ign -> gz in source files # Note: DOES NOT MIGRATE CLASS OR VARIABLE NAMES if [[ $1 =~ \.c[^\.]*$|\.in[^\.]*$|\.h[^\.]*$ ]] ; then # Only do for source files @@ -107,10 +260,10 @@ migrate_sources() { # Different variations of ignition/ign -> gz in source file # Handle Edge Cases sed -i 's@${gz_headers}@${ign_headers}@g' $1 fi -} ; export -f migrate_sources +} ; export -f migrateSources -migrate_cmake() { # Different variations of ignition/ign -> gz in CMake files +migrateCmake() { # Different variations of ignition/ign -> gz in CMake files # This is special because we need to specifically avoid unmigrated ign-cmake macro calls if [[ $1 =~ CMakeLists.txt ]] ; then # Only do for CMakeLists files @@ -126,29 +279,36 @@ migrate_cmake() { # Different variations of ignition/ign -> gz in CMake files sed -i 's@^\(?!ign\(?ition\)_\)Ignition\([A-Z]\)@Gz\1@g' $1 # e.g. IgnitionFormatter -> GzFormatter - sed -i 's@^\(?!ign\(?ition\)_\)(ignition@(gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) + sed -i 's@^\(?!ign\(?ition\)_\)(\(.*\)ignition@(\1gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) sed -i 's@^\(?!ign\(?ition\)_\)ignition/@gz/@g' $1 # e.g. include -> include sed -i 's@^\(?!ign\(?ition\)_\)ignition_@gz_/@g' $1 # e.g. ignition_xxx -> gz_xxx sed -i 's@^\(?!ign\(?ition\)_\)ign_@gz_/@g' $1 # e.g. ign_xxx -> gz_xxx fi -} ; export -f migrate_cmake +} ; export -f migrateCmake -populate_redirection_alias() { +populateRedirectionAlias() { echo "[REDIRECTING] $1" echo "$LICENSE" > $1 echo "#include <$(echo $1 | sed \ -e 's@.*/include/@@g' \ -e 's@ignition/@gz/@g' \ -e 's@*Ign(ition)@Gz@g')>" >> $1 -} ; export -f populate_redirection_alias +} ; export -f populateRedirectionAlias # MAIN ============================================================================================= -# Edit top level CMakeLists -sed -i 's@ign_configure_project(\(.*\))@ign_configure_project(\n REPLACE_IGNITION_INCLUDE_PATH gz/utils\n \1)@g' CMakeLists.txt +startFromCleanBranch header_migration main # Move headers -find . -regex '.*include\(.*\)*' -type f -print0 | xargs -0 -I {} bash -c 'mv_headers {}' _ +find . -regex '.*include\(.*\)*' -type f -print0 | xargs -0 -I {} bash -c 'mvHeaders {}' _ + +# Cleanup dangling files +find . -regex ".*/include.*/ignition.*/CMakeLists\.txt" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling .in config files +find . -regex ".*/include.*/ignition.*/.*\.in" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling ignition CMakeLists + +git reset -q # We need this because we're using git mv +reviewConfirm +gitCommit ${IGN_ORG} "Move header files" 1 # 1 to `git add -A` # Create Export.hh and .hh find . -regex './include.*/ignition/[^/]*' -type d -print0 \ @@ -158,25 +318,34 @@ find . -regex './include.*/ignition/[^/]*' -type d -print0 \ | xargs -0 -I {} bash -c 'touch "$(sed "s@\(.*\)/\(.*\)\$@\1/\2/\2.hh@g" <<< {})" \ && echo "[CREATED] $(sed "s@\(.*\)/\(.*\)\$@\1/\2/\2.hh@g" <<< {})"' -# Cleanup dangling files -find . -regex ".*/include.*/ignition.*/CMakeLists\.txt" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling .in config files -find . -regex ".*/include.*/ignition.*/.*\.in" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling ignition CMakeLists - # Provision redirection aliases find . -regex '.*include.*/ignition.*\.h.*\|.*include\(.*\)*/Ign\(ition\)?[A-Z].*\.h.*' -type f -print0 \ - | xargs -0 -I {} bash -c 'populate_redirection_alias {}' _ + | xargs -0 -I {} bash -c 'populateRedirectionAlias {}' _ + +reviewConfirm +gitCommit ${IGN_ORG} "Provision redirection aliases" 1 # 1 to `git add -A` # Migrate Gz sources -find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrate_sources {}' _ +find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _ + +reviewConfirm +gitCommit ${IGN_ORG} "Migrate sources in src, test, examples, and include" # Migrate Gz CMake files -find . -regex '.*include.*/gz.*\|.*include\(.*\)*/Gz.*' -type f -print0 | xargs -0 -I {} bash -c 'migrate_cmake {}' _ +find . -regex '.*include.*/gz.*\|.*include\(.*\)*/Gz.*' -type f -print0 | xargs -0 -I {} bash -c 'migrateCmake {}' _ # Add header level CMakeLists.txt touch ./include/CMakeLists.txt echo "add_subdirectory(gz)" > ./include/CMakeLists.txt echo "install(DIRECTORY ignition DESTINATION \${IGN_INCLUDE_INSTALL_DIR_FULL})" >> ./include/CMakeLists.txt +# Edit top level CMakeLists +sed -i 's@ign_configure_project(\(.*\))@ign_configure_project(\n REPLACE_IGNITION_INCLUDE_PATH gz/utils\n \1)@g' CMakeLists.txt + +reviewConfirm +gitCommit ${IGN_ORG} "Migrate CMake files" +gitPushAndPR ${IGN_ORG} main "ign -> gz Header Migration" "Test run of https://github.com/ignition-tooling/release-tools/pull/712" + # TODOs # Parse libs from CLI # Clone and autobranch/push From 5656f10475339231b62bbbacb0ce7c21bb6f1eb6 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Mon, 25 Apr 2022 17:25:05 -0700 Subject: [PATCH 04/21] Fix incorrect regex expressions and handle edge cases Signed-off-by: methylDragon --- .../tools/header_migration_script.sh | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index bb230680b..b56feb93c 100644 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -257,7 +257,7 @@ migrateSources() { # Different variations of ignition/ign -> gz in source files sed -i 's@ignition_@gz_@g' $1 # e.g. ignition_xxx -> gz_xxx sed -i 's@ign_@gz_@g' $1 # e.g. ign_xxx -> gz_xxx - # Handle Edge Cases + # Rollback edge cases sed -i 's@${gz_headers}@${ign_headers}@g' $1 fi } ; export -f migrateSources @@ -271,18 +271,23 @@ migrateCmake() { # Different variations of ignition/ign -> gz in CMake files sed -i 's@(ignition@(gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) - # NOTE(CH3): - # ^\(?!ign\(?ition\)_\) ignores lines that start with ign(nition)_ - # Which should avoid changing any ign-cmake macro calls - sed -i 's@^\(?!ign\(?ition\)_\)\(#.*\) IGNITION_@\1 GZ_@g' $1 # e.g. IGNITION_UTILS__XXX -> GZ_UTILS__XXX - sed -i 's@^\(?!ign\(?ition\)_\)\(#.*\) IGN_@\1 GZ_@g' $1 # e.g. IGN_UTILS__XXX -> GZ_UTILS__XXX - - sed -i 's@^\(?!ign\(?ition\)_\)Ignition\([A-Z]\)@Gz\1@g' $1 # e.g. IgnitionFormatter -> GzFormatter + sed -i 's@Ignition\([A-Z]\)@Gz\1@g' $1 # e.g. IgnitionFormatter -> GzFormatter + sed -i 's@(\(.*\)ignition@(\1gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) - sed -i 's@^\(?!ign\(?ition\)_\)(\(.*\)ignition@(\1gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) - sed -i 's@^\(?!ign\(?ition\)_\)ignition/@gz/@g' $1 # e.g. include -> include - sed -i 's@^\(?!ign\(?ition\)_\)ignition_@gz_/@g' $1 # e.g. ignition_xxx -> gz_xxx - sed -i 's@^\(?!ign\(?ition\)_\)ign_@gz_/@g' $1 # e.g. ign_xxx -> gz_xxx + # NOTE(CH3): + # ^\([^ign ]\+\) ignores lines that start with ign(nition)_ + # Which should avoid changing most ign-cmake macro calls + sed -i 's@\b\([^ign ]\+\)ignition/@\1gz/@g' $1 # e.g. include -> include + sed -i 's@\b\([^ign ]\+\)ignition_@\1gz_@g' $1 # e.g. ignition_xxx -> gz_xxx + sed -i 's@\b\([^ign ]\+\)ign_@\1gz_@g' $1 # e.g. ign_xxx -> gz_xxx + + # Rollback edge cases + # TODO(CH3): This becomes a helper once our project names are actually migrated + # We can remove the rollbacks then! + sed -i 's@project(gz@project(ignition@g' $1 + sed -i 's@find_package(gz@find_package(ignition@g' $1 + sed -i 's@IGN_\([^_]*\)_VER ${gz@IGN_\1_VER ${ignition@g' $1 + sed -i 's@-Dgz@-Dignition@g' $1 fi } ; export -f migrateCmake @@ -293,7 +298,7 @@ populateRedirectionAlias() { echo "#include <$(echo $1 | sed \ -e 's@.*/include/@@g' \ -e 's@ignition/@gz/@g' \ - -e 's@*Ign(ition)@Gz@g')>" >> $1 + -e 's@Ign\(ition\)\?@Gz@g')>" >> $1 } ; export -f populateRedirectionAlias # MAIN ============================================================================================= @@ -332,7 +337,7 @@ reviewConfirm gitCommit ${IGN_ORG} "Migrate sources in src, test, examples, and include" # Migrate Gz CMake files -find . -regex '.*include.*/gz.*\|.*include\(.*\)*/Gz.*' -type f -print0 | xargs -0 -I {} bash -c 'migrateCmake {}' _ +find . -regex '.*[include\|src\|test\|examples].*/CMakeLists\.txt' -type f -print0 | xargs -0 -I {} bash -c 'migrateCmake {}' _ # Add header level CMakeLists.txt touch ./include/CMakeLists.txt @@ -348,4 +353,4 @@ gitPushAndPR ${IGN_ORG} main "ign -> gz Header Migration" "Test run of https://g # TODOs # Parse libs from CLI -# Clone and autobranch/push +# Clone From 984824c009c956ea98eeb0c5ae124368c7a0b993 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Tue, 26 Apr 2022 17:54:54 -0700 Subject: [PATCH 05/21] Make git commit function more flexible Signed-off-by: methylDragon --- .../tools/header_migration_script.sh | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index b56feb93c..fa46af4cf 100644 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -151,20 +151,49 @@ startFromCleanBranch() { # Commit and open PR +# gitCommit [-a] [-c] [-f] [-s] ORG [COMMIT_MSG] # Args: # $1: Org name # $2: Base branch to open PR against # $3: Commit message -# $3: PR text gitCommit() { + local OPTIND ADD_ALL STAGED_DIFF FORCE_COMMIT + while getopts acfs flag; do + case "${flag}" in + a) + local ADD_ALL="true" && echo -e "${GREEN}[gitCommit] Adding all unstaged files to commit!${DEFAULT}" + ;; + c|s) + local STAGED_DIFF="true" && echo -e "${GREEN}[gitCommit] Checking diff for staged files!${DEFAULT}" + ;; + f) + local FORCE_COMMIT="true" && echo -e "${GREEN}[gitCommit] Ignoring diffs!${DEFAULT}" + ;; + *) + echo -e "${RED}[gitCommit] Invalid flag passed! Valid: -s -c -a ${DEFAULT}" + ;; + esac + done + shift $((OPTIND-1)) + local REPO=${PWD##*/} local ORG=$1 local COMMIT_MSG=${2:-${DEFAULT_COMMIT_MSG}} - local ADD_ALL=${3:-0} - if git diff --exit-code; then - echo -e "${GREEN}${REPO}: Nothing to commit for ${REPO}.${DEFAULT}" - return + if [[ "${FORCE_COMMIT}" == "true" ]] ; then + echo -e "${GREEN}[gitCommit] Skipping diff check!${DEFAULT}" + else + if [[ "${STAGED_DIFF}" == "true" ]] ; then + if git diff --staged --exit-code; then + echo -e "${GREEN}${REPO}: Nothing to commit for ${REPO}.${DEFAULT}" + return + fi + else + if git diff --exit-code; then + echo -e "${GREEN}${REPO}: Nothing to commit for ${REPO}.${DEFAULT}" + return + fi + fi fi # Sanity check that we're on a right branch @@ -177,10 +206,9 @@ gitCommit() { echo -e "${GREEN_BG}${REPO}: Commit ${REPO}: ${COMMIT_MSG} ? (y/n)${DEFAULT_BG}" read CONTINUE if [ "$CONTINUE" = "y" ]; then - if (( $ADD_ALL )) ; then + if [[ "${ADD_ALL}" == "true" ]] ; then git add -A fi - git commit -sam "${COMMIT_MSG}" fi } From 8ce01767ac0c8bfb35c5770f5c6609f8476176b3 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Tue, 26 Apr 2022 17:57:06 -0700 Subject: [PATCH 06/21] Edit redirection to enable git mv history preservation Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index fa46af4cf..8d4c25872 100644 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -258,12 +258,17 @@ mvHeaders() { echo $1 | sed \ -e 's@include\(.*\)*/ignition@include\1/gz@g' \ -e 's@include\(.*\)*/Ign\(ition\)\?\([A-Z]\)@include\1/Gz\3@g' \ - | xargs -I {} bash -c "git mv -f $1 {} && echo '[MOVED] $1 --> {}'" _ + | xargs -I {} bash -c "git mv -f $1 {} && cp {} $1 && echo '[MOVED WITH RESIDUAL] $1 --> {}'" _ fi # Leave redirection aliases # Converting *.in into normal versions (spoofing configuration of *.in files) - echo $1 | sed 's@\(.*\)\.in@\1@g' | xargs -I {} touch {} + if [[ $1 =~ .*\.in ]] ; then + echo "[CONVERTING] $1" + echo $1 | sed 's@\(.*\)\.in@\1@g' | xargs -I {} mv $1 {} + fi + + # echo $1 | sed 's@\(.*\)\.in@\1@g' | xargs -I {} touch {} } ; export -f mvHeaders @@ -339,9 +344,10 @@ find . -regex '.*include\(.*\)*' -type f -print0 | xargs -0 -I {} bash -c 'mvHea find . -regex ".*/include.*/ignition.*/CMakeLists\.txt" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling .in config files find . -regex ".*/include.*/ignition.*/.*\.in" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling ignition CMakeLists -git reset -q # We need this because we're using git mv reviewConfirm -gitCommit ${IGN_ORG} "Move header files" 1 # 1 to `git add -A` +gitCommit -s ${IGN_ORG} "Move header files with git mv" # Commits staged git mv changes +echo -e "\n== Copying Redirection Aliases ==\n" +gitCommit -f -a ${IGN_ORG} "Create redirection aliases" # Adds and commits unstaged redirections # Create Export.hh and .hh find . -regex './include.*/ignition/[^/]*' -type d -print0 \ From 6e206cb099c4f15fbeae4dbb6d7ed566ad8cc2b2 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Tue, 26 Apr 2022 17:57:29 -0700 Subject: [PATCH 07/21] Change lib header location Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index 8d4c25872..2c6c0af1f 100644 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -354,8 +354,8 @@ find . -regex './include.*/ignition/[^/]*' -type d -print0 \ | xargs -0 -I {} bash -c 'touch "{}/Export.hh" \ && echo "[CREATED] {}/Export.hh"' _ find . -regex './include.*/ignition/[^/]*' -type d -print0 \ - | xargs -0 -I {} bash -c 'touch "$(sed "s@\(.*\)/\(.*\)\$@\1/\2/\2.hh@g" <<< {})" \ - && echo "[CREATED] $(sed "s@\(.*\)/\(.*\)\$@\1/\2/\2.hh@g" <<< {})"' + | xargs -0 -I {} bash -c 'touch "$(sed "s@\(.*\)/\(.*\)\$@\1/\2.hh@g" <<< {})" \ + && echo "[CREATED] $(sed "s@\(.*\)/\(.*\)\$@\1/\2.hh@g" <<< {})"' # Provision redirection aliases find . -regex '.*include.*/ignition.*\.h.*\|.*include\(.*\)*/Ign\(ition\)?[A-Z].*\.h.*' -type f -print0 \ From 434ee6d8d70976b0b46fcceb6142be6a5ec2249f Mon Sep 17 00:00:00 2001 From: methylDragon Date: Tue, 26 Apr 2022 17:58:01 -0700 Subject: [PATCH 08/21] Implement copyright preservation Signed-off-by: methylDragon --- .../tools/header_migration_script.sh | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index 2c6c0af1f..4bb11540a 100644 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -361,8 +361,27 @@ find . -regex './include.*/ignition/[^/]*' -type d -print0 \ find . -regex '.*include.*/ignition.*\.h.*\|.*include\(.*\)*/Ign\(ition\)?[A-Z].*\.h.*' -type f -print0 \ | xargs -0 -I {} bash -c 'populateRedirectionAlias {}' _ +# Do some absolutely ridiculous awk sourcery to remove most instances of copyright edits +GIT_DIFF="$(git diff)" +PATCHED_GIT_DIFF=$(awk '{ + if(/^-.*Open Source Robotics Foundation/){ + prev=$0; + getline; + + if(/^\+.*Open Source Robotics Foundation/){ + print prev; sub(/^-/, "+", prev); print prev; + } else { + print prev "\n" $0; + } + } + else{print;} +}' <<< "${GIT_DIFF}") + +git restore . +git apply <<< "${PATCHED_GIT_DIFF}" + reviewConfirm -gitCommit ${IGN_ORG} "Provision redirection aliases" 1 # 1 to `git add -A` +gitCommit -a ${IGN_ORG} "Provision redirection aliases" # Migrate Gz sources find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _ From 49567c563e6063c5a12a1cba68f4a9d7f7203f45 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Tue, 26 Apr 2022 17:58:10 -0700 Subject: [PATCH 09/21] Fix regex Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index 4bb11540a..c1db42608 100644 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -288,7 +288,10 @@ migrateSources() { # Different variations of ignition/ign -> gz in source files sed -i 's@ignition/@gz/@g' $1 # e.g. include -> include sed -i 's@ignition_@gz_@g' $1 # e.g. ignition_xxx -> gz_xxx - sed -i 's@ign_@gz_@g' $1 # e.g. ign_xxx -> gz_xxx + + # NOTE(CH3): The other one was too greedy (sign_bit -> sgz_bit) + # sed -i 's@ign_@gz_@g' $1 # e.g. ign_xxx -> gz_xxx + sed -i 's@\([{(_<"]\)ign_@\1gz_@g' $1 # e.g. ${ign_utils} -> ${gz_utils} # Rollback edge cases sed -i 's@${gz_headers}@${ign_headers}@g' $1 @@ -312,7 +315,13 @@ migrateCmake() { # Different variations of ignition/ign -> gz in CMake files # Which should avoid changing most ign-cmake macro calls sed -i 's@\b\([^ign ]\+\)ignition/@\1gz/@g' $1 # e.g. include -> include sed -i 's@\b\([^ign ]\+\)ignition_@\1gz_@g' $1 # e.g. ignition_xxx -> gz_xxx - sed -i 's@\b\([^ign ]\+\)ign_@\1gz_@g' $1 # e.g. ign_xxx -> gz_xxx + sed -i 's@\b\([^ign ]\+\)ign_@\1gz_@g' $1 # e.g. XXX_ign_xxx -> XXX_gz_xxx + + # /^#/! ignores lines starting with # (ignore comments) + sed -i '/^#/!s@\(\w\) ign_@\1 gz_@g' $1 # e.g. XXX ign_xxx -> XXX gz_xxx + + # Catchall for open-parentheses/quotes + sed -i 's@\([{(_<"]\)ign_@\1gz_@g' $1 # e.g. ${ign_utils} -> ${gz_utils} # Rollback edge cases # TODO(CH3): This becomes a helper once our project names are actually migrated From c89dfe715d8a369b1676f2204ebd45df6440206a Mon Sep 17 00:00:00 2001 From: methylDragon Date: Tue, 26 Apr 2022 19:02:33 -0700 Subject: [PATCH 10/21] Amend commit instead, and sanitize input prompts Signed-off-by: methylDragon --- .../tools/header_migration_script.sh | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index c1db42608..9a59d4c36 100644 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -158,7 +158,7 @@ startFromCleanBranch() { # $3: Commit message gitCommit() { local OPTIND ADD_ALL STAGED_DIFF FORCE_COMMIT - while getopts acfs flag; do + while getopts acefs flag; do case "${flag}" in a) local ADD_ALL="true" && echo -e "${GREEN}[gitCommit] Adding all unstaged files to commit!${DEFAULT}" @@ -166,11 +166,14 @@ gitCommit() { c|s) local STAGED_DIFF="true" && echo -e "${GREEN}[gitCommit] Checking diff for staged files!${DEFAULT}" ;; + e) + local AMEND="true" && echo -e "${GREEN}[gitCommit] Amending commit!${DEFAULT}" + ;; f) local FORCE_COMMIT="true" && echo -e "${GREEN}[gitCommit] Ignoring diffs!${DEFAULT}" ;; *) - echo -e "${RED}[gitCommit] Invalid flag passed! Valid: -s -c -a ${DEFAULT}" + echo -e "${RED}[gitCommit] Invalid flag passed! Valid: -s -c -e -a ${DEFAULT}" ;; esac done @@ -203,13 +206,30 @@ gitCommit() { return fi - echo -e "${GREEN_BG}${REPO}: Commit ${REPO}: ${COMMIT_MSG} ? (y/n)${DEFAULT_BG}" - read CONTINUE + while true; do + if [[ "${AMEND}" == "true" ]] ; then + echo -e "${GREEN_BG}${REPO}: Amend latest commit on ${REPO}? (y/n)${DEFAULT_BG}" + else + echo -e "${GREEN_BG}${REPO}: Commit ${REPO}: ${COMMIT_MSG} ? (y/n)${DEFAULT_BG}" + fi + + read CONTINUE + + case $CONTINUE in + y) break;; + n) echo -e "${GREEN}Skipping commit${DEFAULT}" && break;; + esac + done + if [ "$CONTINUE" = "y" ]; then if [[ "${ADD_ALL}" == "true" ]] ; then git add -A fi - git commit -sam "${COMMIT_MSG}" + if [[ "${AMEND}" == "true" ]] ; then + git commit --amend -C HEAD + else + git commit -sam "${COMMIT_MSG}" + fi fi } @@ -239,8 +259,15 @@ gitPushAndPR() { # METHODS AND CONSTANTS ============================================================================ reviewConfirm() { - echo -e "${GREEN_BG}Reviewed changes, ready to commit? (y/n)${DEFAULT_BG}" - read CONTINUE + while true; do + echo -e "${GREEN_BG}Have you reviewed the changes above, and are you ready to commit? (y?)${DEFAULT_BG}" + read CONTINUE + + case $CONTINUE in + y) break;; + esac + done + if [ "$CONTINUE" = "y" ]; then return fi @@ -390,7 +417,7 @@ git restore . git apply <<< "${PATCHED_GIT_DIFF}" reviewConfirm -gitCommit -a ${IGN_ORG} "Provision redirection aliases" +gitCommit -f -a -e ${IGN_ORG} # Migrate Gz sources find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _ From e0ff325e5bf6ea67ec065f3dec0bf66380b36c13 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Wed, 27 Apr 2022 14:41:12 -0700 Subject: [PATCH 11/21] Fix more regex Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index 9a59d4c36..5f57e2e3a 100644 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -300,20 +300,20 @@ mvHeaders() { migrateSources() { # Different variations of ignition/ign -> gz in source files - # Note: DOES NOT MIGRATE CLASS OR VARIABLE NAMES + # NOTE(CH3): DOES NOT MIGRATE CLASS OR VARIABLE NAMES if [[ $1 =~ \.c[^\.]*$|\.in[^\.]*$|\.h[^\.]*$ ]] ; then # Only do for source files echo "[MIGRATING SOURCES] $1" if [[ $1 != *.in ]] ; then # !! But not macros for .in files - # Only migrate non-macro definition calls - sed -i 's@\(#.*\) IGNITION_\([^(]*\)$@\1 GZ_\2@g' $1 # e.g. IGNITION_UTILS__XXX -> GZ_UTILS__XXX - sed -i 's@\(#.*\) IGN_\([^(]*\)\$@\1 GZ_\2@g' $1 # e.g. IGN_UTILS__XXX -> GZ_UTILS__XXX + # Only migrate non-macro definition calls (loop to make it recursive) + # \([^(]*\)\ to ignore any macros with arguments (to target header guards only) + sed -i ':loop s@\(#.*\) IGN\(ITION\)\?\(.*\)_H\([^(]*\)$@\1 GZ\3_H\4@g; t loop' $1 # e.g. IGNITION_UTILS__XXX -> GZ_UTILS__XXX fi # NOTE(CH3): We're not migrating class or variable names for now # sed -i 's@Ignition\([A-Z]\)@Gz\1@g' $1 # e.g. IgnitionFormatter -> GzFormatter - sed -i 's@ignition/@gz/@g' $1 # e.g. include -> include + sed -i 's@ignition/@gz/@g' $1 # e.g. include -> include sed -i 's@ignition_@gz_@g' $1 # e.g. ignition_xxx -> gz_xxx # NOTE(CH3): The other one was too greedy (sign_bit -> sgz_bit) @@ -345,7 +345,7 @@ migrateCmake() { # Different variations of ignition/ign -> gz in CMake files sed -i 's@\b\([^ign ]\+\)ign_@\1gz_@g' $1 # e.g. XXX_ign_xxx -> XXX_gz_xxx # /^#/! ignores lines starting with # (ignore comments) - sed -i '/^#/!s@\(\w\) ign_@\1 gz_@g' $1 # e.g. XXX ign_xxx -> XXX gz_xxx + sed -i '/^#/! s@\(\w\) ign_@\1 gz_@g' $1 # e.g. XXX ign_xxx -> XXX gz_xxx # Catchall for open-parentheses/quotes sed -i 's@\([{(_<"]\)ign_@\1gz_@g' $1 # e.g. ${ign_utils} -> ${gz_utils} From f802873d4fb41499f1326827e62adcb3cb3ee34a Mon Sep 17 00:00:00 2001 From: methylDragon Date: Wed, 27 Apr 2022 14:42:00 -0700 Subject: [PATCH 12/21] Implement cloning and multi-PR functionality Signed-off-by: methylDragon --- .../tools/header_migration_script.sh | 184 +++++++++++------- 1 file changed, 116 insertions(+), 68 deletions(-) mode change 100644 => 100755 jenkins-scripts/tools/header_migration_script.sh diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh old mode 100644 new mode 100755 index 5f57e2e3a..cc7f1f3e9 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -39,11 +39,20 @@ # USAGE # ===== # Place the script in the root of the repo to be migrated, and run: -# $ ./header_migration_script.sh +# $ ./header_migration_script.sh ";;..." # # Author: methylDragon +# USER PARAMS ====================================================================================== +LIBRARY_INPUT=${1} +ISSUE_NUMBER=${2} + +if [[ $# -lt 2 ]]; then + echo "./header_migration_script.sh \";;...\" " + exit 1 +fi + # CONSTANTS ======================================================================================== export LICENSE="""\ /* @@ -75,12 +84,43 @@ BLUE_BG="\e[44m" GREEN_BG="\e[42m" IGN_ORG="ignitionrobotics" +TOOLING_ORG="ignition-tooling" + DEFAULT_COMMIT_MSG="DEFAULT_COMMIT_MSG" # Bumps in ${COLLECTION}" DEFAULT_PR_TITLE="DEFAULT_PR_TITLE" -DEFAULT_PR_TEXT="DEFAULT_PR_TEXT" # See https://github.com/${TOOLING_ORG}/release-tools/issues/${ISSUE_NUMBER}" +DEFAULT_PR_TEXT="DEFAULT_PR_TEXT" + +TEMP_DIR="/tmp/header_migration" +echo -e "${GREEN}Creating directory [${TEMP_DIR}]${DEFAULT}" +mkdir -p ${TEMP_DIR} +# PARAMS =========================================================================================== +PR_TEXT="See https://github.com/${TOOLING_ORG}/release-tools/issues/${ISSUE_NUMBER}" +PR_TITLE="ign -> gz Header Migration" # GIT ============================================================================================== +# Clone repository into temp dir if not cloned yet and move to that folder +# Args: +# $1: Organization +# $2: Repository +cloneIfNeeded() { + + cd ${TEMP_DIR} + + local ORG=$1 + local REPO=$2 + + if [ ! -d "$REPO" ]; then + echo -e "${GREEN}${REPO}: Cloning ${ORG}/${REPO}${DEFAULT}" + git clone https://github.com/${ORG}/${REPO} + else + echo -e "${GREEN}${REPO}: ${REPO} is already cloned${DEFAULT}" + fi + + cd $REPO +} + + # Return the passed branch if provided, or main / master getBaseBranch() { @@ -238,7 +278,7 @@ gitPushAndPR() { local REPO=${PWD##*/} local ORG=$1 local BASE_BRANCH=$2 - local PR_TITLE=${3:-${DEFAULT_PR_TEXT}} + local PR_TITLE=${3:-${DEFAULT_PR_TITLE}} local PR_TEXT=${4:-${DEFAULT_PR_TEXT}} # Sanity check that we're on a right branch @@ -260,7 +300,8 @@ gitPushAndPR() { # METHODS AND CONSTANTS ============================================================================ reviewConfirm() { while true; do - echo -e "${GREEN_BG}Have you reviewed the changes above, and are you ready to commit? (y?)${DEFAULT_BG}" + local MSG=${1:-"Have you reviewed the changes above, and are you ready to commit? (y?)"} + echo -e "${GREEN_BG}${MSG}${DEFAULT_BG}" read CONTINUE case $CONTINUE in @@ -290,7 +331,7 @@ mvHeaders() { # Leave redirection aliases # Converting *.in into normal versions (spoofing configuration of *.in files) - if [[ $1 =~ .*\.in ]] ; then + if [[ $1 =~ [Ii]gn(ition)?.*\.in ]] ; then echo "[CONVERTING] $1" echo $1 | sed 's@\(.*\)\.in@\1@g' | xargs -I {} mv $1 {} fi @@ -371,75 +412,82 @@ populateRedirectionAlias() { } ; export -f populateRedirectionAlias # MAIN ============================================================================================= -startFromCleanBranch header_migration main - -# Move headers -find . -regex '.*include\(.*\)*' -type f -print0 | xargs -0 -I {} bash -c 'mvHeaders {}' _ - -# Cleanup dangling files -find . -regex ".*/include.*/ignition.*/CMakeLists\.txt" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling .in config files -find . -regex ".*/include.*/ignition.*/.*\.in" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling ignition CMakeLists - -reviewConfirm -gitCommit -s ${IGN_ORG} "Move header files with git mv" # Commits staged git mv changes -echo -e "\n== Copying Redirection Aliases ==\n" -gitCommit -f -a ${IGN_ORG} "Create redirection aliases" # Adds and commits unstaged redirections - -# Create Export.hh and .hh -find . -regex './include.*/ignition/[^/]*' -type d -print0 \ - | xargs -0 -I {} bash -c 'touch "{}/Export.hh" \ - && echo "[CREATED] {}/Export.hh"' _ -find . -regex './include.*/ignition/[^/]*' -type d -print0 \ - | xargs -0 -I {} bash -c 'touch "$(sed "s@\(.*\)/\(.*\)\$@\1/\2.hh@g" <<< {})" \ - && echo "[CREATED] $(sed "s@\(.*\)/\(.*\)\$@\1/\2.hh@g" <<< {})"' - -# Provision redirection aliases -find . -regex '.*include.*/ignition.*\.h.*\|.*include\(.*\)*/Ign\(ition\)?[A-Z].*\.h.*' -type f -print0 \ - | xargs -0 -I {} bash -c 'populateRedirectionAlias {}' _ - -# Do some absolutely ridiculous awk sourcery to remove most instances of copyright edits -GIT_DIFF="$(git diff)" -PATCHED_GIT_DIFF=$(awk '{ - if(/^-.*Open Source Robotics Foundation/){ - prev=$0; - getline; - - if(/^\+.*Open Source Robotics Foundation/){ - print prev; sub(/^-/, "+", prev); print prev; - } else { - print prev "\n" $0; +IFS=';' +read -a LIBRARIES <<< "${LIBRARY_INPUT}" + +for ((i = 0; i < "${#LIBRARIES[@]}"; i++)); do + LIB=${LIBRARIES[$i]} + + cloneIfNeeded ${IGN_ORG} ${LIB} + startFromCleanBranch header_migration main + + echo -e "${GREEN}\n[STARTING MIGRATION] ${LIB}${DEFAULT}" + reviewConfirm "Read(y?)" + + # Move headers + find . -regex '.*include\(.*\)*' -type f -print0 | xargs -0 -I {} bash -c 'mvHeaders {}' _ + + # Cleanup dangling files + find . -regex ".*/include.*/ignition.*/CMakeLists\.txt" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling .in config files + find . -regex ".*/include.*/ignition.*/.*\.in" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling ignition CMakeLists + + reviewConfirm + gitCommit -s ${IGN_ORG} "Move header files with git mv" # Commits staged git mv changes + echo -e "\n== Copying Redirection Aliases ==\n" + gitCommit -f -a ${IGN_ORG} "Create redirection aliases" # Adds and commits unstaged redirections + + # Create Export.hh and .hh + find . -regex './include.*/ignition/[^/]*' -type d -print0 \ + | xargs -0 -I {} bash -c 'touch "{}/Export.hh" \ + && echo "[CREATED] {}/Export.hh"' _ + find . -regex './include.*/ignition/[^/]*' -type d -print0 \ + | xargs -0 -I {} bash -c 'touch "$(sed "s@\(.*\)/\(.*\)\$@\1/\2.hh@g" <<< {})" \ + && echo "[CREATED] $(sed "s@\(.*\)/\(.*\)\$@\1/\2.hh@g" <<< {})"' + + # Provision redirection aliases + find . -regex '.*include.*/ignition.*\.h.*\|.*include\(.*\)*/Ign\(ition\)?[A-Z].*\.h.*' -type f -print0 \ + | xargs -0 -I {} bash -c 'populateRedirectionAlias {}' _ + + # Do some absolutely ridiculous awk sourcery to remove most instances of copyright edits + GIT_DIFF="$(git diff)" + PATCHED_GIT_DIFF=$(awk '{ + if(/^-.*Open Source Robotics Foundation/){ + prev=$0; + getline; + + if(/^\+.*Open Source Robotics Foundation/){ + print prev; sub(/^-/, "+", prev); print prev; + } else { + print prev "\n" $0; + } } - } - else{print;} -}' <<< "${GIT_DIFF}") - -git restore . -git apply <<< "${PATCHED_GIT_DIFF}" + else{print;} + }' <<< "${GIT_DIFF}") -reviewConfirm -gitCommit -f -a -e ${IGN_ORG} + git restore . + git apply <<< "${PATCHED_GIT_DIFF}" -# Migrate Gz sources -find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _ + reviewConfirm + gitCommit -f -a -e ${IGN_ORG} -reviewConfirm -gitCommit ${IGN_ORG} "Migrate sources in src, test, examples, and include" + # Migrate Gz sources + find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _ -# Migrate Gz CMake files -find . -regex '.*[include\|src\|test\|examples].*/CMakeLists\.txt' -type f -print0 | xargs -0 -I {} bash -c 'migrateCmake {}' _ + reviewConfirm + gitCommit ${IGN_ORG} "Migrate sources in src, test, examples, and include" -# Add header level CMakeLists.txt -touch ./include/CMakeLists.txt -echo "add_subdirectory(gz)" > ./include/CMakeLists.txt -echo "install(DIRECTORY ignition DESTINATION \${IGN_INCLUDE_INSTALL_DIR_FULL})" >> ./include/CMakeLists.txt + # Migrate Gz CMake files + find . -regex '.*[include\|src\|test\|examples].*/CMakeLists\.txt' -type f -print0 | xargs -0 -I {} bash -c 'migrateCmake {}' _ -# Edit top level CMakeLists -sed -i 's@ign_configure_project(\(.*\))@ign_configure_project(\n REPLACE_IGNITION_INCLUDE_PATH gz/utils\n \1)@g' CMakeLists.txt + # Add header level CMakeLists.txt + touch ./include/CMakeLists.txt + echo "add_subdirectory(gz)" > ./include/CMakeLists.txt + echo "install(DIRECTORY ignition DESTINATION \${IGN_INCLUDE_INSTALL_DIR_FULL})" >> ./include/CMakeLists.txt -reviewConfirm -gitCommit ${IGN_ORG} "Migrate CMake files" -gitPushAndPR ${IGN_ORG} main "ign -> gz Header Migration" "Test run of https://github.com/ignition-tooling/release-tools/pull/712" + # Edit top level CMakeLists + sed -i 's@ign_configure_project(\(.*\))@ign_configure_project(\n REPLACE_IGNITION_INCLUDE_PATH gz/utils\n \1)@g' CMakeLists.txt -# TODOs -# Parse libs from CLI -# Clone + reviewConfirm + gitCommit ${IGN_ORG} "Migrate CMake files" + gitPushAndPR ${IGN_ORG} main "${PR_TITLE} : ${LIB}" ${PR_TEXT} +done From db42a17e8b33b03abf619f2660b9d6c7e54bf7f6 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Wed, 27 Apr 2022 14:45:38 -0700 Subject: [PATCH 13/21] Add clarificatory comment Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index cc7f1f3e9..fcc0704e8 100755 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -348,6 +348,7 @@ migrateSources() { # Different variations of ignition/ign -> gz in source files if [[ $1 != *.in ]] ; then # !! But not macros for .in files # Only migrate non-macro definition calls (loop to make it recursive) # \([^(]*\)\ to ignore any macros with arguments (to target header guards only) + # _H to target (mostly) header guards (might miss improperly defined header guards) sed -i ':loop s@\(#.*\) IGN\(ITION\)\?\(.*\)_H\([^(]*\)$@\1 GZ\3_H\4@g; t loop' $1 # e.g. IGNITION_UTILS__XXX -> GZ_UTILS__XXX fi From 815c48069237e5b75b3efb2d57b2a0851fb1c903 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Wed, 27 Apr 2022 16:21:49 -0700 Subject: [PATCH 14/21] Update regex Signed-off-by: methylDragon --- .../tools/header_migration_script.sh | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index fcc0704e8..e98670212 100755 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -316,15 +316,15 @@ reviewConfirm() { mvHeaders() { # Create necessary directories - dirname $1 | sed 's@include\(.*\)*/ignition@include\1/gz@g' | xargs -I {} mkdir -pv {} + dirname $1 | sed ':loop s@include\(.*\)*/\([^/]*_\)\?ign\(ition\)\?@include\1/\2gz@g; t loop' | xargs -I {} mkdir -pv {} # Move anything in an include/.../ignition or include/ignition subdirectory # Also handles: # IgnitionXXX -> GzXXX # IgnXXX -> GzXXX - if [[ $1 =~ include(.*)*/ignition ]] || [[ $1 =~ include(.*)*/Ign(ition)?[A-Z] ]] ; then + if [[ $1 =~ include(.*)*/([^/]*_)?ign(ition)? ]] || [[ $1 =~ include(.*)*/Ign(ition)?[A-Z] ]] ; then echo $1 | sed \ - -e 's@include\(.*\)*/ignition@include\1/gz@g' \ + -e ':loop s@include\(.*\)*/\([^/]*_\)\?ign\(ition\)\?@include\1/\2gz@g; t loop' \ -e 's@include\(.*\)*/Ign\(ition\)\?\([A-Z]\)@include\1/Gz\3@g' \ | xargs -I {} bash -c "git mv -f $1 {} && cp {} $1 && echo '[MOVED WITH RESIDUAL] $1 --> {}'" _ fi @@ -355,12 +355,14 @@ migrateSources() { # Different variations of ignition/ign -> gz in source files # NOTE(CH3): We're not migrating class or variable names for now # sed -i 's@Ignition\([A-Z]\)@Gz\1@g' $1 # e.g. IgnitionFormatter -> GzFormatter - sed -i 's@ignition/@gz/@g' $1 # e.g. include -> include + sed -i 's@ign\(ition\)\?/@gz/@g' $1 # e.g. include -> include + + # NOTE(CH3): Deliberate non-permissive match here sed -i 's@ignition_@gz_@g' $1 # e.g. ignition_xxx -> gz_xxx # NOTE(CH3): The other one was too greedy (sign_bit -> sgz_bit) # sed -i 's@ign_@gz_@g' $1 # e.g. ign_xxx -> gz_xxx - sed -i 's@\([{(_<"]\)ign_@\1gz_@g' $1 # e.g. ${ign_utils} -> ${gz_utils} + sed -i 's@\([{(_<"]\)ign\(ition\)\?_@\1gz_@g' $1 # e.g. ${ign_utils} -> ${gz_utils} # Rollback edge cases sed -i 's@${gz_headers}@${ign_headers}@g' $1 @@ -374,23 +376,22 @@ migrateCmake() { # Different variations of ignition/ign -> gz in CMake files if [[ $1 =~ CMakeLists.txt ]] ; then # Only do for CMakeLists files echo "[MIGRATING CMAKE] $1" - sed -i 's@(ignition@(gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) + sed -i 's@(ign\(ition\)\?@(gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) - sed -i 's@Ignition\([A-Z]\)@Gz\1@g' $1 # e.g. IgnitionFormatter -> GzFormatter - sed -i 's@(\(.*\)ignition@(\1gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) + sed -i 's@Ign\(ition\)\?\([A-Z]\)@Gz\2@g' $1 # e.g. IgnitionFormatter -> GzFormatter + sed -i 's@(\(.*\)ign\(ition\)\?@(\1gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) # NOTE(CH3): # ^\([^ign ]\+\) ignores lines that start with ign(nition)_ # Which should avoid changing most ign-cmake macro calls - sed -i 's@\b\([^ign ]\+\)ignition/@\1gz/@g' $1 # e.g. include -> include - sed -i 's@\b\([^ign ]\+\)ignition_@\1gz_@g' $1 # e.g. ignition_xxx -> gz_xxx - sed -i 's@\b\([^ign ]\+\)ign_@\1gz_@g' $1 # e.g. XXX_ign_xxx -> XXX_gz_xxx + sed -i 's@\b\([^ign ]\+\)ign\(ition\)\?/@\1gz/@g' $1 # e.g. include -> include + sed -i 's@\b\([^ign ]\+\)ign\(ition\)\?_@\1gz_@g' $1 # e.g. ignition_xxx -> gz_xxx # /^#/! ignores lines starting with # (ignore comments) - sed -i '/^#/! s@\(\w\) ign_@\1 gz_@g' $1 # e.g. XXX ign_xxx -> XXX gz_xxx + sed -i '/^#/! s@\(\w\) ign\(ition\)\?_@\1 gz_@g' $1 # e.g. XXX ign_xxx -> XXX gz_xxx # Catchall for open-parentheses/quotes - sed -i 's@\([{(_<"]\)ign_@\1gz_@g' $1 # e.g. ${ign_utils} -> ${gz_utils} + sed -i 's@\([{(_<"]\)ign\(ition\)\?_@\1gz_@g' $1 # e.g. ${ign_utils} -> ${gz_utils} # Rollback edge cases # TODO(CH3): This becomes a helper once our project names are actually migrated @@ -472,7 +473,7 @@ for ((i = 0; i < "${#LIBRARIES[@]}"; i++)); do gitCommit -f -a -e ${IGN_ORG} # Migrate Gz sources - find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _ + find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/\([^/]*_\)?[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _ reviewConfirm gitCommit ${IGN_ORG} "Migrate sources in src, test, examples, and include" From da340bb420702374d0be95c4e4cb016d317db3dd Mon Sep 17 00:00:00 2001 From: methylDragon Date: Wed, 27 Apr 2022 23:55:48 -0700 Subject: [PATCH 15/21] Make example updating more aggressive Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index e98670212..35df8da0b 100755 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -398,6 +398,7 @@ migrateCmake() { # Different variations of ignition/ign -> gz in CMake files # We can remove the rollbacks then! sed -i 's@project(gz@project(ignition@g' $1 sed -i 's@find_package(gz@find_package(ignition@g' $1 + sed -i 's@find_package(Gz@find_package(Ign@g' $1 sed -i 's@IGN_\([^_]*\)_VER ${gz@IGN_\1_VER ${ignition@g' $1 sed -i 's@-Dgz@-Dignition@g' $1 fi @@ -475,6 +476,9 @@ for ((i = 0; i < "${#LIBRARIES[@]}"; i++)); do # Migrate Gz sources find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/\([^/]*_\)?[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _ + # More permissive migration for Gz examples + find . -regex '.*/examples/.*\|.*include\(.*\)*/.*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _ + reviewConfirm gitCommit ${IGN_ORG} "Migrate sources in src, test, examples, and include" @@ -490,6 +494,6 @@ for ((i = 0; i < "${#LIBRARIES[@]}"; i++)); do sed -i 's@ign_configure_project(\(.*\))@ign_configure_project(\n REPLACE_IGNITION_INCLUDE_PATH gz/utils\n \1)@g' CMakeLists.txt reviewConfirm - gitCommit ${IGN_ORG} "Migrate CMake files" + gitCommit -a ${IGN_ORG} "Migrate CMake files" gitPushAndPR ${IGN_ORG} main "${PR_TITLE} : ${LIB}" ${PR_TEXT} done From 8a793c1fc162aa4feadc2dce353770726ea1757e Mon Sep 17 00:00:00 2001 From: methylDragon Date: Thu, 28 Apr 2022 00:45:26 -0700 Subject: [PATCH 16/21] Fix top level CMakeLists generation Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index 35df8da0b..b7e0ec597 100755 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -491,7 +491,11 @@ for ((i = 0; i < "${#LIBRARIES[@]}"; i++)); do echo "install(DIRECTORY ignition DESTINATION \${IGN_INCLUDE_INSTALL_DIR_FULL})" >> ./include/CMakeLists.txt # Edit top level CMakeLists - sed -i 's@ign_configure_project(\(.*\))@ign_configure_project(\n REPLACE_IGNITION_INCLUDE_PATH gz/utils\n \1)@g' CMakeLists.txt + OFS=$IFS; IFS=" " + LIB_NAME_ARR=(${LIB/-/ }) + echo "CREATING TOP LEVEL CMAKELISTS FOR $LIB: ${LIB_NAME_ARR[1]}" + sed -i "s@ign_configure_project(\(.*\))@ign_configure_project(\n REPLACE_IGNITION_INCLUDE_PATH gz/${LIB_NAME_ARR[1]}\n \1)@g" CMakeLists.txt + IFS=$OFS reviewConfirm gitCommit -a ${IGN_ORG} "Migrate CMake files" From 895cfe20c9487cac0e128b62e30db3b4fa5c043e Mon Sep 17 00:00:00 2001 From: methylDragon Date: Thu, 28 Apr 2022 15:16:50 -0700 Subject: [PATCH 17/21] Fix regex Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index b7e0ec597..4e0fde5ee 100755 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -349,7 +349,7 @@ migrateSources() { # Different variations of ignition/ign -> gz in source files # Only migrate non-macro definition calls (loop to make it recursive) # \([^(]*\)\ to ignore any macros with arguments (to target header guards only) # _H to target (mostly) header guards (might miss improperly defined header guards) - sed -i ':loop s@\(#.*\) IGN\(ITION\)\?\(.*\)_H\([^(]*\)$@\1 GZ\3_H\4@g; t loop' $1 # e.g. IGNITION_UTILS__XXX -> GZ_UTILS__XXX + sed -i ':loop s@\(#.*\)\([ _]\)IGN\(ITION\)\?\(.*\)_H\([^(]*\)$@\1\2GZ\4_H\5@g; t loop' $1 # e.g. IGNITION_UTILS__XXX -> GZ_UTILS__XXX fi # NOTE(CH3): We're not migrating class or variable names for now From cc67a0b0449189078bfeecf0199a29b328461477 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Fri, 29 Apr 2022 16:02:44 -0700 Subject: [PATCH 18/21] Use set -e Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index 4e0fde5ee..9f4258f35 100755 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -43,6 +43,7 @@ # # Author: methylDragon +set -e # USER PARAMS ====================================================================================== LIBRARY_INPUT=${1} From 17c1551f5e9681c0bc2899aad03bff9d78dedb7f Mon Sep 17 00:00:00 2001 From: methylDragon Date: Fri, 29 Apr 2022 16:32:18 -0700 Subject: [PATCH 19/21] Refine regex Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index 9f4258f35..f504853f7 100755 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -380,7 +380,7 @@ migrateCmake() { # Different variations of ignition/ign -> gz in CMake files sed -i 's@(ign\(ition\)\?@(gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) sed -i 's@Ign\(ition\)\?\([A-Z]\)@Gz\2@g' $1 # e.g. IgnitionFormatter -> GzFormatter - sed -i 's@(\(.*\)ign\(ition\)\?@(\1gz@g' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) + sed -i ':loop s@(\(\(.*_\)*\)ign\(ition\)\?@(\1gz@g; t loop' $1 # e.g. add_subdirectory(ignition) -> add_subdirectory(gz) # NOTE(CH3): # ^\([^ign ]\+\) ignores lines that start with ign(nition)_ From 7b17e475504d5ad308b943e3e5f848577b65d2de Mon Sep 17 00:00:00 2001 From: methylDragon Date: Wed, 4 May 2022 15:19:39 -0700 Subject: [PATCH 20/21] Don't ticktock detail headers Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index f504853f7..1aef41157 100755 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -332,7 +332,10 @@ mvHeaders() { # Leave redirection aliases # Converting *.in into normal versions (spoofing configuration of *.in files) - if [[ $1 =~ [Ii]gn(ition)?.*\.in ]] ; then + if [[ $1 =~ [Ii]gn(ition)?(.*)?/detail/.* ]] ; then + echo "[REMOVING] $1" + rm $1 + elif [[ $1 =~ [Ii]gn(ition)?.*\.in ]] ; then echo "[CONVERTING] $1" echo $1 | sed 's@\(.*\)\.in@\1@g' | xargs -I {} mv $1 {} fi From e7e1fcd8ae029fe27518ad967fa4f8937236655f Mon Sep 17 00:00:00 2001 From: methylDragon Date: Fri, 6 May 2022 13:29:04 -0700 Subject: [PATCH 21/21] Change ign org to gz Signed-off-by: methylDragon --- jenkins-scripts/tools/header_migration_script.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jenkins-scripts/tools/header_migration_script.sh b/jenkins-scripts/tools/header_migration_script.sh index 1aef41157..5673eeb6e 100755 --- a/jenkins-scripts/tools/header_migration_script.sh +++ b/jenkins-scripts/tools/header_migration_script.sh @@ -84,7 +84,7 @@ WHITE_BG="\e[107m" BLUE_BG="\e[44m" GREEN_BG="\e[42m" -IGN_ORG="ignitionrobotics" +GZ_ORG="gazebosim" TOOLING_ORG="ignition-tooling" DEFAULT_COMMIT_MSG="DEFAULT_COMMIT_MSG" # Bumps in ${COLLECTION}" @@ -425,7 +425,7 @@ read -a LIBRARIES <<< "${LIBRARY_INPUT}" for ((i = 0; i < "${#LIBRARIES[@]}"; i++)); do LIB=${LIBRARIES[$i]} - cloneIfNeeded ${IGN_ORG} ${LIB} + cloneIfNeeded ${GZ_ORG} ${LIB} startFromCleanBranch header_migration main echo -e "${GREEN}\n[STARTING MIGRATION] ${LIB}${DEFAULT}" @@ -439,9 +439,9 @@ for ((i = 0; i < "${#LIBRARIES[@]}"; i++)); do find . -regex ".*/include.*/ignition.*/.*\.in" -type f -print0 | xargs -0 -I {} rm {} # Remove dangling ignition CMakeLists reviewConfirm - gitCommit -s ${IGN_ORG} "Move header files with git mv" # Commits staged git mv changes + gitCommit -s ${GZ_ORG} "Move header files with git mv" # Commits staged git mv changes echo -e "\n== Copying Redirection Aliases ==\n" - gitCommit -f -a ${IGN_ORG} "Create redirection aliases" # Adds and commits unstaged redirections + gitCommit -f -a ${GZ_ORG} "Create redirection aliases" # Adds and commits unstaged redirections # Create Export.hh and .hh find . -regex './include.*/ignition/[^/]*' -type d -print0 \ @@ -475,7 +475,7 @@ for ((i = 0; i < "${#LIBRARIES[@]}"; i++)); do git apply <<< "${PATCHED_GIT_DIFF}" reviewConfirm - gitCommit -f -a -e ${IGN_ORG} + gitCommit -f -a -e ${GZ_ORG} # Migrate Gz sources find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/\([^/]*_\)?[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _ @@ -484,7 +484,7 @@ for ((i = 0; i < "${#LIBRARIES[@]}"; i++)); do find . -regex '.*/examples/.*\|.*include\(.*\)*/.*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _ reviewConfirm - gitCommit ${IGN_ORG} "Migrate sources in src, test, examples, and include" + gitCommit ${GZ_ORG} "Migrate sources in src, test, examples, and include" # Migrate Gz CMake files find . -regex '.*[include\|src\|test\|examples].*/CMakeLists\.txt' -type f -print0 | xargs -0 -I {} bash -c 'migrateCmake {}' _ @@ -502,6 +502,6 @@ for ((i = 0; i < "${#LIBRARIES[@]}"; i++)); do IFS=$OFS reviewConfirm - gitCommit -a ${IGN_ORG} "Migrate CMake files" - gitPushAndPR ${IGN_ORG} main "${PR_TITLE} : ${LIB}" ${PR_TEXT} + gitCommit -a ${GZ_ORG} "Migrate CMake files" + gitPushAndPR ${GZ_ORG} main "${PR_TITLE} : ${LIB}" ${PR_TEXT} done