diff options
author | Matt Raybuck <mraybuc@us.ibm.com> | 2018-09-07 08:59:11 -0500 |
---|---|---|
committer | Daniel M. Crowell <dcrowell@us.ibm.com> | 2018-09-11 15:18:41 -0500 |
commit | 9b59223389e768975850f0c8bf44d7a2c7135fcf (patch) | |
tree | 59198864bab536df715ca02163be5ba3cb0e06aa /src/build/tools | |
parent | 60d11f6f5f0720d2740cf990351c25d0f6bcd9c7 (diff) | |
download | talos-hostboot-9b59223389e768975850f0c8bf44d7a2c7135fcf.tar.gz talos-hostboot-9b59223389e768975850f0c8bf44d7a2c7135fcf.zip |
Add commit hook to sort the attribute xml files
When xml files were changed it would produce an instant merge
conflict. To resolve this issue a pre-commit hook was added that
will sort the xml attributes by id preventing instant conflicts.
Change-Id: Iffea1abfab459c542fe4f961616e0b5b4062804f
RTC: 180350
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/65894
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Reviewed-by: Nicholas E. Bofferding <bofferdn@us.ibm.com>
Reviewed-by: Ilya Smirnov <ismirno@us.ibm.com>
Reviewed-by: Roland Veloz <rveloz@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src/build/tools')
-rwxr-xr-x | src/build/tools/addCopyright | 12 | ||||
-rwxr-xr-x | src/build/tools/applyTargetingStyle | 20 | ||||
-rw-r--r-- | src/build/tools/insert_newlines.xsl | 40 | ||||
-rwxr-xr-x | src/build/tools/pre-commit-actions | 6 | ||||
-rw-r--r-- | src/build/tools/sort_targeting.xsl | 52 |
5 files changed, 129 insertions, 1 deletions
diff --git a/src/build/tools/addCopyright b/src/build/tools/addCopyright index c43f9f323..2e067902a 100755 --- a/src/build/tools/addCopyright +++ b/src/build/tools/addCopyright @@ -459,6 +459,10 @@ sub filetype { return "xml" } + if ( $filename =~ m/\.xsl$/i ) + { + return "xsl" + } if ( $filename =~ m/\.txt$/i ) { return "txt" @@ -777,6 +781,10 @@ sub removeCopyrightBlock { $data = removeProlog( $data, '<!--', '-->' ); } + elsif ( $filetype eq "xsl" ) + { + $data = removeProlog( $data, '<!--', '-->' ); + } elsif ( "Assembly" eq $filetype ) { $data = removeProlog( $data, '\#', '' ); @@ -1035,6 +1043,10 @@ EOF { $IBMCopyrightBlock = addPrologComments($IBMCopyrightBlock, '<!--', '-->'); } + elsif ( "xsl" eq $filetype) + { + $IBMCopyrightBlock = addPrologComments($IBMCopyrightBlock, '<!--', '-->'); + } else { print STDOUT "ERROR: Can\'t handle filetype: $filetype\n"; diff --git a/src/build/tools/applyTargetingStyle b/src/build/tools/applyTargetingStyle new file mode 100755 index 000000000..7fc5d198d --- /dev/null +++ b/src/build/tools/applyTargetingStyle @@ -0,0 +1,20 @@ +#!/usr/bin/bash + +for var in "$@" +do + if [[ $var = *target_types*.xml ]] || [[ $var = *attribute_types*.xml ]] ; + then + echo "Applying targeting sort for file: " + echo " $var" + xsltproc $TOOLSDIR/sort_targeting.xsl $var > temp.xml + rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi + xsltproc $TOOLSDIR/insert_newlines.xsl temp.xml > $var + rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi + rm temp.xml + rc=$?; if [[ $rc != 0 ]]; + then + echo "rm $PROJECT_ROOT/temp.xml failed. Manual removal required." + fi + fi +done + diff --git a/src/build/tools/insert_newlines.xsl b/src/build/tools/insert_newlines.xsl new file mode 100644 index 000000000..637c22b57 --- /dev/null +++ b/src/build/tools/insert_newlines.xsl @@ -0,0 +1,40 @@ +<!-- IBM_PROLOG_BEGIN_TAG --> +<!-- This is an automatically generated prolog. --> +<!-- --> +<!-- $Source: src/build/tools/insert_newlines.xsl $ --> +<!-- --> +<!-- OpenPOWER HostBoot Project --> +<!-- --> +<!-- Contributors Listed Below - COPYRIGHT 2018 --> +<!-- [+] 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 --> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + <xsl:output method="xml" indent="no" omit-xml-declaration="yes"/> + + <!-- Copy everything from the source file to the destination as it is but + add newlines if the current match is a child element of the root node. + --> + <xsl:template match="@*|node()"> + <xsl:copy> + <xsl:apply-templates select="@*|node()"/> + </xsl:copy> + <xsl:if test=". = /node()/*"> + <xsl:text>
</xsl:text> + </xsl:if> + </xsl:template> + +</xsl:stylesheet> diff --git a/src/build/tools/pre-commit-actions b/src/build/tools/pre-commit-actions index d47dfff74..a914663d2 100755 --- a/src/build/tools/pre-commit-actions +++ b/src/build/tools/pre-commit-actions @@ -6,7 +6,7 @@ # # OpenPOWER HostBoot Project # -# Contributors Listed Below - COPYRIGHT 2015,2016 +# Contributors Listed Below - COPYRIGHT 2015,2018 # [+] International Business Machines Corp. # # @@ -28,6 +28,7 @@ # the code beautifier astyle. my $copyrightScript = "addCopyright"; +my $xmlSortingScript = "applyTargetingStyle"; ## Make up a list of all staged files ( --cached --name-only ) ## Filter for only Added or Modified ( --diff-filter=AM ) @@ -43,6 +44,9 @@ if ( @fileList ) system "$ENV{'TOOLSDIR'}/$copyrightScript update @fileList"; die("$?") if ($? != 0); + system "$ENV{'TOOLSDIR'}/$xmlSortingScript @fileList"; + die("$?") if ($? != 0); + system "git add @fileList"; exit 1 if ($? != 0); } diff --git a/src/build/tools/sort_targeting.xsl b/src/build/tools/sort_targeting.xsl new file mode 100644 index 000000000..47e5c98b9 --- /dev/null +++ b/src/build/tools/sort_targeting.xsl @@ -0,0 +1,52 @@ +<!-- IBM_PROLOG_BEGIN_TAG --> +<!-- This is an automatically generated prolog. --> +<!-- --> +<!-- $Source: src/build/tools/sort_targeting.xsl $ --> +<!-- --> +<!-- OpenPOWER HostBoot Project --> +<!-- --> +<!-- Contributors Listed Below - COPYRIGHT 2018 --> +<!-- [+] 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 --> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> +<xsl:strip-space elements="*"/> + +<!-- Setup a key that maps preceding comments to the first following sibling. + That way the output can keep the comments in the same relative position + after sorting has occurred. + --> +<xsl:key name = "k_precedingComment" + match = "comment()" + use = "generate-id(following-sibling::*[1])" /> + +<!-- For each element in the file sort it recursively based on its child + <id> tag. If an element doesn't have a child <id> tag then its order + relative to its parent won't change. + --> +<xsl:template match="*"> + <!-- Add the preceding comments back atop the current matched element --> + <xsl:copy-of select="key('k_precedingComment', generate-id())" /> + <xsl:copy> + <xsl:apply-templates select="@*"/> + <xsl:apply-templates select="node()"> + <xsl:sort select="id"/> + </xsl:apply-templates> + </xsl:copy> +</xsl:template> + +</xsl:stylesheet> |