CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / tools / update-packaging / common.sh
blobc5b60f40c4ae49c4a5330f3963391a48235013be
1 #!/bin/bash
3 # Code shared by update packaging scripts.
4 # Author: Darin Fisher
7 # -----------------------------------------------------------------------------
8 # By default just assume that these tools exist on our path
9 MAR=${MAR:-mar}
10 BZIP2=${BZIP2:-bzip2}
11 MBSDIFF=${MBSDIFF:-mbsdiff}
13 # -----------------------------------------------------------------------------
14 # Helper routines
16 notice() {
17 echo $* 1>&2
20 get_file_size() {
21 info=($(ls -ln "$1"))
22 echo ${info[4]}
25 copy_perm() {
26 reference="$1"
27 target="$2"
29 if [ -x "$reference" ]; then
30 chmod 0755 "$target"
31 else
32 chmod 0644 "$target"
36 make_add_instruction() {
37 f="$1"
38 is_extension=$(echo "$f" | grep -c 'extensions/.*/')
39 if [ $is_extension = "1" ]; then
40 # Use the subdirectory of the extensions folder as the file to test
41 # before performing this add instruction.
42 testdir=$(echo "$f" | sed 's/\(extensions\/[^\/]*\)\/.*/\1/')
43 echo "add-if \"$testdir\" \"$f\""
44 else
45 echo "add \"$f\""
49 make_patch_instruction() {
50 f="$1"
51 is_extension=$(echo "$f" | grep -c 'extensions/.*/')
52 is_search_plugin=$(echo "$f" | grep -c 'searchplugins/.*')
53 if [ $is_extension = "1" ]; then
54 # Use the subdirectory of the extensions folder as the file to test
55 # before performing this add instruction.
56 testdir=$(echo "$f" | sed 's/\(extensions\/[^\/]*\)\/.*/\1/')
57 echo "patch-if \"$testdir\" \"$f.patch\" \"$f\""
58 elif [ $is_search_plugin = "1" ]; then
59 echo "patch-if \"$f\" \"$f.patch\" \"$f\""
60 else
61 echo "patch \"$f.patch\" \"$f\""
65 append_remove_instructions() {
66 dir="$1"
67 if [ -f "$dir/removed-files" ]; then
68 prefix=
69 listfile="$dir/removed-files"
70 elif [ -f "$dir/Contents/MacOS/removed-files" ]; then
71 prefix=Contents/MacOS/
72 listfile="$dir/Contents/MacOS/removed-files"
74 if [ -n "$listfile" ]; then
75 # Map spaces to pipes so that we correctly handle filenames with spaces.
76 files=($(cat "$listfile" | tr " " "|"))
77 num_files=${#files[*]}
78 for ((i=0; $i<$num_files; i=$i+1)); do
79 # Trim whitespace (including trailing carriage returns)
80 f=$(echo ${files[$i]} | tr "|" " " | sed 's/^ *\(.*\) *$/\1/' | tr -d '\r')
81 # Exclude any blank lines or any lines ending with a slash, which indicate
82 # directories. The updater doesn't know how to remove entire directories.
83 if [ -n "$f" ]; then
84 if [ $(echo "$f" | grep -c '\/$') = 0 ]; then
85 echo "remove \"$prefix$f\""
86 else
87 notice "ignoring remove instruction for directory: $f"
90 done
94 # List all files in the current directory, stripping leading "./"
95 # Skip the channel-prefs.js file as it should not be included in any
96 # generated MAR files (see bug 306077). Pass a variable name and it will be
97 # filled as an array.
98 list_files() {
99 count=0
101 find . -type f \
102 ! -name "channel-prefs.js" \
103 ! -name "update.manifest" \
104 ! -name "temp-filelist" \
105 | sed 's/\.\/\(.*\)/\1/' \
106 | sort > "temp-filelist"
107 while read file; do
108 eval "${1}[$count]=\"$file\""
109 (( count++ ))
110 done < "temp-filelist"
111 rm "temp-filelist"