distrocompare.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2017, Intel Corporation.
  4. # All rights reserved.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. #
  20. # distrocompare.sh : provides capability to get a list of new packages
  21. # based on two distinct branches. This script takes
  22. # 2 parameters; either a commit-ish or a branch name
  23. #
  24. # To run : distrocompare.sh <older hash> <newer hash>
  25. # E.g. distrocompare.sh morty 92aa0e7
  26. # E.g. distrocompare.sh morty pyro
  27. #
  28. # get input as version
  29. previous_version=$1
  30. current_version=$2
  31. # set previous and current version
  32. if [ -z "$2" ]; then
  33. previous_version=$1
  34. current_version="current"
  35. fi
  36. # get script location. That's where the source supposedly located as well.
  37. scriptdir="$( realpath $(dirname "${BASH_SOURCE[0]}" ))"
  38. sourcedir="$( realpath $scriptdir/../.. )"
  39. # create working directory
  40. workdir=$(mktemp -d)
  41. # prepare to rollback to the branch if not similar
  42. branch=`cd $sourcedir; git branch | grep \* | cut -d ' ' -f2`
  43. # set current workdir to store final result
  44. currentworkdir=`pwd`
  45. # persists the file after local repo change
  46. cp $scriptdir/build-recipe-list.py $workdir
  47. #==================================================================
  48. function bake_distrodata {
  49. # get to source directory of the git
  50. cd $sourcedir
  51. # change the branch / commit. Do not change if input is current
  52. if [ "$1" != "current" ]; then
  53. output=$(git checkout $1 2>&1)
  54. # exit if git fails
  55. if [[ $output == *"error"* ]]; then
  56. echo "git error : $output"
  57. echo "exiting ... "
  58. rm -rf $workdir
  59. exit
  60. fi
  61. fi
  62. # make tmp as workdir
  63. cd $workdir
  64. # source oe-init to generate a new build folder
  65. source $sourcedir/oe-init-build-env $1
  66. # if file already exists with distrodata, do not append
  67. if ! grep -q "distrodata" "conf/local.conf"; then
  68. # add inherit distrodata to local.conf to enable distrodata feature
  69. echo 'INHERIT += "distrodata"' >> conf/local.conf
  70. fi
  71. # use from tmp
  72. $workdir/build-recipe-list.py generate_recipe_list
  73. }
  74. bake_distrodata $previous_version
  75. bake_distrodata $current_version
  76. #==================================================================
  77. cd $workdir
  78. # compare the 2 generated recipe-list.txt
  79. $workdir/build-recipe-list.py compare_recipe $previous_version $current_version
  80. # copy final result to current working directory
  81. cp $workdir/*_new_recipe_list.txt $currentworkdir
  82. if [ $? -ne 0 ]; then
  83. rm -rf $workdir/$previous_version
  84. rm -rf $workdir/$current_version
  85. rm $workdir/build-recipe-list.py
  86. # preserve the result in /tmp/distrodata if fail to copy the result over
  87. exit
  88. fi
  89. # cleanup
  90. rm -rf $workdir
  91. # perform rollback branch
  92. cd $sourcedir
  93. currentbranch=`git branch | grep \* | cut -d ' ' -f2`
  94. if [ "$currentbranch" != "$branch" ]; then
  95. git checkout $branch
  96. fi
  97. cd $currentworkdir
  98. #==================================================================