MozillaZine

Bash build script

From MozillaZine Knowledge Base

(Difference between revisions)
Revision as of 03:12, 19 December 2004
Asqueella (Talk | contribs)

<-- Previous diff
Revision as of 17:55, 26 January 2005
Asqueella (Talk | contribs)
(new version)
Next diff -->
Line 1: Line 1:
{{extdev}} {{extdev}}
-Here is a bash script I'm using to package my extensions (under Linux and Cygwin). For Windows script see [[Dev : Extensions : Windows cmd build script]].+Here is a bash script I'm using to package my extensions (under [http://www.cygwin.com/ Cygwin]). For Windows script see [[Dev : Extensions : Windows cmd build script|'''cmd''' build script]].
-<pre>#!/bin/bash+<pre>
-# build.sh: build JAR and XPI files from source+#!/bin/bash
-# based on Nathan Yergler's build script+# build.sh -- builds JAR and XPI files for mozilla extensions
 +# by Nickolay Ponomarev <asqueella@gmail.com>
 +# based on Nathan Yergler's build script
 + 
 +# this script assumes the following directory structure:
 +# ./
 +# (files listed in $ROOT_FILES)
 +# content/
 +# locale/
 +# skin/
 +# defaults/ (only if $HAS_DEFAULTS=1)
 +# components/ (only if $HAS_COMPONENTS=1)
 +#
 +# It uses a temporary directory ./build; don't use that!
 +# Its output is:
 +# ./$APP_NAME.xpi
 +# ./$APP_NAME.jar (only if $KEEP_JAR=1)
 +# ./files -- the list of packaged files
#### editable items (none of these can be blank) #### editable items (none of these can be blank)
-APP_NAME=menuedit # short-name, jar and xpi files name.+APP_NAME=infolister # short-name, jar and xpi files name.
HAS_DEFAULTS=1 # whether the ext. provides default values for user prefs etc. HAS_DEFAULTS=1 # whether the ext. provides default values for user prefs etc.
-HAS_COMPONENTS=0 # whether the ext. includes any components+HAS_COMPONENTS=1 # whether the ext. includes any components
-HAS_LOCALE=1 # package APP_NAME.jar/locale/ ?+
-HAS_SKIN=0 # package APP_NAME.jar/skin/ ?+
KEEP_JAR=1 # leave the jar when done? KEEP_JAR=1 # leave the jar when done?
ROOT_FILES="license.txt install.rdf" # put these files in root of xpi ROOT_FILES="license.txt install.rdf" # put these files in root of xpi
 +VERSION=0.8.1 # version (for preprocessor which replaces __VERSION__ in
 + # install.rdf with $VERSION.builddate, eg 0.8.1.20050126)
#### editable items end #### editable items end
-TMP_DIR=build.tmp+ROOT_DIR=`pwd`
 +TMP_DIR=build
#uncomment to debug #uncomment to debug
Line 25: Line 43:
rm $APP_NAME.jar rm $APP_NAME.jar
rm $APP_NAME.xpi rm $APP_NAME.xpi
 +rm files
rm -rf $TMP_DIR rm -rf $TMP_DIR
-# create xpi directory layout and populate it+mkdir --parents --verbose $TMP_DIR/chrome
-mkdir $TMP_DIR+
-mkdir $TMP_DIR/chrome+
 +# generate the JAR file, excluding CVS and temporary files
 +JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar
 +echo "Generating $JAR_FILE..."
 +for CHROME_SUBDIR in content locale skin; do
 + find $CHROME_SUBDIR -path '*CVS*' -prune -o -type f -print | grep -v \~ >> files
 +done
 +
 +zip -0 -r $JAR_FILE `cat files`
 +# The following statement should be used instead if you don't wish to use the JAR file
 +#cp --verbose --parents `cat files` $TMP_DIR/chrome
 +
 +# prepare components and defaults
 +echo "Copying various files to '$TMP_DIR'..."
if [ $HAS_COMPONENTS = 1 ]; then if [ $HAS_COMPONENTS = 1 ]; then
mkdir $TMP_DIR/components mkdir $TMP_DIR/components
- cp components/* $TMP_DIR/components+ COMPONENT_FILES="`find components -path '*CVS*' -prune -o -type f -print | grep -v \~`"
 + echo $COMPONENT_FILES >> files
 + cp --verbose --parents $COMPONENT_FILES $TMP_DIR
fi fi
if [ $HAS_DEFAULTS = 1 ]; then if [ $HAS_DEFAULTS = 1 ]; then
DEFAULT_FILES="`find defaults -path '*CVS*' -prune -o -type f -print | grep -v \~`" DEFAULT_FILES="`find defaults -path '*CVS*' -prune -o -type f -print | grep -v \~`"
- cp --parents $DEFAULT_FILES $TMP_DIR+ echo $DEFAULT_FILES >> files
 + cp --verbose --parents $DEFAULT_FILES $TMP_DIR
fi fi
# Copy other files to the root of future XPI. # Copy other files to the root of future XPI.
-cp $ROOT_FILES $TMP_DIR+for ROOT_FILE in $ROOT_FILES; do
 + echo $ROOT_FILE >> files
 + cp --verbose $ROOT_FILE $TMP_DIR
 +done
-# generate the JAR file, excluding CVS and temporary files+cd $TMP_DIR
-zip -0 -r $TMP_DIR/chrome/$APP_NAME.jar `find content -path '*CVS*' -prune -o -type f -print | grep -v \~`+# Preprocess install.rdf (insert current date)
-if [ $HAS_LOCALE = 1 ]; then+# XXX preprocess customizable set of files (about.xul)
- zip -0 -r $TMP_DIR/chrome/$APP_NAME.jar `find locale -path '*CVS*' -prune -o -type f -print | grep -v \~`+if [ -f "install.rdf" ]; then
-fi+ echo "Preprocessing install.rdf..."
-if [ $HAS_SKIN = 1 ]; then+ cat install.rdf | sed s/__VERSION__/$VERSION.`date "+%Y%m%d"`/ > install.rdf
- zip -0 -r $TMP_DIR/chrome/$APP_NAME.jar `find skin -path '*CVS*' -prune -o -type f -print | grep -v \~`+
fi fi
# generate the XPI file # generate the XPI file
-cd $TMP_DIR+echo "Generating $APP_NAME.xpi..."
zip -r ../$APP_NAME.xpi * zip -r ../$APP_NAME.xpi *
-cd .. 
 +cd $ROOT_DIR
 +
 +echo "Cleanup..."
if [ $KEEP_JAR = 1 ]; then if [ $KEEP_JAR = 1 ]; then
# save the jar file # save the jar file
Line 64: Line 101:
# remove the working files # remove the working files
-rm -rf $TMP_DIR</pre>+rm -rf $TMP_DIR
 +echo "Done!"
 +</pre>
[[Category:Development]] [[Category:Development]]

Revision as of 17:55, 26 January 2005

This page is part of the extension development documentation project.

Ask your questions in MozillaZine Forums. Also try browsing example code.

Note: development documentation is in process of being moved to Mozilla Development Center (MDC).

Here is a bash script I'm using to package my extensions (under Cygwin). For Windows script see cmd build script.

#!/bin/bash
# build.sh -- builds JAR and XPI files for mozilla extensions
#   by Nickolay Ponomarev <asqueella@gmail.com>
#   based on Nathan Yergler's build script

# this script assumes the following directory structure:
# ./
#   (files listed in $ROOT_FILES)
#   content/
#   locale/
#   skin/
#   defaults/    (only if $HAS_DEFAULTS=1)
#   components/  (only if $HAS_COMPONENTS=1)
#
# It uses a temporary directory ./build; don't use that!
# Its output is:
# ./$APP_NAME.xpi
# ./$APP_NAME.jar  (only if $KEEP_JAR=1)
# ./files -- the list of packaged files

#### editable items (none of these can be blank)
APP_NAME=infolister  # short-name, jar and xpi files name.
HAS_DEFAULTS=1       # whether the ext. provides default values for user prefs etc.
HAS_COMPONENTS=1     # whether the ext. includes any components
KEEP_JAR=1           # leave the jar when done?
ROOT_FILES="license.txt install.rdf" # put these files in root of xpi
VERSION=0.8.1        # version (for preprocessor which replaces __VERSION__ in 
                     # install.rdf with $VERSION.builddate, eg 0.8.1.20050126)
#### editable items end

ROOT_DIR=`pwd`
TMP_DIR=build

#uncomment to debug
#set -x

# remove any left-over files
rm $APP_NAME.jar
rm $APP_NAME.xpi
rm files
rm -rf $TMP_DIR

mkdir --parents --verbose $TMP_DIR/chrome

# generate the JAR file, excluding CVS and temporary files
JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar
echo "Generating $JAR_FILE..."
for CHROME_SUBDIR in content locale skin; do
  find $CHROME_SUBDIR -path '*CVS*' -prune -o -type f -print | grep -v \~ >> files
done

zip -0 -r $JAR_FILE `cat files`
# The following statement should be used instead if you don't wish to use the JAR file
#cp --verbose --parents `cat files` $TMP_DIR/chrome

# prepare components and defaults
echo "Copying various files to '$TMP_DIR'..."
if [ $HAS_COMPONENTS = 1 ]; then
  mkdir $TMP_DIR/components
  COMPONENT_FILES="`find components -path '*CVS*' -prune -o -type f -print | grep -v \~`"
  echo $COMPONENT_FILES >> files
  cp --verbose --parents $COMPONENT_FILES $TMP_DIR
fi

if [ $HAS_DEFAULTS = 1 ]; then
  DEFAULT_FILES="`find defaults -path '*CVS*' -prune -o -type f -print | grep -v \~`"
  echo $DEFAULT_FILES >> files
  cp --verbose --parents $DEFAULT_FILES $TMP_DIR
fi

# Copy other files to the root of future XPI.
for ROOT_FILE in $ROOT_FILES; do
  echo $ROOT_FILE >> files
  cp --verbose $ROOT_FILE $TMP_DIR
done

cd $TMP_DIR
# Preprocess install.rdf (insert current date)
# XXX preprocess customizable set of files (about.xul)
if [ -f "install.rdf" ]; then
  echo "Preprocessing install.rdf..."
  cat install.rdf | sed s/__VERSION__/$VERSION.`date "+%Y%m%d"`/ > install.rdf
fi

# generate the XPI file
echo "Generating $APP_NAME.xpi..."
zip -r ../$APP_NAME.xpi *

cd $ROOT_DIR

echo "Cleanup..."
if [ $KEEP_JAR = 1 ]; then
  # save the jar file
  mv $TMP_DIR/chrome/$APP_NAME.jar .
fi

# remove the working files
rm -rf $TMP_DIR
echo "Done!"