Browse files

Pack Erlang files into a zip archive

Reduces the total number of files in CouchbaseResources from 500+ to 5.
Speeds up installs and saves about 900k of disk space (though total data size is unchanged.)

Change-Id: Id404aeeefa7758c820116ebff3259d328ff65bd4
Reviewed-on: http://review.couchbase.org/9677
Reviewed-by: Aaron Miller <apage43@ninjawhale.com>
Tested-by: Aaron Miller <apage43@ninjawhale.com>
  • Loading branch information...
1 parent 0e96abd commit 5741c00d5f660e8ddd0ae9d10e2876073127f4e0 @snej snej committed with apage43 Sep 20, 2011
View
32 Framework/Classes/CouchbaseMobile.m
@@ -172,39 +172,51 @@ - (void) restart {
// Body of the pthread that runs Erlang (and CouchDB)
- (void)erlangThread {
- char* erlang_args[15] = {"beam", "--", "-noinput",
+ char* erlang_args[18] = {"beam", "--", "-noinput",
"-sasl", "errlog_type", "error", // Change "error" to "all" to re-enable progress reports
"-eval", "R = application:start(couch), io:format(\"~w~n\",[R]).",
+ "-pa", NULL, ":",
"-root", NULL, "-couch_ini", NULL, NULL, NULL, NULL};
int erlang_argc;
{
- // Alloc some paths to pass in as args to erl_start:
+ // Alloc some paths to pass in as args to erl_start.
+ // erl_root points to the root of the ZIP archive where the .beam files live.
+ // erl_extras points to the erlang dir where unzippable files (.js mostly) live.
NSAutoreleasePool* pool = [NSAutoreleasePool new];
- char* erl_root = strdup([[_bundlePath stringByAppendingPathComponent:@"erlang"]
- fileSystemRepresentation]);
- erlang_args[9] = erl_root;
+ char* erl_root = strdup([[_bundlePath stringByAppendingPathComponent:@"couchbasemobile.ez"]
+ fileSystemRepresentation]);
+ char* erl_extras = strdup([_bundlePath fileSystemRepresentation]);
+ erlang_args[9] = erl_extras;
+ erlang_args[12] = erl_root;
// Yes, there are up to four layers of .ini files: Default, iOS, app, local.
- erlang_args[11] = strdup([[_bundlePath stringByAppendingPathComponent:@"default.ini"]
+ erlang_args[14] = strdup([[_bundlePath stringByAppendingPathComponent:@"default.ini"]
fileSystemRepresentation]);
- erlang_args[12] = strdup([[_documentsDirectory stringByAppendingPathComponent:
+ erlang_args[15] = strdup([[_documentsDirectory stringByAppendingPathComponent:
@"default_ios.ini"] fileSystemRepresentation]);
- erlang_argc = 13;
+ erlang_argc = 16;
if (_iniFilePath)
erlang_args[erlang_argc++] = strdup([_iniFilePath fileSystemRepresentation]);
erlang_args[erlang_argc++] = strdup([self.localIniFilePath fileSystemRepresentation]);
// Set some environment variables for Erlang:
char erl_bin[1024];
char erl_inetrc[1024];
- sprintf(erl_bin, "%s/erts-5.7.5/bin", erl_root);
+ sprintf(erl_bin, "%s/lib/erts-5.7.5/bin", erl_root);
sprintf(erl_inetrc, "%s/erl_inetrc", erl_root);
- setenv("ROOTDIR", erl_root, 1);
+ setenv("ROOTDIR", erl_extras, 1);
setenv("BINDIR", erl_bin, 1);
setenv("ERL_INETRC", erl_inetrc, 1);
[pool drain];
}
+
+#if 0
+ fprintf(stderr, "Launching Erlang with argv: ");
+ for (int i=0; i<erlang_argc; ++i)
+ fprintf(stderr, "%s ", erlang_args[i]);
+ fprintf(stderr, "\n");
+#endif
erl_start(erlang_argc, erlang_args); // This never returns (unless Erlang exits)
}
View
4 Framework/Resources/default_ios.ini
@@ -27,10 +27,10 @@ file = $INSTALLDIR/log/couch.log
[view_server_emonk]
num_threads = 2
-mapred_js = $BUNDLEDIR/erlang/emonk_mapred.js
+mapred_js = $BUNDLEDIR/emonk_mapred.js
[app_server_emonk]
-source = $BUNDLEDIR/erlang/emonk_app.js
+source = $BUNDLEDIR/emonk_app.js
[httpd_global_handlers]
favicon.ico = {couch_httpd_misc_handlers, handle_favicon_req, "$INSTALLDIR/utils"}
View
9 Framework/Scripts/build_erlang_packages.sh
@@ -7,7 +7,7 @@
set -e # Bail out if any command returns an error
export PATH=$PATH:/usr/local/bin:/opt/local/bin # Erlang is often installed in nonstandard places
-ERLANG_DSTDIR="${CONFIGURATION_BUILD_DIR}/${CONTENTS_FOLDER_PATH}/CouchbaseResources/erlang"
+ERLANG_DSTDIR="${CONFIGURATION_BUILD_DIR}/${CONTENTS_FOLDER_PATH}/CouchbaseResources"
COMPILE=Scripts/compile_erlang_dir.sh
# First copy the checked-in erlang resources into the framework:
@@ -27,3 +27,10 @@ $COMPILE emonk/src "emonk.erl" "$ERLANG_DSTDIR/lib/emonk/ebin"
echo "Stripping .beam files..."
cd "${ERLANG_DSTDIR}"
erl -noinput -eval 'erlang:display(beam_lib:strip_release("."))' -s init stop
+
+# Archive all the Erlang files into a Zip file. (Don't compress the already-gz'd .beam files.)
+rm -f couchbasemobile.ez
+zip --test -r couchbasemobile.ez bin lib erl_inetrc \
+ --include '*.beam' '*.app' '*.appup' '*.boot' 'erl_inetrc' \
+ -n .beam
+rm -rf bin lib erl_inetrc
View
2 Framework/Scripts/concat_js_files.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-ERLANG_DSTDIR="${CONFIGURATION_BUILD_DIR}/${CONTENTS_FOLDER_PATH}/CouchbaseResources/erlang"
+ERLANG_DSTDIR="${CONFIGURATION_BUILD_DIR}/${CONTENTS_FOLDER_PATH}/CouchbaseResources"
cd ../../vendor/couchdb/share/server

0 comments on commit 5741c00

Please sign in to comment.