blob: 9f05394d3af3d026ca6a8d24542d61f8f406a6b9 [file] [log] [blame]
Colin Crossb852a582017-08-10 17:58:12 -07001#!/bin/bash -e
2
3# Script that takes a list of files on stdin and converts it to arguments to jar on stdout
4# Usage:
5# find $dir -type f | sort | jar-args.sh $dir > jar_args.txt
6# jar cf out.jar @jar_args.txt
7
8case $(uname) in
9 Linux)
10 extended_re=-r
11 ;;
12 Darwin)
13 extended_re=-E
14 ;;
15 *) echo "unknown OS:" $(uname) >&2 && exit 1;;
16esac
17
18if [ "$1" == "--test" ]; then
19 in=$(mktemp)
20 expected=$(mktemp)
21 out=$(mktemp)
22 cat > $in <<EOF
23a
24a/b
25a/b/'
26a/b/"
27a/b/\\
28a/b/#
29a/b/a
30EOF
31 cat > $expected <<EOF
32
33-C 'a' 'b'
34-C 'a' 'b/\\''
35-C 'a' 'b/"'
36-C 'a' 'b/\\\\'
37-C 'a' 'b/#'
38-C 'a' 'b/a'
39EOF
40 cat $in | $0 a > $out
41
42 if cmp $out $expected; then
43 status=0
44 echo "PASS"
45 else
46 status=1
47 echo "FAIL"
48 echo "got:"
49 cat $out
50 echo "expected:"
51 cat $expected
52 fi
53 rm -f $in $expected $out
54 exit $status
55fi
56
57# In order, the regexps:
58# - Strip $1/ from the beginning of each line, and everything from lines that just have $1
59# - Escape single and double quotes, '#', ' ', and '\'
60# - Prefix each non-blank line with -C $1
61sed ${extended_re} \
62 -e"s,^$1(/|\$),," \
63 -e"s,(['\\]),\\\\\1,g" \
64 -e"s,^(.+),-C '$1' '\1',"