This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Correctly quote result from adb, otherwise multiline responses breal (eg signal_cmd)
[perl5.git] / hints / linux-android.sh
1 # set -x
2
3 userelocatableinc='define'
4
5 # On Android the shell is /system/bin/sh:
6 targetsh='/system/bin/sh'
7
8 # Down with locales!
9 # https://github.com/android/platform_bionic/blob/master/libc/CAVEATS
10 d_locconv='undef'
11 d_setlocale='undef'
12 d_setlocale_r='undef'
13 i_locale='undef'
14
15
16 case "$src" in
17     /*) run=$src/Cross/run
18             targetmkdir=$src/Cross/mkdir
19             to=$src/Cross/to
20             from=$src/Cross/from
21             ;;
22     *)  pwd=`test -f ../Configure && cd ..; pwd`
23             run=$pwd/Cross/run
24             targetmkdir=$pwd/Cross/mkdir
25             to=$pwd/Cross/to
26             from=$pwd/Cross/from
27                ;;
28 esac
29     
30 targetrun=adb-shell
31 targetto=adb-push
32 targetfrom=adb-pull
33 run=$run-$targetrun
34 to=$to-$targetto
35 from=$from-$targetfrom
36
37 cat >$run <<EOF
38 #!/bin/sh
39 doexit="echo \\\$?"
40 env=''
41 case "\$1" in
42 -cwd)
43   shift
44   cwd=\$1
45   shift
46   ;;
47 esac
48 case "\$1" in
49 -env)
50   shift
51   env=\$1
52   shift
53   ;;
54 esac
55 case "\$cwd" in
56 '') cwd=$targetdir ;;
57 esac
58 case "\$env" in
59 '') env="echo "
60 esac
61 exe=\$1
62 shift
63 args=\$@
64 $to \$exe > /dev/null 2>&1
65
66 # send copy results to /dev/null as otherwise it outputs speed stats which gets in our way.
67 # sometimes there is no $?, I dunno why? we then get Cross/run-adb-shell: line 39: exit: XX: numeric argument required
68 foo=\`adb -s $targethost shell "sh -c '(cd \$cwd && \$env ; \$exe \$args) > $targetdir/output.stdout ; \$doexit '"\`
69 # We get back Ok\r\n on android for some reason, grrr:
70 $from output.stdout
71 result=\`cat output.stdout\`
72 rm output.stdout
73 result=\`echo "\$result" | sed -e 's|\r||g'\`
74 foo=\`echo \$foo | sed -e 's|\r||g'\`
75 # Also, adb doesn't exit with the commands exit code, like ssh does, double-grr
76 echo "\$result"
77 exit \$foo
78
79 EOF
80 chmod a+rx $run
81
82 cat >$targetmkdir <<EOF
83 #!/bin/sh
84 adb -s $targethost shell "mkdir -p \$@"
85 EOF
86 chmod a+rx $targetmkdir
87
88 cat >$to <<EOF
89 #!/bin/sh
90 for f in \$@
91 do
92   case "\$f" in
93   /*)
94     $targetmkdir \`dirname \$f\`
95     adb -s $targethost push \$f \$f            || exit 1
96     ;;
97   *)
98     $targetmkdir $targetdir/\`dirname \$f\`
99     (adb -s $targethost push \$f $targetdir/\$f < /dev/null 2>&1) || exit 1
100     ;;
101   esac
102 done
103 exit 0
104 EOF
105 chmod a+rx $to
106
107 cat >$from <<EOF
108 #!/bin/sh
109 for f in \$@
110 do
111   $rm -f \$f
112   (adb -s $targethost pull $targetdir/\$f . > /dev/null 2>&1) || exit 1
113 done
114 exit 0
115 EOF
116 chmod a+rx $from
117