Commit 1724b361 authored by anonym's avatar anonym
Browse files

Build system: by default, merge the base branch early when building (#12557)

Previously, when we run `rake build` in a non-base branch it will be
run at the Git state before the base branch merge, resulting in mixed
Git state. And since the merge happens in auto/build it will obviously
also be run in an pre-merge state. This can cause all sorts of subtle
build errors.

So let's move this merge earlier, into the Rakefile, so only changes
there can be mixed. Also, this builds a foundation for completely
eliminating this mixed state (soon!).
parent 91b9da72
......@@ -38,7 +38,6 @@ EXPORTED_VARIABLES = [
'TAILS_ACNG_PROXY',
'TAILS_BUILD_FAILURE_RESCUE',
'TAILS_DATE_OFFSET',
'TAILS_MERGE_BASE_BRANCH',
'TAILS_OFFLINE_MODE',
'TAILS_PROXY',
'TAILS_PROXY_TYPE',
......@@ -47,6 +46,7 @@ EXPORTED_VARIABLES = [
'GIT_COMMIT',
'GIT_REF',
'BASE_BRANCH_GIT_COMMIT',
'BUILD_BASENAME_SUFFIX',
].freeze
ENV['EXPORTED_VARIABLES'] = EXPORTED_VARIABLES.join(' ')
......@@ -298,8 +298,8 @@ task :parse_build_options do
$keep_running = true
ENV['TAILS_BUILD_FAILURE_RESCUE'] = '1'
# Jenkins
when 'mergebasebranch'
ENV['TAILS_MERGE_BASE_BRANCH'] = '1'
when 'nomergebasebranch'
$skip_mergebasebranch = true
else
raise "Unknown Tails build option '#{opt}'"
end
......@@ -409,6 +409,35 @@ task setup_environment: ['validate_git_state'] do
end
end
task merge_base_branch: ['parse_build_options', 'setup_environment'] do
ENV['BUILD_BASENAME_SUFFIX'] ||= ''
next if $skip_mergebasebranch
branch = git_helper('git_current_branch')
base_branch = git_helper('base_branch')
source_date_faketime = `date --utc --date="$(dpkg-parsechangelog --show-field=Date)" '+%Y-%m-%d %H:%M:%S'`.chomp
next if releasing? || branch == base_branch
warn "Merging base branch '#{base_branch}' (at commit " \
"#{ENV['BASE_BRANCH_GIT_COMMIT']}) ..."
begin
run_command('faketime', '-f', source_date_faketime, \
'git', 'merge', '--no-edit', ENV['BASE_BRANCH_GIT_COMMIT'])
rescue CommandError
run_command('git', 'merge', '--abort')
raise <<-END_OF_MESSAGE.gsub(/^ /, '')
There were conflicts when merging the base branch; either
merge it yourself and resolve conflicts, or skip this merge
by rebuilding with the 'nomergebasebranch' option.
END_OF_MESSAGE
end
run_command('git', 'submodule', 'update', '--init')
clean_git_base_branch = base_branch.gsub('/', '_')
git_base_branch_short_id = `git rev-parse --verify --short #{ENV['BASE_BRANCH_GIT_COMMIT']}`.chomp
ENV['BUILD_BASENAME_SUFFIX'] = \
"+#{clean_git_base_branch}@#{git_base_branch_short_id}"
end
task :maybe_clean_up_builder_vms do
clean_up_builder_vms if $force_cleanup
end
......@@ -447,6 +476,7 @@ task build: [
'maybe_clean_up_builder_vms',
'validate_git_state',
'setup_environment',
'merge_base_branch',
'validate_http_proxy',
'ensure_correct_permissions',
'vm:up',
......
......@@ -28,7 +28,7 @@ GIT_BRANCH="$(git_current_branch)"
if [ -n "${GIT_BRANCH}" ]; then
CLEAN_GIT_BRANCH=$(echo "$GIT_BRANCH" | sed 's,/,_,g')
GIT_SHORT_ID="$(git_current_commit --short)"
BUILD_BASENAME="tails-amd64-${CLEAN_GIT_BRANCH}-${AMNESIA_VERSION}-${AMNESIA_NOW}-${GIT_SHORT_ID}"
BUILD_BASENAME="tails-amd64-${CLEAN_GIT_BRANCH}-${AMNESIA_VERSION}-${AMNESIA_NOW}-${GIT_SHORT_ID}${BUILD_BASENAME_SUFFIX}"
else
if git_on_a_tag; then
CLEAN_GIT_TAG=$(git_current_tag | tr '/-' '_~')
......@@ -40,30 +40,6 @@ else
fi
fi
GIT_BASE_BRANCH=$(base_branch) \
|| fatal "GIT_BASE_BRANCH could not be guessed."
if [ "${TAILS_MERGE_BASE_BRANCH:-}" = 1 ] && \
! git_on_a_tag && [ "$GIT_BRANCH" != "$GIT_BASE_BRANCH" ] ; then
[ -n "${BASE_BRANCH_GIT_COMMIT}" ] \
|| fatal "Base branch's top commit is not set."
echo "I: Merging base branch ${GIT_BASE_BRANCH}" \
"(at commit ${BASE_BRANCH_GIT_COMMIT})..."
faketime -f "${SOURCE_DATE_FAKETIME}" \
git merge --no-edit "${BASE_BRANCH_GIT_COMMIT}" \
|| fatal "Failed to merge base branch."
git submodule update --init
# Adjust BUILD_BASENAME to embed the base branch name and its top commit
CLEAN_GIT_BASE_BRANCH=$(echo "$GIT_BASE_BRANCH" | sed 's,/,_,g')
GIT_BASE_BRANCH_SHORT_ID=$(git rev-parse --verify --short "${BASE_BRANCH_GIT_COMMIT}")
[ -n "${GIT_BASE_BRANCH_SHORT_ID}" ] \
|| fatal "Base branch's top commit short ID could not be guessed."
BUILD_BASENAME="${BUILD_BASENAME}+${CLEAN_GIT_BASE_BRANCH}"
BUILD_BASENAME="${BUILD_BASENAME}@${GIT_BASE_BRANCH_SHORT_ID}"
fi
# save variables that lb build needs
mkdir -p tmp
echo "BUILD_BASENAME='${BUILD_BASENAME}'" > tmp/build_environment
......
......@@ -12,7 +12,6 @@
export SOURCE_DATE_EPOCH="$(date --utc --date="$(dpkg-parsechangelog --show-field=Date)" +%s)"
export SOURCE_DATE_YYYYMMDD="$(date --utc --date="$(dpkg-parsechangelog --show-field=Date)" +%Y%m%d)"
export SOURCE_DATE_FAKETIME="$(date --utc --date="$(dpkg-parsechangelog --show-field=Date)" '+%Y-%m-%d %H:%M:%S')"
# Base for the string that will be passed to "lb config --bootappend-live"
AMNESIA_APPEND="live-media=removable nopersistence noprompt timezone=Etc/UTC splash noautologin module=Tails slab_nomerge slub_debug=FZP mce=0 vsyscall=none page_poison=1 init_on_free=1 mds=full,nosmt"
......
......@@ -23,10 +23,10 @@ as_root_do() {
${APT_SNAPSHOTS_SERIALS:+APT_SNAPSHOTS_SERIALS="${APT_SNAPSHOTS_SERIALS}"} \
${TAILS_WEBSITE_CACHE:+TAILS_WEBSITE_CACHE="${TAILS_WEBSITE_CACHE}"} \
${WEBSITE_CACHE_BASEDIR:+WEBSITE_CACHE_BASEDIR="${WEBSITE_CACHE_BASEDIR}"} \
${TAILS_MERGE_BASE_BRANCH:+TAILS_MERGE_BASE_BRANCH="${TAILS_MERGE_BASE_BRANCH}"} \
${GIT_COMMIT:+GIT_COMMIT="${GIT_COMMIT}"} \
${GIT_REF:+GIT_REF="${GIT_REF}"} \
${BASE_BRANCH_GIT_COMMIT:+BASE_BRANCH_GIT_COMMIT="${BASE_BRANCH_GIT_COMMIT}"} \
${BUILD_BASENAME_SUFFIX:+BUILD_BASENAME_SUFFIX="${BUILD_BASENAME_SUFFIX}"} \
"${@}"
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment