diff options
author | Stephen Cprek <smcprek@us.ibm.com> | 2015-09-25 16:40:37 -0500 |
---|---|---|
committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2015-12-11 13:32:21 -0600 |
commit | 5b981cbc9d2bfdd348c7aeb3ae4b22da4cc98880 (patch) | |
tree | cf8224eb4db14d541bb0fcff0a7deeb1aac4c2ca /src/build/tools | |
parent | 59068127c969af4cfda3408da4d3e99fdf84325d (diff) | |
download | talos-hostboot-5b981cbc9d2bfdd348c7aeb3ae4b22da4cc98880.tar.gz talos-hostboot-5b981cbc9d2bfdd348c7aeb3ae4b22da4cc98880.zip |
Tool to convert gerrit branches to fips releases and vice versa
Change-Id: I6e38248db57e1d6f0f5dd85411e7bf1489454d76
Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/20783
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Tested-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/build/tools')
-rwxr-xr-x | src/build/tools/conv_rel_branch | 320 |
1 files changed, 320 insertions, 0 deletions
diff --git a/src/build/tools/conv_rel_branch b/src/build/tools/conv_rel_branch new file mode 100755 index 000000000..9f1d807a4 --- /dev/null +++ b/src/build/tools/conv_rel_branch @@ -0,0 +1,320 @@ +#!/usr/bin/perl +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/build/tools/conv_rel_branch $ +# +# OpenPOWER HostBoot Project +# +# Contributors Listed Below - COPYRIGHT 2015 +# [+] International Business Machines Corp. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. See the License for the specific language governing +# permissions and limitations under the License. +# +# IBM_PROLOG_END_TAG + +use strict; +use warnings; +use Data::Dumper; +use Getopt::Long qw(:config pass_through); + +# Globals +my %power_platforms = (); +my %relations = (); +my $latest_power_platform = ""; +my $fsp_ci_jenkins_rel_file = "/gsa/ausgsa/home/f/s/fspcibld/patches/cipatch_xml"; +use constant MASTER => "master"; +my $debug = 0; +my $help = 0; + +# Set local variables based on ENV variables +my $PROJECT_ROOT = `git rev-parse --show-toplevel`; + +# Parse command line parameters +GetOptions("debug!" => \$debug, + "help" => \$help); + +# List of commands tool can run +my %commands = ( "rtob" => \&execute_rel_to_branch, + "btor" => \&execute_branch_to_rel, + ); + +if ($help) +{ + execute_help(); +} +else +{ + my $command = shift @ARGV; + if ($commands{$command}) + { + system("git remote -v | grep gerrit -q"); + die "Gerrit remote DNE, must run in repo with gerrit remote" if $?; + # Build release to branch relation hash. + build_relations(); + &{$commands{$command}}(); + } + else + { + execute_help(); + } +} + +############################## Begin Actions ################################### + +sub execute_rel_to_branch +{ + my $release = ""; + + GetOptions("release:s" => \$release); + die "Missing release" if $release eq ""; + + # Get power platform associated with release + my $power_platform = get_power_platform($release); + # Find release in relations hash. + my $branch = $relations{$power_platform}{$release}; + die "Fips release => $release has not corresponding gerrit branch" if (!$branch); + print "$branch \n"; +} + +sub execute_branch_to_rel +{ + my $branch = ""; + + GetOptions("branch:s" => \$branch); + die "Missing branch" if $branch eq ""; + + # Get power platform associated with branch + my $power_platform = get_power_platform($branch); + + # Find branch in relations hash. + my $release = ""; + foreach my $rel (sort keys %{$relations{$power_platform}}) + { + if ($relations{$power_platform}{$rel} eq "$branch") + { + $release = $rel; + last; + } + } + die "Gerrit branch => $branch has not corresponding fips release" if ($release eq ""); + print "$release \n"; +} + +sub execute_help +{ + my $command = shift @ARGV; + + if ($command eq "") + { + print " Usage:\n"; + print " rel_branch [options] <tool>\n\n"; + print " Tool to convert fips release to branches and vice versa\n\n"; + print " Requires:\n"; + print " Tool to run in git repo that has gerrit remote\n\n"; + print " Available subtools:\n"; + foreach my $key (sort keys %commands) + { + print " $key\n"; + } + print "\n"; + print " Global options:\n"; + print " --debug Enable debug mode.\n"; + print " --help Display help on a specific tool.\n"; + } + elsif (not defined $commands{$command}) + { + die "Unknown subcommand: $command.\n"; + } + else + { + my %help = ( + "rtob" => +q( + Convert release to branch + + Options: + --release=<release> Fips release name (e.g. fips810) [required]. +), + "btor" => +q( + Convert branch to fips release + + Options: + --branch=<remote-gerrit-branch> Remote gerrit branch (e.g. release-fips810, master) [required]. +), + ); + + print "rel_branch $command:"; + print $help{$command}; + } +} + +############################## Begin Sub Routines ############################## + +# sub get_release_branches +# +# Get all branches in gerrit that are prefixed 'release-' and remove the prefix +# *Note branches with string 'master' are removed from this to result in direct +# matches of fips releases only. Master branches will be dervied later. +# +# @return array - sorted names of branches (e.g release-fips810 ...) +# +sub get_release_branches +{ + chdir($PROJECT_ROOT); + die $? if ($?); + + # Parse for remote gerrit branches associated directly with a release + my $cmd = "git branch -a | grep -e remotes/gerrit/release"; + $cmd .= " | sed -e 's/^[ \\t]*remotes\\/gerrit\\///'"; + + my @release_branches = sort (split('\n',`$cmd`)); + print "Release Branches:\n" if $debug; + print Dumper \@release_branches if $debug; + return @release_branches; +} + +# sub get_fips_releases +# +# Get all fips releases that fsp-ci-jenkins uses in sorted order. +# +# @return array - sorted names of releases (e.g fips810, fips820, etc) +# +sub get_fips_releases +{ + chdir($PROJECT_ROOT); + die $? if ($?); + + # Parse fsp-ci-jenkins xml file for releases + my $cmd = "cat $fsp_ci_jenkins_rel_file | grep release | "; + $cmd .= "sed -e 's/^[ \\t]*<release>//' -e 's/<\\/release>[ \\t]*//'"; + + my @fips_releases = sort (split('\n',`$cmd`)); + print "Fips Release:\n" if $debug; + print Dumper \@fips_releases if $debug; + return @fips_releases; +} + +# sub get_power_platform +# +# Takes a references (release or gerrit branch) and determines the power +# platform it belongs to. +# +# @return string - power platform (e.g. p8, p9) +# +sub get_power_platform +{ + my $reference = shift; + + my $power_platform = ""; + if ($reference =~ m/master/) + { + # Remove prefix from older platforms (e.g. master-p8). If nothing is + # replaced then it is the latest power platform. + $reference =~ s/master-//; + if ($reference eq MASTER) + { + $power_platform = $latest_power_platform; + } + else + { + $power_platform = $reference; + } + } + else + { + ($power_platform) = $reference =~ /fips(.*)[0-9][0-9]/; + $power_platform = "p$power_platform"; + $power_platforms{$power_platform} = 1; + } + return $power_platform; +} + +# sub build_relations +# +# Build a relationship hash between fips releases and gerrit branches using +# fsp-ci-jenkins xml and git branch command within hostboot. +# +# Structure: +# power_platform => +# fips-release => gerrit-branch +# Example: +# p8 => +# fips820 => release-fips820 +# fips811 => release-fips811 +# fips840 => release-fips840 +# fips850 => master-p8 +# fips830 => release-fips830 +# fips810 => release-fips810 +# p9 => +# fips910 => master +# +sub build_relations +{ + my @releases = get_fips_releases(); + my @branches = get_release_branches(); + + # Fill in fips release keys + foreach my $release (@releases) + { + my $power_platform = get_power_platform($release); + $relations{$power_platform}{$release} = ""; + } + + # Fill in fips release values, which are gerrit release branches. + foreach my $branch (@branches) + { + my $power_platform = get_power_platform($branch); + my $release = $branch; + $release =~ s/release-//; + $relations{$power_platform}{$release} = $branch; + } + + # Handle master branches for each platform + my @platforms = sort keys %power_platforms; + foreach my $i (0 .. $#platforms) + { + my $power_platform = $platforms[$i]; + + # Lastest power platform matches branch master + my $master = MASTER; + # Previous power platforms match branch "master-$platform" + if ($i < $#platforms) + { + $master = MASTER."-$power_platform"; + } + else + { + # Set latest power platform + $latest_power_platform = $power_platform; + } + + # Check for first fips release without a gerrit branch. Due to sort + # order, it will be the next in order release. It is done this way + # to avoid issues when fips releases are ahead of gerrit branches. In + # other words it is possible to have fips releases past gerrit master. + foreach my $release (sort keys %{$relations{$power_platform}}) + { + if ($relations{$power_platform}{$release} eq "") + { + $relations{$power_platform}{$release} = $master; + last; + } + } + } + + print "Relations:\n" if $debug; + print Dumper \%relations if $debug; +} |