diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-12-09 19:55:03 +0300 |
---|---|---|
committer | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-12-09 19:55:03 +0300 |
commit | 3d15539efe301bb47250169fc97b72d8f634823f (patch) | |
tree | 15a81fe0541b7b444a3d84604d2ac3e7c06abaa0 /main | |
parent | bd26ad70c68c6f41e21beafdbb359e17134fb860 (diff) | |
parent | 1415c31d14f116f716455f10ca902e288df347da (diff) |
Merge remote-tracking branch 'origin/cycle6_create_dyld_library_correctly' into cycle6
Diffstat (limited to 'main')
-rw-r--r-- | main/build/MacOSX/monostub-test.m | 2 | ||||
-rw-r--r-- | main/build/MacOSX/monostub-utils.h | 49 |
2 files changed, 34 insertions, 17 deletions
diff --git a/main/build/MacOSX/monostub-test.m b/main/build/MacOSX/monostub-test.m index afae4b2f76..b9f76cd0a9 100644 --- a/main/build/MacOSX/monostub-test.m +++ b/main/build/MacOSX/monostub-test.m @@ -145,7 +145,7 @@ void test_push_env(void) if (current->initial) setenv(current->var, current->initial, 1); - check_bool_equal(current->expected, push_env(current->var, current->to_find)); + check_bool_equal(current->expected, push_env_to_start(current->var, current->to_find)); check_string_equal(current->updated, getenv(current->var)); } } diff --git a/main/build/MacOSX/monostub-utils.h b/main/build/MacOSX/monostub-utils.h index 5fa69c7e34..4e5a4418f7 100644 --- a/main/build/MacOSX/monostub-utils.h +++ b/main/build/MacOSX/monostub-utils.h @@ -113,7 +113,7 @@ env2bool (const char *env, bool defaultValue) } static bool -push_env (const char *variable, const char *value) +push_env (const char *variable, const char *value, BOOL push_to_end) { const char *current; size_t len; @@ -122,8 +122,10 @@ push_env (const char *variable, const char *value) if ((current = getenv (variable)) && *current) { char *token, *copy, *tofree; + size_t current_length; tofree = copy = strdup (current); + current_length = strlen (current); len = strlen (value); while ((token = strsep(©, ":"))) { if (!strncmp (token, value, len)) { @@ -135,12 +137,18 @@ push_env (const char *variable, const char *value) } } - if (!(buf = malloc (len + strlen (current) + 2))) + if (!(buf = malloc (len + current_length + 2))) return NO; - - memcpy (buf, value, len); - buf[len] = ':'; - strcpy (buf + len + 1, current); + + if (push_to_end) { + memcpy (buf, current, current_length); + buf[current_length] = ':'; + strcpy (buf + current_length + 1, value); + } else { + memcpy (buf, value, len); + buf[len] = ':'; + strcpy (buf + len + 1, current); + } setenv (variable, buf, 1); free (buf); done: @@ -149,9 +157,6 @@ done: setenv (variable, value, 1); } - //if (updated) - // printf ("Updated the %s environment variable with '%s'.\n", variable, value); - return updated; } @@ -168,6 +173,18 @@ replace_env (const char *variable, const char *value) } static bool +push_env_to_start (const char *variable, const char *value) +{ + return push_env (variable, value, NO); +} + +static bool +push_env_to_end (const char *variable, const char *value) +{ + return push_env (variable, value, YES); +} + +static bool update_environment (const char *contentsDir) { bool updated = NO; @@ -177,33 +194,33 @@ update_environment (const char *contentsDir) char *token; while ((token = strsep(&value, ":"))) { - if (push_env ("DYLD_FALLBACK_LIBRARY_PATH", token)) + if (push_env_to_end ("DYLD_FALLBACK_LIBRARY_PATH", token)) updated = YES; } free (value); } - if (push_env ("PKG_CONFIG_PATH", "/Library/Frameworks/Mono.framework/External/pkgconfig")) + if (push_env_to_start ("PKG_CONFIG_PATH", "/Library/Frameworks/Mono.framework/External/pkgconfig")) updated = YES; /* Enable the use of stuff bundled into the app bundle and the Mono "External" directory */ if ((value = str_append (contentsDir, "/Resources/lib/pkgconfig"))) { - if (push_env ("PKG_CONFIG_PATH", value)) + if (push_env_to_start ("PKG_CONFIG_PATH", value)) updated = YES; free (value); } if ((value = str_append (contentsDir, "/Resources"))) { - if (push_env ("MONO_GAC_PREFIX", value)) + if (push_env_to_start ("MONO_GAC_PREFIX", value)) updated = YES; free (value); } if ((value = str_append (contentsDir, "/MacOS"))) { - if (push_env ("PATH", value)) + if (push_env_to_start ("PATH", value)) updated = YES; free (value); @@ -212,13 +229,13 @@ update_environment (const char *contentsDir) // Note: older versions of Xamarin Studio incorrectly set the PATH to the Resources dir instead of the MacOS dir // and older versions of mtouch relied on this broken behavior. if ((value = str_append (contentsDir, "/Resources"))) { - if (push_env ("PATH", value)) + if (push_env_to_start ("PATH", value)) updated = YES; free (value); } - if (push_env ("PATH", "/Library/Frameworks/Mono.framework/Commands")) + if (push_env_to_start ("PATH", "/Library/Frameworks/Mono.framework/Commands")) updated = YES; if (replace_env ("LC_NUMERIC", "C")) |