Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d3148b8d9ec515c3f5508b5dc9d3ec578ada11b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/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


Back to the top