diff --git a/scripts/linux-build.sh b/scripts/linux-build.sh index 55b03dd14..35aebc102 100755 --- a/scripts/linux-build.sh +++ b/scripts/linux-build.sh @@ -41,18 +41,11 @@ SCRIPT=`basename "$0"` SCRIPTDIR=`dirname "$0"` cd "$SCRIPTDIR/.." -# Main repository location, as an absolute path. +# Main repository location and Working Directory, as an absolute path. TOPDIR=`pwd` +WORKING_DIR=`cd TOPDIR/..` cd "$TOPDIR" -# TODO: These variables below should be called from the GitHub actions -# environment. Then change this to an if statement incase those environment -# variables are not set. - -# This script pulls down and maintains a clone of the mypaint project so I need -# to keep track of the root directory of the project. This will be using ubuntu -# image from github actions and the root directory will be /home/work/mypaint/. - # Gather revelant information of the project and where it was cloned. SRC_REMOTE_URL="$(git config --get remote.origin.url)" SRC_REMOTE_USRNAME="$(echo $SRC_REMOTE_URL | awk -F[:/.] '{print $6}')" @@ -60,21 +53,7 @@ SRC_REMOTE_PROJECT_NAME="$(echo $SRC_REMOTE_URL | awk -F[:/.] '{print $7}')" SRC_SITE="$(git config --get remote.origin.url | sed -nE 's#(https://[^/]*)/.*#\1#p')" SRC_UPSTREAM_URL="$SRC_SITE/$SRC_REMOTE_PROJECT_NAME/$SRC_REMOTE_PROJECT_NAME.git" SRC_BRANCH=$(git rev-parse --abbrev-ref HEAD) - -# Need to make the script for package management flexible so that it can be used -# on other systems. Need to make running sudo optional as well. - -PKG_MANAGER="apt-get" -UPDATE_CMD="sudo $PKG_MANAGER update" -UPGRADE_CMD="sudo $PKG_MANAGER upgrade" -INSTALL_CMD="sudo $PKG_MANAGER install -y" -REMOVE_CMD="sudo $PKG_MANAGER remove -y" - -# Set a package dependency list incase other OS's are used. - -DEP_LIST="g++ gettext intltool gir1.2-gtk-3.0 libgtk-3-dev libjson-c-dev \ - liblcms2-dev libpng-dev python3-dev python-gi-dev python3-gi-cairo \ - python3-nose python3-numpy python3-setuptools swig git" +DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | rev | cut -d'/' -f1 | rev) # These are just here to make the output of the script more readable in the logs. @@ -102,6 +81,27 @@ lognote() { echo -e "${NC}" } +# TODO: These variables below should be called from the GitHub actions +# environment. Then change this to an if statement incase those environment +# variables are not set. + +# Need to make the script for package management flexible so that it can be used +# on other systems. Need to make running sudo optional as well. + +PKG_MANAGER="apt-get" +UPDATE_CMD="sudo $PKG_MANAGER update" +UPGRADE_CMD="sudo $PKG_MANAGER upgrade" +INSTALL_CMD="sudo $PKG_MANAGER install -y" +REMOVE_CMD="sudo $PKG_MANAGER remove -y" + +# Set a package dependency list incase other OS's are used. + +DEP_LIST="g++ gettext intltool gir1.2-gtk-3.0 libgtk-3-dev libjson-c-dev \ + liblcms2-dev libpng-dev python3-dev python-gi-dev python3-gi-cairo \ + python3-nose python3-numpy python3-setuptools swig git" + + + # This function will be used to update the environment and upgrade the packages prepare_enviroment(){ @@ -127,63 +127,73 @@ install_dependencies() { logok "Pixbuf query loaders cache updated" } -# The use_correct_branch() fuction will check the upstream remote repository for the correct branch and -# if it exists it will use the same branch. If it does not exist it will use -# the main branch. This will most likely be called from the install_from_source() -# function. +# This function will select the correct fork of the source package and pass it to $SOURCEPKG_URL. +use_correct_fork(){ + if [ -z "$1" ]; then + logerror "No argument passed to use_correct_fork()" + exit 1 + fi + SOURCEPKG="$1" + loginfo "Checking to see if $SRC_REMOTE_USERNAME has $SOURCEPKG in their Repositories" + SOURCEPKG_URL="$SRC_SITE/$SRC_REMOTE_USRNAME/$SOURCEPKG.git" + if ! git ls-remote --heads $SOURCEPKG_URL; then + lognote "No fork found for $SOURCEPKG. Using upstream source" + $SOURCEPKG_URL="$SRC_SITE/$SRC_REMOTE_PROJECT_NAME/$SOURCEPKG.git" + if ! git ls-remote --heads $SOURCEPKG_URL; then + logerror "No upstream source for $SOURCEPKG exits" + exit 1 + fi + fi + loginfo "The Correct source for $SOURCEPKG is $SOURCEPKG_URL." +} +# This function will select the correct branch of the source package and pass it to $SOURCEPKG_BRANCH. use_correct_branch(){ - # Set the branch name - SRC_BRANCH=$(git rev-parse --abbrev-ref HEAD) - - loginfo "$SOURCEPKG is on branch $SRC_BRANCH" - - # Check if the branch exists in the mypaint repository - git ls-remote --heads https://github.com/owner1/repo1.git $branch | grep -q refs/heads/$branch - if [ $? -eq 0 ]; then - branch=$branch + if [ -z "$1" ]; then + logerror "No argument passed to use_correct_branch()" + exit 1 + fi + SOURCEPKG="$1" + loginfo "Checking to see if $SRC_BRANCH exists in $SOURCEPKG git repository" + if ! git ls-remote --heads $SOURCEPKG_URL $SRC_BRANCH; then + lognote "No branch found for $SOURCEPKG. Using $DEFAULT_BRANCH branch" + SOURCEPKG_BRANCH="$DEFAULT_BRANCH" else - branch="main" + SOURCEPKG_BRANCH="$SRC_BRANCH" fi - # Checkout the branches - git clone --branch $branch1 https://github.com/owner1/repo1.git repo1 + loginfo " USING $SOURCEPKG_BRANCH branch for $SOURCEPKG" } -# This function will be used to install the dependencies from source. Need to -# make it modular so that it can be used for other enviroment or when we change -# build procces. - +# This function will be used to install the source package from the source. Needs +# use_correct_fork() and use_correct_branch() to work properly. install_from_source(){ - SOURCEPKG="$1" - INSTALL="$2" - SOURCEPKG_URI="$SRC_SITE/$SRC_REMOTE_USRNAME/$SOURCEPKG" - loginfo "Cloning $SOURCEPKG Repository" - cd $TOPDIR - # Check to see if the user has forked the repository. If not use upstream. - if ! git clone --verbose $SOURCEPKG_URI; then - lognote "User has no fork of $SOURCEPKG. Using upstream source" - if ! git clone --verbose $SRC_SITE/$SRC_REMOTE_PROJECT_NAME/$SOURCEPKG.git; then - logerror "Failed to clone $SOURCEPKG" - exit 1 - fi - fi - pushd "$SOURCEPKG" - # TODO: Make this bit of code into it's own function. - loginfo "Building $SOURCEPKG" - ./autogen.sh - ./configure --prefix=/usr - make - if $INSTALL; then - loginfo "Installing $SOURCEPKG into Enviroment" - sudo make install - logok "Install finished" - fi - popd - # This should stay instead of deleting the source package. - # At least for testing. - loginfo "Removing $SOURCEPKG" Source from Environment - sudo rm -v -fr $SOURCEPKG + SOURCEPKG="$1" + INSTALL="$2" + cd $WORKING_DIR + use_correct_fork $SOURCEPKG + use_correct_branch $SOURCEPKG + loginfo "Cloning the correct $SOURCEPKG Repository" + if ! git clone --depth 1 --branch $SOURCEPKG_BRANCH $SOURCEPKG_URL; then + logerror "Failed to clone $SOURCEPKG" + exit 1 + fi + pushd "$SOURCEPKG" + # TODO: Make this bit of script into it's own function. + loginfo "Building $SOURCEPKG" + ./autogen.sh + ./configure --prefix=/usr + make + if $INSTALL; then + loginfo "Installing $SOURCEPKG into Enviroment" + sudo make install + logok "Install finished" + fi + popd + # This should stay instead of deleting the source package. + # At least for testing. + loginfo "Removing $SOURCEPKG" Source from Environment + sudo rm -v -fr $SOURCEPKG } build_for_testing() {