source: build.sh @ 13df6d

ng_0.9
Last change on this file since 13df6d was 13df6d, checked in by rene <rene@…>, 5 years ago

change version-schema of intermediate releases

  • Property mode set to 100755
File size: 5.1 KB
Line 
1#!/bin/bash
2# build.sh -- builds JAR and XPI files for mozilla extensions
3#   by Nickolay Ponomarev <asqueella@gmail.com>
4#   (original version based on Nathan Yergler's build script)
5# Most recent version is at <http://kb.mozillazine.org/Bash_build_script>
6
7# This script assumes the following directory structure:
8# ./
9#   chrome.manifest (optional - for newer extensions)
10#   install.rdf
11#   (other files listed in $ROOT_FILES)
12#
13#   content/    |
14#   locale/     |} these can be named arbitrary and listed in $CHROME_PROVIDERS
15#   skin/       |
16#
17#   defaults/   |
18#   components/ |} these must be listed in $ROOT_DIRS in order to be packaged
19#   ...         |
20#
21# It uses a temporary directory ./build when building; don't use that!
22# Script's output is:
23# ./$APP_NAME.xpi
24# ./$APP_NAME.jar  (only if $KEEP_JAR=1)
25# ./files -- the list of packaged files
26#
27# Note: It modifies chrome.manifest when packaging so that it points to
28#       chrome/$APP_NAME.jar!/*
29
30#
31# default configuration file is ./config_build.sh, unless another file is
32# specified in command-line. Available config variables:
33APP_NAME=          # short-name, jar and xpi files name. Must be lowercase with no spaces
34CHROME_PROVIDERS=  # which chrome providers we have (space-separated list)
35CLEAN_UP=          # delete the jar / "files" when done?       (1/0)
36ROOT_FILES=        # put these files in root of xpi (space separated list of leaf filenames)
37ROOT_DIRS=         # ...and these directories       (space separated list)
38BEFORE_BUILD=      # run this before building       (bash command)
39AFTER_BUILD=       # ...and this after the build    (bash command)
40
41if [ -z $1 ]; then
42  . ./build_config.sh
43else
44  . $1
45fi
46
47if [ -z $APP_NAME ]; then
48  echo "You need to create build config file first!"
49  echo "Read comments at the beginning of this script for more info."
50  exit;
51fi
52
53ROOT_DIR=`pwd`
54TMP_DIR=build
55
56#uncomment to debug
57#set -x
58
59# remove any left-over files from previous build
60rm -f $APP_NAME.jar $APP_NAME_*.xpi files
61rm -rf $TMP_DIR
62
63$BEFORE_BUILD
64
65# ---detect version
66REV=$(git log -n 1 --abbrev-commit --abbrev=8 | grep "commit" | cut -d" " -f2 | cut -d"." -f1)
67#CLEAN=$(git status | grep "working directory clean")
68CLEAN="true"
69TAG=$(git describe 2>/dev/null | sed 's/-/\./')
70INTERMEDIATE=$(git describe 2>/dev/null | grep "-")
71
72LOCALVERSION=$(cut -d"\"" -f 2 content/_version.dtd)
73if [ "$TAG" ]; then
74    VERSION=$TAG
75else
76    VERSION=$LOCALVERSION"-x-"g$REV
77fi
78if [ -z "$CLEAN" ]; then
79    VERSION=$VERSION"++"
80fi
81# --- version detected
82
83mkdir --parents  $TMP_DIR/chrome
84
85# generate the JAR file, excluding CVS, SVN, and temporary files
86JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar
87echo "Generating $JAR_FILE..."
88for CHROME_SUBDIR in $CHROME_PROVIDERS; do
89  find $CHROME_SUBDIR \( -path '*CVS*' -o -path '*.svn*' \) -prune -o -type f -print | grep -v \~ >> files
90done
91
92#zip -0 -r $JAR_FILE -@ < files
93# The following statement should be used instead if you don't wish to use the JAR file
94cp  --parents `cat files` $TMP_DIR/chrome
95
96# prepare components and defaults
97echo "Copying various files to $TMP_DIR folder..."
98for DIR in $ROOT_DIRS; do
99  mkdir $TMP_DIR/$DIR
100  FILES="`find $DIR \( -path '*CVS*' -o -path '*.svn*' \) -prune -o -type f -print | grep -v \~`"
101  echo $FILES >> files
102  cp  --parents $FILES $TMP_DIR
103done
104
105# Copy other files to the root of future XPI.
106for ROOT_FILE in $ROOT_FILES install.rdf chrome.manifest; do
107  cp  $ROOT_FILE $TMP_DIR
108  if [ -f $ROOT_FILE ]; then
109    echo $ROOT_FILE >> files
110  fi
111done
112
113cd $TMP_DIR
114find . -iname '.git' -type d -exec rm -rf {} \; 2>/dev/null
115find . -iname '.*.sw*' -exec rm -f {} \; 2>/dev/null
116find . -iname 'tests' -type d -exec rm -rf {} \; 2>/dev/null
117
118if [ -f "chrome.manifest" ]; then
119  echo "Preprocessing chrome.manifest..."
120  # You think this is scary?
121  #s/^(content\s+\S*\s+)(\S*\/)$/\1jar:chrome\/$APP_NAME\.jar!\/\2/
122  #s/^(skin|locale)(\s+\S*\s+\S*\s+)(.*\/)$/\1\2jar:chrome\/$APP_NAME\.jar!\/\3/
123  #
124  # Then try this! (Same, but with characters escaped for bash :)
125  sed -i -r s/^\(content\\s+\\S*\\s+\)\(\\S*\\/\)$/\\1chrome\\/\\2/ chrome.manifest
126  sed -i -r s/^\(skin\|locale\)\(\\s+\\S*\\s+\\S*\\s+\)\(.*\\/\)$/\\1\\2chrome\\/\\3/ chrome.manifest
127
128  # (it simply adds jar:chrome/whatever.jar!/ at appropriate positions of chrome.manifest)
129fi
130
131# change version information
132if [ -z "$CLEAN" ] || [ -z "$TAG" ] || [ "$INTERMEDIATE" ]; then
133    # replace the version tag
134    sed '/vident\.version/s/\".*\"/\"'$VERSION'\"/g' chrome/content/_version.dtd > chrome/content/_version.dtd_work
135    mv chrome/content/_version.dtd_work chrome/content/_version.dtd
136#   sed '/var version/s/\".*\";/'$VERSION'\";/g' install.js >install.js_new  2>/dev/null
137#   mv install.js_new install.js  2>/dev/null
138    sed '/em:version/s/\".*\"/\"'$VERSION'\"/g' install.rdf >install.rdf_new
139    mv install.rdf_new install.rdf
140fi
141
142# generate the XPI file
143echo "Generating ${APP_NAME}-${VERSION}-tb+sm.xpi..."
144zip -r ../${APP_NAME}-${VERSION}-tb+sm.xpi *
145
146cd "$ROOT_DIR"
147
148echo "Cleanup..."
149if [ $CLEAN_UP = 0 ]; then
150  # save the jar file
151  mv $TMP_DIR/chrome/$APP_NAME.jar .
152else
153  rm ./files
154fi
155
156# remove the working files
157rm -rf $TMP_DIR
158echo "Done!"
159
160$AFTER_BUILD
Note: See TracBrowser for help on using the repository browser.