MozillaZine

Bash build script

From MozillaZine Knowledge Base

(Difference between revisions)
Revision as of 12:01, 17 April 2005
Asqueella (Talk | contribs)
(update link)
<-- Previous diff
Revision as of 00:07, 26 April 2005
Asqueella (Talk | contribs)
(new version; including chrome.manifest preprocessing!)
Next diff -->
Line 8: Line 8:
# by Nickolay Ponomarev <asqueella@gmail.com> # by Nickolay Ponomarev <asqueella@gmail.com>
# based on Nathan Yergler's build script # based on Nathan Yergler's build script
 +# Most recent version is at <http://kb.mozillazine.org/Bash_build_script>
# this script assumes the following directory structure: # this script assumes the following directory structure:
# ./ # ./
-# (files listed in $ROOT_FILES)+# chrome.manifest (optional - for newer extensions)
-# content/+# install.rdf
-# locale/+# (other files listed in $ROOT_FILES)
-# skin/+# content/ |
 +# locale/ |} these can be named arbitrary and listed in $CHROME_PROVIDERS
 +# skin/ |
# defaults/ (only if $HAS_DEFAULTS=1) # defaults/ (only if $HAS_DEFAULTS=1)
# components/ (only if $HAS_COMPONENTS=1) # components/ (only if $HAS_COMPONENTS=1)
Line 23: Line 26:
# ./$APP_NAME.jar (only if $KEEP_JAR=1) # ./$APP_NAME.jar (only if $KEEP_JAR=1)
# ./files -- the list of packaged files # ./files -- the list of packaged files
 +#
 +# Note: It modifies chrome.manifest when packaging so that it points to
 +# chrome/$APP_NAME.jar!/*
#### editable items (none of these can be blank) #### editable items (none of these can be blank)
-APP_NAME=infolister # short-name, jar and xpi files name.+APP_NAME=helloworld # short-name, jar and xpi files name
-HAS_DEFAULTS=1 # whether the ext. provides default values for user prefs etc.+CHROME_PROVIDERS="content locale skin" # which chrome providers we have
-HAS_COMPONENTS=1 # whether the ext. includes any components+HAS_DEFAULTS=0 # whether to package defaults/
 +HAS_COMPONENTS=0 # same for components/
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="readme.txt" # 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
Line 40: Line 45:
#set -x #set -x
-# remove any left-over files+# remove any left-over files from previous build
rm $APP_NAME.jar rm $APP_NAME.jar
rm $APP_NAME.xpi rm $APP_NAME.xpi
Line 51: Line 56:
JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar
echo "Generating $JAR_FILE..." echo "Generating $JAR_FILE..."
-for CHROME_SUBDIR in content locale skin; do+for CHROME_SUBDIR in $CHROME_PROVIDERS; do
find $CHROME_SUBDIR -path '*CVS*' -prune -o -type f -print | grep -v \~ >> files find $CHROME_SUBDIR -path '*CVS*' -prune -o -type f -print | grep -v \~ >> files
done done
Line 60: Line 65:
# prepare components and defaults # prepare components and defaults
-echo "Copying various files to '$TMP_DIR'..."+echo "Copying various files to $TMP_DIR folder..."
if [ $HAS_COMPONENTS = 1 ]; then if [ $HAS_COMPONENTS = 1 ]; then
mkdir $TMP_DIR/components mkdir $TMP_DIR/components
Line 75: Line 80:
# Copy other files to the root of future XPI. # Copy other files to the root of future XPI.
-for ROOT_FILE in $ROOT_FILES; do+for ROOT_FILE in $ROOT_FILES install.rdf chrome.manifest; do
- echo $ROOT_FILE >> files+
cp --verbose $ROOT_FILE $TMP_DIR cp --verbose $ROOT_FILE $TMP_DIR
 + if [ -f $ROOT_FILE ]; then
 + echo $ROOT_FILE >> files
 + fi
done done
cd $TMP_DIR cd $TMP_DIR
-# Preprocess install.rdf (insert current date)+# XXXenh Preprocess install.rdf (insert current date)
-# XXX preprocess customizable set of files (about.xul)+# XXXenh preprocess customizable set of files (about.xul)
-if [ -f "install.rdf" ]; then+# (can't do this atm, as install.rdf at this location is now read by EM)
- echo "Preprocessing install.rdf..."+#if [ -f "install.rdf" ]; then
- cat install.rdf | sed s/__VERSION__/$VERSION.`date "+%Y%m%d"`/ > install.rdf+# echo "Preprocessing install.rdf..."
 +# cat install.rdf | sed s/__VERSION__/$VERSION.`date "+%Y%m%d"`/ > install.rdf
 +#fi
 + 
 +if [ -f "chrome.manifest" ]; then
 + echo "Preprocessing chrome.manifest..."
 + # You think this is scary?
 + #s/^(content\s+\S*\s+)(\S*\/)$/\1jar:chrome\/$APP_NAME\.jar!\/\2/
 + #s/^(skin|locale)(\s+\S*\s+\S*\s+)(.*\/)$/\1\2jar:chrome\/$APP_NAME\.jar!\/\3/
 + #
 + # Then try this! (Same, but with characters escaped for bash :)
 + sed -i -r s/^\(content\\s+\\S*\\s+\)\(\\S*\\/\)$/\\1jar:chrome\\/$APP_NAME\\.jar!\\/\\2/ chrome.manifest
 + sed -i -r s/^\(skin\|locale\)\(\\s+\\S*\\s+\\S*\\s+\)\(.*\\/\)$/\\1\\2jar:chrome\\/$APP_NAME\\.jar!\\/\\3/ chrome.manifest
 + 
 + # (it simply adds jar:chrome/whatever.jar!/ at appropriate positions of chrome.manifest)
fi fi

Revision as of 00:07, 26 April 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). See also Windows 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
# Most recent version is at <http://kb.mozillazine.org/Bash_build_script>

# this script assumes the following directory structure:
# ./
#   chrome.manifest (optional - for newer extensions)
#   install.rdf
#   (other files listed in $ROOT_FILES)
#   content/    |
#   locale/     |} these can be named arbitrary and listed in $CHROME_PROVIDERS
#   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
#
# Note: It modifies chrome.manifest when packaging so that it points to 
#       chrome/$APP_NAME.jar!/*

#### editable items (none of these can be blank)
APP_NAME=helloworld  # short-name, jar and xpi files name
CHROME_PROVIDERS="content locale skin" # which chrome providers we have
HAS_DEFAULTS=0       # whether to package defaults/
HAS_COMPONENTS=0     # same for components/
KEEP_JAR=1           # leave the jar when done?
ROOT_FILES="readme.txt" # put these files in root of xpi
#### editable items end

ROOT_DIR=`pwd`
TMP_DIR=build

#uncomment to debug
#set -x

# remove any left-over files from previous build
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 $CHROME_PROVIDERS; 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 folder..."
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 install.rdf chrome.manifest; do
  cp --verbose $ROOT_FILE $TMP_DIR
  if [ -f $ROOT_FILE ]; then
    echo $ROOT_FILE >> files
  fi
done

cd $TMP_DIR
# XXXenh Preprocess install.rdf (insert current date)
# XXXenh preprocess customizable set of files (about.xul)
# (can't do this atm, as install.rdf at this location is now read by EM)
#if [ -f "install.rdf" ]; then
#  echo "Preprocessing install.rdf..."
#  cat install.rdf | sed s/__VERSION__/$VERSION.`date "+%Y%m%d"`/ > install.rdf
#fi

if [ -f "chrome.manifest" ]; then
  echo "Preprocessing chrome.manifest..."
  # You think this is scary?
  #s/^(content\s+\S*\s+)(\S*\/)$/\1jar:chrome\/$APP_NAME\.jar!\/\2/
  #s/^(skin|locale)(\s+\S*\s+\S*\s+)(.*\/)$/\1\2jar:chrome\/$APP_NAME\.jar!\/\3/
  #
  # Then try this! (Same, but with characters escaped for bash :)
  sed -i -r s/^\(content\\s+\\S*\\s+\)\(\\S*\\/\)$/\\1jar:chrome\\/$APP_NAME\\.jar!\\/\\2/ chrome.manifest
  sed -i -r s/^\(skin\|locale\)\(\\s+\\S*\\s+\\S*\\s+\)\(.*\\/\)$/\\1\\2jar:chrome\\/$APP_NAME\\.jar!\\/\\3/ chrome.manifest

  # (it simply adds jar:chrome/whatever.jar!/ at appropriate positions of chrome.manifest)
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!"