blob: d3148b8d9ec515c3f5508b5dc9d3ec578ada11b6 [file] [log] [blame]
#!/usr/bin/env bash
#*******************************************************************************
# Copyright (c) 2016 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# David Williams - initial API and implementation
#*******************************************************************************
# boot strap basic variable values, to drive Eclipse Platform builds.
# We set RAWDATE first thing, just to make it more accurate of the "start of the build".
# We have found on Hudson (but never by cron jobs) that by the time the build starts, it is often already 1 minute
# past the time we scheduled. This may eventually be fixed (or improved) in Hudson (see bug 496403).
# Initially we tried heuristic of deducting 60 seconds (bug 496345) but occasionally Hudson would start the job in, say 51 seconds, making
# our build ID a minute less that it should be. Then we tried 30 seconds (bug 500233), but given a look at the long term history
# of Hudson "start" times, it seems 30 seconds may fail at times too.
# So modified to truncate "epoch seconds" to the nearest 5 minutes since in our production builds we always schedule them
# to start at "even" times, such as "on the hour", occasionally "on the half hour", and rarely on "quarter hours" and maybe once at 10 after. :)
# So as long as schedule as it currently is, it seems truncating to nearest 5 minutes will always work. We have seen Hudson "delay times" range from
# about 20 seconds to at most about 2 minutes, but never any near 5 minutes so that shouldn't be a concern,
# unless Hudson delays start to get really long (over 5 minutes) for some reason.
if [[ -z "${RAWDATE}" ]]
then
RAWDATE=$( date +%s )
remainder=$(( RAWDATE % 300 ))
RAWDATE=$((RAWDATE - remainder))
export RAWDATE
echo -e "\n\t[DEBUG] RAWDATE in ${0##*/} was empty (as expected) so setting to \"now minus $remainder\" (truncating to nearest 5 minutes): ${RAWDATE}\n"
else
echo -e "\n\t[DEBUG] RAWDATE in ${0##*/} was already set. RAWDATE: ${RAWDATE}\n"
fi
if [[ -z "${SCRIPT_PATH}" ]]
then
echo -e "\n\t[ERROR] SCRIPT_PATH is not defined as expected in ${0##*/}"
exit 1
else
echo -e "\n\t[INFO] SCRIPT_PATH defined as ${SCRIPT_PATH}"
fi
source "${SCRIPT_PATH}/bashUtilities.shsource"
# USAGE: fn-git-cache BUILD_ROOT
# ROOT: /shared/eclipse/builds/${major}${type}
fn-git-cache ()
{
# we (now) leave branch our of git-cache path, or else "topic branches", such as
# 'david_williams/II20130409-0900' complicates directory structure
checkNArgs $# 1
if [[ $? != 0 ]]; then return 1; fi
ROOT="$1"; shift
echo $ROOT/gitCache
}
# USAGE: fn-git-dir GIT_CACHE URL
# GIT_CACHE: /shared/eclipse/builds/R4_2_maintenance/gitCache
# URL: file:///gitroot/platform/eclipse.platform.releng.aggregator.git
fn-git-dir ()
{
checkNArgs $# 2
if [[ $? != 0 ]]; then return 1; fi
GIT_CACHE="$1"; shift
URL="$1"; shift
echo $GIT_CACHE/$( basename "$URL" .git )
}
# USAGE: fn-build-id BUILD_TYPE
# BUILD_TYPE: I, M, N, X, Y, P, U
fn-build-id ()
{
checkNArgs $# 1
if [[ $? != 0 ]]; then return 1; fi
BUILD_TYPE="$1"; shift
TIMESTAMP=$( date +%Y%m%d-%H%M --date='@'$RAWDATE )
echo ${BUILD_TYPE}${TIMESTAMP}
}
# USAGE: fn-build-dir ROOT BUILD_ID STREAM
# ROOT: /shared/eclipse/builds
# BUILD_ID: M20121119-1900
# STREAM: 4.3.0
fn-build-dir ()
{
checkNArgs $# 3
if [[ $? != 0 ]]; then return 1; fi
ROOT="$1"; shift
BUILD_ID="$1"; shift
STREAM="$1"; shift
eclipseStreamMajor=${STREAM:0:1}
dropDirSegment=siteDir/eclipse/downloads/drops
if (( $eclipseStreamMajor > 3 ))
then
dropDirSegment=siteDir/eclipse/downloads/drops4
fi
echo $ROOT/$dropDirSegment/$BUILD_ID
}
# if not defined "externally", then something is wrong
# with our assumptions and we should simply fail here.
# If the definition ever needs to be put back here, then
# see bootstrap.shsource for how REPO_AND_ACESS is defined.
assertNotEmpty REPO_AND_ACCESS
if [[ -z "${AGGREGATOR_REPO}" ]]
then
export AGGREGATOR_REPO=${REPO_AND_ACCESS}/platform/eclipse.platform.releng.aggregator.git
fi
assertNotEmpty BUILD_ROOT
assertNotEmpty AGGREGATOR_REPO
assertNotEmpty BUILD_TYPE
assertNotEmpty STREAM
if [[ -z "${gitCache}" ]]
then
gitCache=$( fn-git-cache "${BUILD_ROOT}" )
assertNotEmpty gitCache
export gitCache
else
echo "gitCache was already defined as $gitCache"
fi
if [[ -z "${aggDir}" ]]
then
aggDir=$( fn-git-dir "$gitCache" "$AGGREGATOR_REPO" )
assertNotEmpty aggDir
export aggDir
else
echo "aggDir was already defined as $aggDir"
fi
# NOTE: if BUILD_ID is already set, we need to make sure it
# is one of "our" BUILD_IDs,
# since if we try to run on Hudson, it gets's Hudson's
# version of BUILD_D which is like "2016-03-13_17-12-03"
# Therefore, we not only check "if set", we also check
# it's format to be sure it matches the pattern we use.
# We do not expect S or R in this context
# if we ever do, it is a 3 part id, not 2 part.
# Either of the two "digits" forms should work.
#buildIdPattern="^[MNIPYU][0-9]{8}-[0-9]{4}$"
buildIdPattern="^[MNIPYU][[:digit:]]{8}-[[:digit:]]{4}$"
if [[ -z "${BUILD_ID}" || ! "${BUILD_ID}" =~ $buildIdPattern ]]
then
BUILD_ID=$(fn-build-id "$BUILD_TYPE" )
assertNotEmpty BUILD_ID
export BUILD_ID
echo "BUILD_ID was defined as $BUILD_ID"
else
echo "BUILD_ID was already defined as $BUILD_ID"
fi
if [[ -z "${buildDirectory}" ]]
then
buildDirectory=$( fn-build-dir "$BUILD_ROOT" "$BUILD_ID" "$STREAM" )
assertNotEmpty buildDirectory
export buildDirectory
# this should be when we first create buildDirectory
echo "Making buildDirectory: ${buildDirectory}"
# Testing confirmed that umask was correct initially.
#echo "initial umask in bootstrapVariables.shsource: $(umask)"
#umask 0002
#echo "umask after setting in bootstrapVariables.shsource: $(umask)"
# it appears GID bit is not always set correctly.
# Appears related to "depth" of directories made.
# If we "cd" to parent directory, then it works.
# even using --mode u=rwx,g=rwxs,o=rx did not make it correctly.
# See https://bugs.eclipse.org/bugs/show_bug.cgi?id=492493
#mkdir -p --verbose --mode u=rwx,g=rwxs,o=rx "${buildDirectory}"
mkdir -p --verbose $BUILD_ROOT/siteDir/eclipse/downloads/drops4
pushd $BUILD_ROOT/siteDir/eclipse/downloads/drops4
mkdir --verbose $BUILD_ID
popd
else
echo "buildDirectory was already defined as $buildDirectory"
fi