Skip to content

Commit 6ceb976

Browse files
bertmaherfacebook-github-bot
authored andcommitted
Produce a single-file self-extracting script for OSS
Summary: For the benefit of Buck, homebrew, and all the users who have no idea what redex-all is, we'll now build redex as a magic self-extracting script. The script contains a bash extraction preamble followed by a tar file containing redex-all and the python wrapper (and libraries). When `redex` is invoked it untars this payload to a temp location, executes redex with the specified parameters, and then deletes the untarred payload. Differential Revision: D4401602 fbshipit-source-id: 94fa04d7a966be55ab86720c4d426ea566b562bb
1 parent b47750b commit 6ceb976

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

Makefile.am

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ libredex_la_LIBADD = \
112112
#
113113
# redex-all: the main executable
114114
#
115-
bin_PROGRAMS = redex-all redexdump
115+
bin_PROGRAMS = redexdump
116+
noinst_PROGRAMS = redex-all
116117

117118
redex_all_SOURCES = \
118119
opt/annoclasskill/AnnoClassKill.cpp \
@@ -177,11 +178,12 @@ redexdump_LDADD = \
177178
#
178179
bin_SCRIPTS = redex apkutil
179180
CLEANFILES = redex
180-
EXTRA_DIST = redex.py
181181

182-
redex: redex.py Makefile
183-
cp $(srcdir)/redex.py redex
184-
chmod +x redex
182+
PYTHON_SRCS := redex.py \
183+
pyredex/__init__.py \
184+
pyredex/log.py \
185+
pyredex/unpacker.py \
186+
pyredex/utils.py
185187

186-
install-exec-hook:
187-
cp -r $(srcdir)/pyredex $(DESTDIR)$(bindir)
188+
redex: redex-all $(PYTHON_SRCS)
189+
$(srcdir)/bundle-redex.sh

bundle-redex.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
tar czf redex.tar.gz redex-all redex.py pyredex/*.py
4+
cat selfextract.sh redex.tar.gz > redex
5+
chmod +x redex

redex.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ def run_pass(
6666
):
6767

6868
if executable_path is None:
69-
executable_path = subprocess.check_output(['which', 'redex-all']).rstrip()
70-
if executable_path is None:
71-
executable_path = join(dirname(abspath(__file__)), 'redex-all')
69+
try:
70+
executable_path = subprocess.check_output(['which', 'redex-all']).rstrip()
71+
except subprocess.CalledProcessError:
72+
pass
73+
if executable_path is None:
74+
executable_path = join(dirname(abspath(__file__)), 'redex-all')
7275
if not isfile(executable_path) or not os.access(executable_path, os.X_OK):
7376
sys.exit('redex-all is not found or is not executable')
7477
log('Running redex binary at ' + executable_path)

selfextract.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
export TMPDIR=`mktemp -d /tmp/redex.XXXXXX`
4+
ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ { print NR + 1; exit 0 }' $0`
5+
tail -n+$ARCHIVE $0 | tar xz -C $TMPDIR
6+
7+
$TMPDIR/redex.py $@
8+
9+
rm -rf $TMPDIR
10+
exit 0
11+
12+
__ARCHIVE_BELOW__

0 commit comments

Comments
 (0)