summaryrefslogtreecommitdiffstats
path: root/release-tools/mksrc.sh
blob: 1c2632058d95e90f90486aa2c53189f355093537 (plain)
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/bin/bash
# Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
# Contact: http://www.qt-project.org/
#
# You may use this file under the terms of the 3-clause BSD license.
# See the file LICENSE from this package for details.
#
#
#
# Script for archiving qt5 repositories
#
# Usage:
# ./mksrc.sh -u <file url to local git clone> -v <version>
#  - Currently supporting only local clones, not direct git:// url's
# After running the script, one will get qt-everywhere-opensource-src-<version>.tar.gz
# and qt-everywhere-opensource-src-<version>.zip
#

CUR_DIR=$PWD
REPO_DIR=$CUR_DIR
QTVER=0.0.0
QTSHORTVER=0.0
QTGITTAG=.sha1s
PACK_TIME=`date '+%Y-%m-%d'`
DOCS=generate
MULTIPACK=no
IGNORE_LIST=

function usage()
{
  echo "Usage:"
  echo "./mksrc.sh -u <file_url_to_git_repo> -v <version> [-m][-d][-i sub]"
  echo "where -u is path to git repo and -v is version"
  echo "Optional parameters:"
  echo "-m             one is able to tar each sub module separately"
  echo "-no-docs       skip generating documentation"
  echo "-i submodule   will exclude the submodule from final package "
}

function cleanup()
{
  echo "Cleaning all tmp artifacts"
  rm -f _txtfiles
  rm -f __files_to_zip
  rm -f _tmp_mod
  rm -f _tmp_shas
  rm -rf $PACKAGE_NAME
}

function create_main_file()
{
  echo " - Creating single tar.gz file - "
  tar czf $BIG_TAR $PACKAGE_NAME/

  echo " - Creating single tar.bz2 file - "
  tar cjf $PACKAGE_NAME.tar.bz2 $PACKAGE_NAME/

  echo " - Creating single tar.xz file - "
  tar cJf $PACKAGE_NAME.tar.xz $PACKAGE_NAME/

  echo " - Creating single 7z file - "
  7z a $PACKAGE_NAME.7z $PACKAGE_NAME/ > /dev/null

  echo " - Creating single win zip - "
  # ZIP
  find $PACKAGE_NAME/ > __files_to_zip
  # zip binfiles
  file -f __files_to_zip | fgrep -f _txtfiles -v | cut -d: -f1 | zip -9q $BIG_ZIP -@
  #zip ascii files with win line endings
  file -f __files_to_zip | fgrep -f _txtfiles | cut -d: -f1 | zip -l9q $BIG_ZIP -@
}

function create_and_delete_submodule()
{
  mkdir submodules_tar
  mkdir submodules_zip
  while read submodule; do
    _file=$(echo "$submodule" | cut -d'/' -f1)-$QTVER
    echo " - tarring $_file -"
    tar czf $_file.tar.gz $PACKAGE_NAME/$submodule
    mv $_file.tar.gz submodules_tar/
    find $PACKAGE_NAME/$submodule > __files_to_zip
    echo "- zippinging $_file -"
    # zip binfiles
    file -f __files_to_zip | fgrep -f _txtfiles -v | cut -d: -f1 | zip -9q $_file.zip -@
    #zip ascii files with win line endings
    file -f __files_to_zip | fgrep -f _txtfiles | cut -d: -f1 | zip -l9q $_file.zip -@
    mv $_file.zip submodules_zip/
    rm -rf $PACKAGE_NAME/$submodule
  done < $MODULES
}

#read machine config
. $(dirname $0)/default_src.config

# read the arguments
while test $# -gt 0; do
  case "$1" in
    -h|--help)
      usage
      exit 0
    ;;
    -m|--modules)
      shift
      MULTIPACK=yes
    ;;
    --no-docs)
      shift
      DOCS=skip
    ;;
    -i|--ignore)
      shift
      IGNORE_LIST=$IGNORE_LIST" "$1
      shift
    ;;
    -u|--url)
      shift
      REPO_DIR=/$1
      if [ ! -d "$REPO_DIR/.git" ]; then
        echo "Error: $REPO_DIR is not a valid git repo ($1)"
        exit 1
      fi
      shift
    ;;
    -v|--version)
      shift
        QTVER=$1
        QTSHORTVER=$(echo $QTVER | cut -d. -f1-2)
      shift
    ;;
    *)
      echo "Error: Unknown option $1"
      usage
      exit 0
    ;;
    esac
done

# Check if the DIR is valid git repository
if [ ! -d "$REPO_DIR/.git" ]; then
  echo "$REPO_DIR is not a valid git repo"
  exit 2
fi

PACKAGE_NAME=qt-everywhere-opensource-src-$QTVER
BIG_TAR=$PACKAGE_NAME.tar.gz
BIG_ZIP=$PACKAGE_NAME.zip
MODULES=$CUR_DIR/submodules.txt
_TMP_DIR=$CUR_DIR/$PACKAGE_NAME

#------------------------------------------------------------------
# Step 1, Find all submodules from main repo and archive them
#------------------------------------------------------------------

echo " -- Finding submodules from $REPO_DIR -- "

rm -f $MODULES
rm -f $BIG_TAR
rm -f $BIG_ZIP
rm -rf $_TMP_DIR
mkdir $_TMP_DIR

cd $REPO_DIR

# detect the submodules to be archived
rm -f $MODULES
find . -name '.git' -type d -print | sed -e 's/^\.\///' -e 's/\.git$//' | grep -v '^$' >> $MODULES

#archive the main repo
git archive --format=tar  HEAD | gzip -4 > $CUR_DIR/$BIG_TAR
mv $CUR_DIR/$BIG_TAR $_TMP_DIR
cd $_TMP_DIR
tar xzf $BIG_TAR
rm -f $BIG_TAR
cd $REPO_DIR
_SHA=`cat .git/refs/heads/master`
rm -f $_TMP_DIR/$QTGITTAG
echo "qt5=$_SHA">$_TMP_DIR/$QTGITTAG

#archive all the submodules and generate file from sha1's
while read submodule; do
  echo " -- From dir $PWD/$submodule, lets pack $submodule --"
  cd $submodule
  _file=$(echo "$submodule" | cut -d'/' -f1).tar.gz
  #archive submodule to $CUR_DIR/$BIG_TAR
  git archive --format=tar --prefix=$submodule/ HEAD | gzip -4 > $CUR_DIR/$_file
  #move it temp dir
  mv $CUR_DIR/$_file $_TMP_DIR
  #store the sha1
  _SHA=`cat .git/HEAD | cut -d' ' -f2`
  if [ $(echo $_SHA | cut -d/ -f1-2) = refs/heads ]; then
    _SHA=`cat .git/$_SHA`
  else
    _SHA=`cat .git/HEAD`
  fi
  echo "$(echo $(echo $submodule|sed 's/-/_/g') | cut -d/ -f1)=$_SHA" >>$_TMP_DIR/$QTGITTAG
  cd $_TMP_DIR
  #extract to tmp dir
  tar xzf $_file
  rm -f $_file
  cd $REPO_DIR
done < $MODULES
#mv $MODULES $CUR_DIR

#------------------------------------------------------------------
# Step 2,  remove rest of the unnecessary files and ignored submodules
# and its sha1 values from sha file
#------------------------------------------------------------------
rm -f $CUR_DIR/$PACKAGE_NAME/init-repository
rm -f $CUR_DIR/$PACKAGE_NAME/.commit-template
rm -f $CUR_DIR/$PACKAGE_NAME/.gitmodules
find $CUR_DIR/$PACKAGE_NAME -name .gitignore -exec rm -f {} \; > /dev/null 2>&1
find $CUR_DIR/$PACKAGE_NAME -name .gitattributes -exec rm -f {} \; > /dev/null 2>&1
rm -f $CUR_DIR/$PACKAGE_NAME/qtbase/header.*
# find ./ -type d -name "tests" -exec rm -rf {} \; > /dev/null 2>&1

cd $CUR_DIR/$PACKAGE_NAME
__skip_sub=no
rm -f _tmp_mod
rm -f _tmp_shas

# read the shas
. $CUR_DIR/$PACKAGE_NAME/$QTGITTAG
echo "The qt5 was archived from $qt5 sha" >$CUR_DIR/_tmp_shas
echo "------------------------------------------------------------------------">>$CUR_DIR/_tmp_shas
echo "Fixing shas"
while read submodule; do
  for ignore in $IGNORE_LIST; do
    if [ _pre_$ignore"/" = _pre_$submodule ]; then
      __skip_sub=yes
      echo "removing $submodule"
      rm -rf $submodule
      break
    fi
  done
  if [ $__skip_sub = no ]; then
    __sub=$(echo $(echo $submodule|sed 's/-/_/g') | cut -d/ -f1)
    echo "Fixing $__sub ${!__sub}"
    echo $submodule >>$CUR_DIR/_tmp_mod
    echo "The $(echo $__sub| sed 's/_/-/g') was archived from ${!__sub} sha" >>$CUR_DIR/_tmp_shas
    echo "------------------------------------------------------------------------">>$CUR_DIR/_tmp_shas
  fi
  __skip_sub=no
done < $MODULES
cat $CUR_DIR/_tmp_mod > $MODULES
rm -f $CUR_DIR/$PACKAGE_NAME/$QTGITTAG
cat $CUR_DIR/_tmp_shas > $CUR_DIR/$PACKAGE_NAME/$QTGITTAG
#------------------------------------------------------------------
# Step 3,  replace version strings with correct version, and
# patch Qt_PACKAGE_TAG and QT_PACKAGEDATE_STR defines
#------------------------------------------------------------------
echo " -- Patching %VERSION% etc. defines --"
cd $CUR_DIR/$PACKAGE_NAME/
find . -type f -print0 | xargs -0 sed -i -e "s/%VERSION%/$QTVER/g" -e "s/%SHORTVERSION%/$QTSHORTVER/g" -e "s/#define QT_PACKAGE_TAG \"\"/#define QT_PACKAGE_TAG \"\"/g" -e "s/#define QT_PACKAGEDATE_STR \"YYYY-MM-DD\"/#define QT_PACKAGEDATE_STR \"$PACK_TIME\"/g"

#------------------------------------------------------------------
# Step 4,  generate docs
#------------------------------------------------------------------
if [ $DOCS = generate ]; then
  # Make a copy of the source tree
  DOC_BUILD=$CUR_DIR/doc-build
  mkdir -p $DOC_BUILD
  cp -R $CUR_DIR/$PACKAGE_NAME $DOC_BUILD
  cd $DOC_BUILD/$PACKAGE_NAME
  # Build bootstrapped qdoc
  ./configure -developer-build -opensource -confirm-license -nomake examples -nomake tests -release
  (cd qtbase && make -j30 sub-tools-bootstrap && make -j30 sub-qdoc)
  # Run qmake in each module, as this generates the .pri files that tell qdoc what docs to generate
  QMAKE=$PWD/qtbase/bin/qmake
#  for i in q* ; do if [ -d $i -a -e $i/*.pro ] ; then (cd $i ; $QMAKE ; cp module-paths/modules/*.pri ../qtbase/module-paths/modules ) ; fi ; done
  for i in `cat $MODULES` ; do if [ -d $i -a -e $i/*.pro ] ; then (cd $i ; $QMAKE ; cp module-paths/modules/*.pri ../qtbase/module-paths/modules ) ; fi ; done
  # Build libQtHelp.so and qhelpgenerator
  (cd qtbase && make -j30)
  (cd qtxmlpatterns ; make -j30)
  (cd qttools ; make -j30)
  (cd qttools/src/assistant/help ; make -j30)
  (cd qttools/src/assistant/qhelpgenerator ; make -j30)
  # Generate the offline docs and qt.qch
  (cd qtdoc ; LD_LIBRARY_PATH=$PWD/../qttools/lib make -j30 qch_docs)
  # Put the generated docs back into the clean source directory
  mv $DOC_BUILD/$PACKAGE_NAME/qtdoc/doc/html $CUR_DIR/$PACKAGE_NAME/qtdoc/doc
  mv $DOC_BUILD/$PACKAGE_NAME/qtdoc/doc/qch $CUR_DIR/$PACKAGE_NAME/qtdoc/qch
  # Cleanup
  cd $CUR_DIR/$PACKAGE_NAME/
  #rm -rf $DOC_BUILD
else
  echo " -- Creating src files without generated offline documentation --"
fi

#------------------------------------------------------------------
# Step 5,  create zip file and tar files
#------------------------------------------------------------------
# list text file regexp keywords, if you find something obvious missing, feel free to add
cd $CUR_DIR
echo "ASCII
directory
empty
POSIX
html
text" > _txtfiles

echo " -- Create B I G tars -- "
create_main_file

# Create tar/submodule
if [ $MULTIPACK = yes ]; then
  mv $BIG_TAR $BIG_TAR.huge
  mv $BIG_ZIP $BIG_ZIP.huge
  echo " -- Creating tar per submodule -- "
  create_and_delete_submodule
  create_main_file
  mv $BIG_TAR submodules_tar/qt5-$QTVER.tar.gz
  mv $BIG_ZIP submodules_zip/qt5-$QTVER.zip
  mv $BIG_TAR.huge $BIG_TAR
  mv $BIG_ZIP.huge $BIG_ZIP
fi
cleanup

echo "Done!"