Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ If you are *not* using a node version manager like [nvm](https://github.com/crea
-c, --detect only detect if the device is connected
-b, --bundle <bundle.app> the path to the app bundle to be installed
-a, --args <args> command line arguments to pass to the app when launching it
-s, --envs <envs> environment variables, space separated key-value pairs, to pass to the app when launching it
-t, --timeout <timeout> number of seconds to wait for a device to be connected
-u, --unbuffered don't buffer stdout
-n, --nostart do not start the app when debugging
Expand Down Expand Up @@ -95,6 +96,9 @@ The commands below assume that you have an app called `my.app` with bundle id `b
// deploy and debug your app to a connected device
ios-deploy --debug --bundle my.app

// deploy, debug and pass environment variables to a connected device
ios-deploy --debug --envs DYLD_PRINT_STATISTICS=1 --bundle my.app

// deploy and debug your app to a connected device, skipping any wi-fi connection (use USB)
ios-deploy --debug --bundle my.app --no-wifi

Expand Down
24 changes: 23 additions & 1 deletion src/ios-deploy/ios-deploy.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
char *app_path = NULL;
char *device_id = NULL;
char *args = NULL;
char *envs = NULL;
char *list_root = NULL;
int _timeout = 0;
int _detectDeadlockTimeout = 0;
Expand Down Expand Up @@ -651,6 +652,22 @@ void write_lldb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) {
//printf("write_lldb_prep_cmds: [%s][%s]\n", CFStringGetCStringPtr (cmds,kCFStringEncodingMacRoman),
// CFStringGetCStringPtr(pmodule, kCFStringEncodingMacRoman));
}

if (envs) {
CFStringRef cf_envs = CFStringCreateWithCString(NULL, envs, kCFStringEncodingUTF8);
CFStringFindAndReplace(cmds, CFSTR("{envs}"), cf_envs, range, 0);
rangeLLDB.length = CFStringGetLength(pmodule);
CFStringFindAndReplace(pmodule, CFSTR("{envs}"), cf_envs, rangeLLDB, 0);

//printf("write_lldb_prep_cmds:envs: [%s][%s]\n", CFStringGetCStringPtr (cmds,kCFStringEncodingMacRoman),
// CFStringGetCStringPtr(pmodule, kCFStringEncodingMacRoman));
CFRelease(cf_envs);
} else {
CFStringFindAndReplace(cmds, CFSTR("{envs}"), CFSTR(""), range, 0);
CFStringFindAndReplace(pmodule, CFSTR("{envs}"), CFSTR(""), rangeLLDB, 0);
//printf("write_lldb_prep_cmds: [%s][%s]\n", CFStringGetCStringPtr (cmds,kCFStringEncodingMacRoman),
// CFStringGetCStringPtr(pmodule, kCFStringEncodingMacRoman));
}
range.length = CFStringGetLength(cmds);

CFStringRef bundle_identifier = copy_disk_app_identifier(disk_app_url);
Expand Down Expand Up @@ -1731,6 +1748,7 @@ void usage(const char* app) {
@" -c, --detect only detect if the device is connected\n"
@" -b, --bundle <bundle.app> the path to the app bundle to be installed\n"
@" -a, --args <args> command line arguments to pass to the app when launching it\n"
@" -s, --envs <envs> environment variables, space separated key-value pairs, to pass to the app when launching it\n"
@" -t, --timeout <timeout> number of seconds to wait for a device to be connected\n"
@" -u, --unbuffered don't buffer stdout\n"
@" -n, --nostart do not start the app when debugging\n"
Expand Down Expand Up @@ -1776,6 +1794,7 @@ int main(int argc, char *argv[]) {
{ "id", required_argument, NULL, 'i' },
{ "bundle", required_argument, NULL, 'b' },
{ "args", required_argument, NULL, 'a' },
{ "envs", required_argument, NULL, 's' },
{ "verbose", no_argument, NULL, 'v' },
{ "timeout", required_argument, NULL, 't' },
{ "unbuffered", no_argument, NULL, 'u' },
Expand Down Expand Up @@ -1804,7 +1823,7 @@ int main(int argc, char *argv[]) {
};
int ch;

while ((ch = getopt_long(argc, argv, "VmcdvunNrILeD:R:i:b:a:t:g:x:p:1:2:o:l::w::9::B::W", longopts, NULL)) != -1)
while ((ch = getopt_long(argc, argv, "VmcdvunNrILeD:R:i:b:a:s:t:g:x:p:1:2:o:l::w::9::B::W", longopts, NULL)) != -1)
{
switch (ch) {
case 'm':
Expand All @@ -1823,6 +1842,9 @@ int main(int argc, char *argv[]) {
case 'a':
args = optarg;
break;
case 's':
envs = optarg;
break;
case 'v':
verbose = true;
break;
Expand Down
6 changes: 6 additions & 0 deletions src/scripts/lldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def run_command(debugger, command, result, internal_dict):
#This env variable makes NSLog, CFLog and os_log messages get mirrored to stderr
#https://stackoverflow.com/a/39581193
launchInfo.SetEnvironmentEntries(['OS_ACTIVITY_DT_MODE=enable'], True)

envs_arr = []
if len(args) > 1:
envs_arr = shlex.split(args[1])
envs_arr = envs_arr + shlex.split('{envs}')
launchInfo.SetEnvironmentEntries(envs_arr, True)

lldb.target.Launch(launchInfo, error)
lockedstr = ': Locked'
Expand Down