Skip to content

Commit

Permalink
pull git commands to own helper file, add staging/stashing of our cha…
Browse files Browse the repository at this point in the history
…nges/patches to be able to visualize new changes made easier.
  • Loading branch information
mitchcapper committed Aug 22, 2023
1 parent 9cb7e32 commit 6efd872
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 49 deletions.
10 changes: 7 additions & 3 deletions default_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ CONFIG_NO_TESTS=1
CONFIG_NO_PO=1
CONFIG_NO_DOCS=1

GIT_SETTINGS_DEFAULT=( "core.autocrlf false" "core.fileMode false" "core.eol lf" "diff.ignoreAllSpace true" "apply.ignoreWhitespace change" "apply.whitespace fix" )
GIT_SETTINGS_DEFAULT=( "core.autocrlf false" "user.email [email protected]" "user.name YourNamee" "core.fileMode false" "core.eol lf" "diff.ignoreAllSpace true" "apply.ignoreWhitespace change" "apply.whitespace fix" )
GIT_SETTINGS_ADDL=() #
GIT_IGNORE_DEFAULT=("*.exe" "*.ilk" "*.obj" "*.log" "*.Plo" "*.pdb" "*.idb" "*.zip" "*.tmp" "*.o" ".deps" "*.a" "final" "proj_config.ini" "*~" "*confest*" "_configure" )
GIT_IGNORE_ADDL=()
GIT_PATCH_APPLY_DEFAULT_ARGS=("--whitespace=nowarn" "--ignore-space-change" "--ignore-whitespace")
GIT_STASH_STAGE_AROUND_PATCHES=1 # to make it easier to tell what code you have changed vs what code we patch/change with the build script we can try to stage all of the changes we make using git. This way any untracked changes are the changes you made. In general this works without error always on first builds. To re-apply patches though we have to do some stashing of changes in different ways to discard the old applied patch changes before applying them again. We try to stash user changes separately and backup everything to tmp files (see output for what tmp files for a specific run) so it should be hard to lose your changes. It is more likely a conflict of some sort will occur though so this can break. There are also a few scripts where we need to commit a fake commit to git to store some changes we made to get this to work. If you disable this then it will just apply patches without any staging, which may make it harder to see changes you made.
GIT_STASH_STAGE_DEBUG=0 #given the above is fragile this will output debug messages if it is breaking to help determine what went wrong

ADD_WIN_ARGV_LIB=1 #should windows expand wildcard command line args, most of hte time we want this, something like find -name "*.c" we don't want it on

Expand All @@ -49,11 +52,12 @@ GNU_LIBS_BRANCH=master #leave blank to use whatever version the app checks out
GNU_LIBS_BUILD_AUX_ONLY_USED=0
#symlink gets us unistd and lstat, lstat gets us stat, stat gets us sys_stat and filename
GNU_LIBS_DEFAULT=( "sigpipe" "sigaction" "spawn-pipe" "strtok_r" "waitpid" "windows-stat-inodes" "windows-stat-timespec" "execute" "poll" "symlink" "symlinkat" "readlink" "readlinkat" "link" "fchmodat" "unlink" "unlinkat" "fsync" "open" )
BUNDLE_PATH=[BASE_FOLDER]/gnulib.bundle # if this file exists use it as a bootstrapping bundle when cloning
GNU_LIBS_ADDL=()
GNU_LIBS_EXCLUDE= ()
GNU_LIBS_USE_GNULIB_TOOL_PY=1
GNU_LIBS_USE_GNULIB_TOOL_PY_ADDL_MK_FILES_FIX=()
GNU_LIBS_PATCHES_DEFAULT=( "NOOP_FOR_WINDOWS_CHOWN_CHMOD_GETUSER_GETGROUP" "GNULIB_TOOL_APPLY_PATCHES_BY_FILE" "FTS_MINOR_FIXES" "BUILD_AUX_HANDLE_DOT_A_LIBS" "FIX_SYSSTAT_TIMESPEC_DISABLE_BUG" "WIN_FSUSAGE_FIXES" "WINDOWS_SYMLINK_SUPPORT" "SPAWN_PIPE_FORK_FD_FIXES" "WINDOW_PATH_FIXES" "PHYSMEM_TEST_MAIN_RENAME" )
GNU_LIBS_PATCHES_DEFAULT=( "NOOP_FOR_WINDOWS_CHOWN_CHMOD_GETUSER_GETGROUP" "GNULIB_TOOL_APPLY_PATCHES_BY_FILE" "FTS_MINOR_FIXES" "BUILD_AUX_HANDLE_DOT_A_LIBS" "FIX_SYSSTAT_TIMESPEC_DISABLE_BUG" "WIN_FSUSAGE_FIXES" "WINDOWS_SYMLINK_SUPPORT" "SPAWN_PIPE_FORK_FD_FIXES" "WINDOW_PATH_FIXES" "PHYSMEM_TEST_MAIN_RENAME" "WIN32_POLL_FIXES" "MSVC_PARAMETER_HANDLER_M4_MACRO_FIX" )
GNU_LIBS_PATCHES_ADDL=()

VCPKG_DIR=[BASE_FOLDER]/vcpkg
Expand All @@ -76,7 +80,7 @@ LOG_MAKE_CMD_FILE="[BASE_FOLDER]/[BUILD_FOLDER_NAME]-make.log" #must call log_ma
LOG_CONFIG_ENV_FILE="[BASE_FOLDER]/[BUILD_FOLDER_NAME]-env.log"
LOG_CONFIGURE_FILE="[BASE_FOLDER]/[BUILD_FOLDER_NAME]-configure.log"
LOG_RAW_BUILD_FILE="[BASE_FOLDER]/[BUILD_FOLDER_NAME]-build.bat" #if used with the "log_raw_build" or "log_raw_build_full" all the actual commands output to cl.exe or lib.exe although need to add link.exe you can also use log_true_make_full to run all the commands up to true make and stop at that point
LOG_RAW_BUILD_FILE_POST_PROCESS=1 # This will call the dotnet bat_cleanup.csx script after generating the bat file. It fixes any msys only paths into windows compat paths, it will also try to extract out long repeating strings into bat variables. See the comments at the top of the file for more details.
LOG_RAW_BUILD_FILE_POST_PROCESS=1 # This will call the dotnet bat_cleanup.csx script after generating the bat file. It fixes any msys only paths into windows compat paths, it will also try to extract out long repeating strings into bat variables. See the comments at the top of the file for more details., note not currently actually enabled.

LOG_EXPAND_VARS=0 #This is a safeish way to expand the variables in commands but it is pretty slow, also note expanding the command manually is not error proof, any bash vars declared local won't be avail, and if there is a global var with the same name it will appear instead. This is for the LOG_FILE file.
LOG_FILE_AUTOTAIL=0
Expand Down
111 changes: 76 additions & 35 deletions helpers.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eo pipefail -o functrace

shopt -s inherit_errexit
#while we could export SHELLOPTS many scripts dont work well with pipefail enabled

Expand All @@ -9,6 +9,7 @@ declare -g SCRIPT_FOLDER="${WLB_SCRIPT_FOLDER:-$(dirname "$(CALL_SCRIPT_PATH)")}
declare -g LOG_MAKE_RUN=""
declare -g LOG_MAKE_CONTINUE=0


function usage(){
load_colors;
declare -A cmds=(
Expand Down Expand Up @@ -48,6 +49,8 @@ function usage(){
case "$SKIP_STEP" in
log_raw_build|log)
LOG_MAKE_RUN="raw"
SKIP_STEP=""
LOG_MAKE_CONTINUE=1
;;
log_raw_build_full|log_full)
LOG_MAKE_RUN="raw"
Expand All @@ -56,14 +59,14 @@ case "$SKIP_STEP" in
;;
log_make)
LOG_MAKE_RUN="make"
SKIP_STEP=""
;;
log_make_full)
LOG_MAKE_RUN="make"
SKIP_STEP="$2"
;;
esac


#if a env variable is completely undefined our changes wont be picked up unless past directly to the command or exported

pkg_config_manual_add(){
Expand Down Expand Up @@ -107,16 +110,62 @@ apply_our_repo_patch () {
local PATCH_NAME="${1:-$BLD_CONFIG_BUILD_NAME}"
PATCH_PATH="${WIN_SCRIPT_FOLDER}/patches/repo_${PATCH_NAME}.patch"
if [[ -f "${PATCH_PATH}" ]]; then
git_stash_cur_work_discard_staged_work
git_apply_patch "${PATCH_PATH}"
git_stash_stage_patches_and_restore_cur_work
else
echo "Error apply_our_repo_patch called but can't find patch at: ${PATCH_PATH}" 1>&2;
exit 1
fi
}
git_apply_patch () {
local PATCH=$1
ex git apply --ignore-space-change --ignore-whitespace "$PATCH"

osfixes_set_locations_dbg_add_to_libs(){
osfixes_set_locations "$@"
if [[ ! $BLD_CONFIG_BUILD_DEBUG ]]; then
return;
fi
LDFLAGS+=" -Xlinker $OSFIXES_LIB"
}
osfixes_bare_compile(){
cd $OSFIXES_SRC_DST_FLDR
ex cl.exe -D_DEBUG -DDEBUG /nologo /c /ZI /MTd -DWLB_DISABLE_DEBUG_ASSERT_POPUP_AT_LAUNCH "$OSFIXES_SRC_DST"
#ex lib.exe /nologo "${OSFIXES_SRC_DST::-1}obj" want to do obj to make sure it is always incldued
cd $BLD_CONFIG_SRC_FOLDER
}
osfixes_set_locations(){
declare -g OSFIXES_HEADER_DST="$BLD_CONFIG_SRC_FOLDER"
declare -g OSFIXES_SRC_DST_FLDR="$BLD_CONFIG_SRC_FOLDER"
if [[ "$#" -gt 0 ]]; then
OSFIXES_HEADER_DST="$1"
if [[ "$#" -gt 1 ]]; then
OSFIXES_SRC_DST_FLDR="$2"
fi
fi
declare -g OSFIXES_SRC_DST="${OSFIXES_SRC_DST_FLDR}/osfixes.c"
OSFIXES_HEADER_DST+="/osfixes.h"
#declare -g OSFIXES_LIB="${OSFIXES_SRC_DST::-1}lib"
declare -g OSFIXES_LIB="${OSFIXES_SRC_DST::-1}obj"

}

osfixes_link_in_if_dbg_and_stg() {
if [[ ! $BLD_CONFIG_BUILD_DEBUG ]]; then
return;
fi
osfixes_link_in_if_needed;
git_staging_add "$OSFIXES_SRC_DST" "$OSFIXES_HEADER_DST"
}
# first arg is header folder, second arg is c file folder
osfixes_link_in_if_needed() {

if [[ ! -e "${OSFIXES_SRC_DST}" ]]; then
ln -s "${WLB_SCRIPT_FOLDER}/osfixes.c" "${OSFIXES_SRC_DST}"
fi
if [[ ! -e "${OSFIXES_HEADER_DST}" ]]; then
ln -s "${WLB_SCRIPT_FOLDER}/osfixes.h" "${OSFIXES_HEADER_DST}"
fi
}

convert_to_msys_path () {
local WPATH=$1
WPATH=`cygpath -u "$WPATH"`
Expand Down Expand Up @@ -203,11 +252,20 @@ function run_logged_make(){
exit 0
fi
}

function configure_run(){
setup_build_env;
#gl_cv_host_operating_system="MSYS2" ac_cv_host="x86_64-w64-msys2" ac_cv_build="x86_64-w64-msys2"
ex ./configure "${FULL_CONFIG_CMD_ARR[@]}" > >(tee "${BLD_CONFIG_LOG_CONFIGURE_FILE}");
}
function use_custom_make_and_gsh(){
BLD_CONFIG_BUILD_MAKE_BIN="gnumake.exe"
MAKESHELL="gsh.exe"
DEFAULTMAKESHELL="$MAKESHELL"
NOMAKESHELLS="/bin/sh"

export MAKESHELL DEFAULTMAKESHELL NOMAKESHELLS
}
declare -g SETUP_BUILD_ENV_RUN=0

#sometimes we may update a command args from taking a users string to taking an array to fix escape issues, rather than require all scripts update right away we can use this to convert
Expand Down Expand Up @@ -287,7 +345,8 @@ function setup_build_env(){
ADL_LIB_FLAGS+=" /DLL"
fi
if [[ $BLD_CONFIG_BUILD_DEBUG -eq 1 ]]; then
ADL_C_FLAGS+=" /D_DEBUG ${BLD_CONFIG_BUILD_DEBUG_ADDL_CFLAGS} ${BLD_CONFIG_BUILD_MSVC_CL_DEBUG_OPTS}"
#the xlinker debug here is mostly needed for libtool which wont recognize it otherwise
ADL_C_FLAGS+=" /D_DEBUG ${BLD_CONFIG_BUILD_DEBUG_ADDL_CFLAGS} ${BLD_CONFIG_BUILD_MSVC_CL_DEBUG_OPTS} ${XLINKER_CMD} /DEBUG ${XLINKER_CMD} -ZI ${XLINKER_CMD} -Zf ${XLINKER_CMD} -FS"
ADL_LIB_FLAGS+=" /DEBUG"
if [[ "$BUILD_MSVC_NO_DEFAULT_LIB" == "debug" ]]; then
NO_DEFAULT_LIB_ARR+=($MSVC_DESIRED_LIB)
Expand Down Expand Up @@ -390,29 +449,15 @@ function configure_fixes(){


}
function git_settings_to_env(){
declare -a GIT_SETTINGS=("${BLD_CONFIG_GIT_SETTINGS_DEFAULT[@]}")
if [[ ${#BLD_CONFIG_GIT_SETTINGS_ADDL[@]} > 0 ]]; then
GIT_SETTINGS+=("${BLD_CONFIG_GIT_SETTINGS_ADDL[@]}")
fi
GIT_SETTING_COUNT=${#GIT_SETTINGS[@]}
GIT_CONFIG_COUNT=0

for (( j=0; j<${GIT_SETTING_COUNT}; j++ )); do
SETTING="${GIT_SETTINGS[$j]}"
IFS=' ' read -ra KVP <<< "$SETTING"
NAME="${KVP[0]}"
VALUE="${KVP[1]}"
if [[ $name -eq "" ]]; then
continue;
fi

export GIT_CONFIG_KEY_${GIT_CONFIG_COUNT}="$NAME"
export GIT_CONFIG_VALUE_${GIT_CONFIG_COUNT}="$VALUE"
(( GIT_CONFIG_COUNT++ ))
done
export GIT_CONFIG_COUNT
function load_colors(){
COLOR_MINOR="${COLOR_MINOR:-\e[2;33m}"
COLOR_MINOR2="${COLOR_MINOR2:-\e[2;36m}"
COLOR_MAJOR="${COLOR_MAJOR:-\e[1;32m}"
COLOR_ERROR="${COLOR_ERROR:-\e[1;31m}"
COLOR_NONE="${COLOR_NONE:-\e[0m}"
}

function startcommon(){
# need to do these early before everything else

Expand All @@ -424,11 +469,7 @@ function startcommon(){
mkdir -p "$BLD_CONFIG_SRC_FOLDER"
cd "$BLD_CONFIG_SRC_FOLDER"
if [[ $BLD_CONFIG_LOG_COLOR_HIGHLIGHT ]]; then
COLOR_MINOR="${COLOR_MINOR:-\e[2;33m}"
COLOR_MINOR2="${COLOR_MINOR2:-\e[2;36m}"
COLOR_MAJOR="${COLOR_MAJOR:-\e[1;32m}"
COLOR_ERROR="${COLOR_ERROR:-\e[1;31m}"
COLOR_NONE="${COLOR_NONE:-\e[0m}"
load_colors;
else
COLOR_MINOR=""
COLOR_MINOR2=""
Expand Down Expand Up @@ -471,8 +512,8 @@ function finalcommon(){
if [[ "${LOG_MAKE_RUN}" -eq "raw" && -e "${BLD_CONFIG_LOG_RAW_BUILD_FILE}" ]]; then
BUILD_OUT="$BLD_CONFIG_INSTALL_FOLDER/build"
mkdir -p "$BUILD_OUT"
cp -t "$BUILD_OUT" "${BLD_CONFIG_LOG_RAW_BUILD_FILE}" "${BLD_CONFIG_LOG_CONFIG_ENV_FILE}" &>/dev/null || true
CFG_PATHS=("config.h" "lib/config.h" "gnulib/config.h" "gl/config.h" "include/config.h")
cp -t "$BUILD_OUT" "${BLD_CONFIG_LOG_RAW_BUILD_FILE}" "${BLD_CONFIG_LOG_FILE}" &>/dev/null || true
CFG_PATHS=("config.h" "lib/config.h" "gnulib/config.h" "gl/config.h" "include/config.h" "${BLD_CONFIG_LOG_CONFIG_ENV_FILE}" "config.cache" "config.log" "${BLD_CONFIG_LOG_CONFIGURE_FILE}")
for path in "${CFG_PATHS[@]}"; do
if [[ -e "$path" ]]; then
cp "$path" "$BUILD_OUT"
Expand All @@ -483,7 +524,7 @@ function finalcommon(){
trace_final;
return 0;
}

. "$SCRIPT_FOLDER/helpers_git.sh"
. "$SCRIPT_FOLDER/helpers_ini.sh"
. "$SCRIPT_FOLDER/helpers_gnu.sh"
. "$SCRIPT_FOLDER/helpers_vcpkg.sh"
Expand Down
Loading

0 comments on commit 6efd872

Please sign in to comment.