Skip to content

Commit 7aaefaa

Browse files
committed
Add the ability to specify multiple mono search path in the config
1 parent 710cef8 commit 7aaefaa

File tree

6 files changed

+56
-18
lines changed

6 files changed

+56
-18
lines changed

CHANGES.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,3 @@ The change was made for two reasons:
7474

7575
* Doorstop does not need to pass any arguments anymore. Instead, Doorstop passes all the information via environment variables.
7676
* CoreCLR does not support easy method searching using wildcards yet.
77-
78-
## *Possibly* breaking: `target_assembly` directory is now always added to mono search path
79-
80-
In UnityDoorstop 3.x, the tool only loaded the `target_assembly` and left any other assembly resolving to the target assembly code.
81-
**Starting Doorstop 4, `target_assembly`'s parent directory is set to mono DLL search path.**
82-
83-
This means that any additional assemblies that are placed into the same directory as `target_assembly` will receive priority during assembly resolving.
84-
Note that this option for now only affects UnityMono as there is no similar search path priority available via current CoreCLR C hosting API.

assets/nix/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ignore_disable_switch="0"
3636
# (e.g. mscorlib is stripped in original game)
3737
# This option causes Mono to seek mscorlib and core libraries from a different folder before Managed
3838
# Original Managed folder is added as a secondary folder in the search path
39+
# To specify multiple paths, separate them with colons (:)
3940
dll_search_path_override=""
4041

4142
# If 1, Mono debugger server will be enabled

assets/windows/doorstop_config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ignore_disable_switch=false
2424
# (e.g. mscorlib is stripped in original game)
2525
# This option causes Mono to seek mscorlib and core libraries from a different folder before Managed
2626
# Original Managed folder is added as a secondary folder in the search path
27+
# To specify multiple paths, separate them with semicolons (;)
2728
dll_search_path_override=
2829

2930
# If true, Mono debugger server will be enabled

src/bootstrap.c

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,60 @@ void *init_mono(const char *root_domain_name, const char *runtime_version) {
136136
size_t mono_search_path_len = strlen(root_dir) + 1;
137137

138138
char_t *override_dir_full = NULL;
139-
bool_t has_override = config.mono_dll_search_path_override &&
140-
strlen(config.mono_dll_search_path_override);
139+
char_t *config_path_value = config.mono_dll_search_path_override;
140+
bool_t has_override = config_path_value && strlen(config_path_value);
141141
if (has_override) {
142-
override_dir_full = get_full_path(config.mono_dll_search_path_override);
142+
size_t path_start = 0;
143+
override_dir_full = calloc(MAX_PATH, sizeof(char_t));
144+
memset(override_dir_full, 0, MAX_PATH * sizeof(char_t));
145+
146+
bool_t found_path = FALSE;
147+
for (size_t i = 0; i <= strlen(config_path_value); i++) {
148+
char_t current_char = config_path_value[i];
149+
if (current_char == *PATH_SEP || current_char == 0) {
150+
if (i <= path_start) {
151+
path_start++;
152+
continue;
153+
}
154+
155+
size_t path_len = i - path_start;
156+
char_t *path = calloc(path_len + 1, sizeof(char_t));
157+
strncpy(path, config_path_value + path_start, path_len);
158+
path[path_len] = 0;
159+
160+
char_t *full_path = get_full_path(path);
161+
162+
if (strlen(override_dir_full) + strlen(full_path) + 2 >
163+
MAX_PATH) {
164+
LOG("Ignoring this root path because its absolute version "
165+
"is too long: %s",
166+
full_path);
167+
free(path);
168+
free(full_path);
169+
path_start = i + 1;
170+
continue;
171+
}
172+
173+
if (found_path) {
174+
strcat(override_dir_full, PATH_SEP);
175+
}
176+
177+
strcat(override_dir_full, full_path);
178+
LOG("Adding root path: %s", full_path);
179+
180+
free(path);
181+
free(full_path);
182+
183+
found_path = TRUE;
184+
path_start = i + 1;
185+
}
186+
}
187+
143188
mono_search_path_len += strlen(override_dir_full) + 1;
144-
LOG("Adding root path: %s", override_dir_full);
145189
}
146190

147191
char_t *mono_search_path = calloc(mono_search_path_len + 1, sizeof(char_t));
148-
if (has_override) {
192+
if (override_dir_full && strlen(override_dir_full)) {
149193
strcat(mono_search_path, override_dir_full);
150194
strcat(mono_search_path, PATH_SEP);
151195
}

src/nix/config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ void load_config() {
3737
try_get_env("DOORSTOP_MONO_DEBUG_ADDRESS", TEXT("127.0.0.1:10000"),
3838
&config.mono_debug_address);
3939
get_env_path("DOORSTOP_TARGET_ASSEMBLY", &config.target_assembly);
40-
get_env_path("DOORSTOP_MONO_DLL_SEARCH_PATH_OVERRIDE",
41-
&config.mono_dll_search_path_override);
40+
try_get_env("DOORSTOP_MONO_DLL_SEARCH_PATH_OVERRIDE", TEXT(""),
41+
&config.mono_dll_search_path_override);
4242
get_env_path("DOORSTOP_CLR_RUNTIME_CORECLR_PATH",
4343
&config.clr_runtime_coreclr_path);
4444
get_env_path("DOORSTOP_CLR_CORLIB_DIR", &config.clr_corlib_dir);

src/windows/config.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ static inline void init_config_file() {
7272
load_path_file(config_path, TEXT("General"), TEXT("target_assembly"),
7373
DEFAULT_TARGET_ASSEMBLY, &config.target_assembly);
7474

75-
load_path_file(config_path, TEXT("UnityMono"),
76-
TEXT("dll_search_path_override"), NULL,
77-
&config.mono_dll_search_path_override);
75+
load_str_file(config_path, TEXT("UnityMono"),
76+
TEXT("dll_search_path_override"), TEXT(""),
77+
&config.mono_dll_search_path_override);
7878
load_bool_file(config_path, TEXT("UnityMono"), TEXT("debug_enabled"),
7979
TEXT("false"), &config.mono_debug_enabled);
8080
load_bool_file(config_path, TEXT("UnityMono"), TEXT("debug_suspend"),

0 commit comments

Comments
 (0)