Skip to content

Commit 3bd630e

Browse files
migueldeicazamarek-safar
authored andcommitted
[mkbundle] Automatically bundle config files and machine.config files (mono#7002)
* [mkbundle] Automatically bundle config files and machine.config files for the simple/cross compiler scenario, fixes one of the missing issues for mono#6230
1 parent b90d8ec commit 3bd630e

2 files changed

Lines changed: 56 additions & 8 deletions

File tree

man/mkbundle.1

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ directory.
111111
.SH OPTIONS
112112
.TP
113113
.I "--config FILE"
114-
Specifies that a machine.config file must be bundled as well.
115-
Typically this is $prefix/etc/mono/1.0/machine.config or
116-
$prefix/etc/mono/2.0/machine.config depending on the profile that you
117-
are using (1.0 or 2.0)
114+
Specifies that a DLLMAP Mono config file must be bundled as well. In
115+
the simple and cross compiler modes, if no config file is specified
116+
the one for the current target is picked (either the system one in the
117+
case of the simple mode, or the one that came from the cross
118+
compilation target for the cross compiling mode).
118119
.TP
119120
.I "--config-dir DIR"
120121
When passed, DIR will be set for the MONO_CFG_DIR environment variable
@@ -202,13 +203,31 @@ Provides mkbundle access to a managed linker to preprocess the assemblies.
202203
.TP
203204
.I "--machine-config FILE"
204205
Uses the given FILE as the machine.config file for the generated
205-
application.
206+
application. The machine config contains an XML file that is used by
207+
System.Configuration APIs to configure the .NET stack. Typically this
208+
is
209+
.I $prefix/etc/mono/4.5/machine.config.
210+
.Sp
211+
If you want to disable this automatic bundling, you can use the
212+
.I "--no-machine-config"
213+
flag. In the simple and cross compiler modes, if no machine.config file is specified
214+
the one for the current target is picked (either the system one in the
215+
case of the simple mode, or the one that came from the cross
216+
compilation target for the cross compiling mode).
217+
.TP
218+
.I "--no-config"
219+
In simple or cross compiling mode, this prevents mkbundle from
220+
automatically bundling a config file.
206221
.TP
207222
.I "--nodeps"
208223
This is the default: \fImkbundle\fP will only include the assemblies that
209224
were specified on the command line to reduce the size of the resulting
210225
image created.
211226
.TP
227+
.I "--no-machine-config"
228+
In simple or cross compiling mode, this prevents mkbundle from
229+
automatically bundling a machine.config file.
230+
.TP
212231
.I "-o filename"
213232
Places the output on `out'. If the flag -c is specified, this is the
214233
C host program. If not, this contains the resulting executable.

mcs/tools/mkbundle/mkbundle.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,19 @@ class MakeBundle {
4848
static bool keeptemp = false;
4949
static bool compile_only = false;
5050
static bool static_link = false;
51-
static string config_file = null;
51+
52+
// Points to the $sysconfig/mono/4.5/machine.config, which contains System.Configuration settings
5253
static string machine_config_file = null;
54+
55+
// By default, we automatically bundle a machine-config, use this to turn off the behavior.
56+
static bool no_machine_config = false;
57+
58+
// Points to the $sysconfig/mono/config file, contains <dllmap> and others
59+
static string config_file = null;
60+
61+
// By default, we automatically bundle the above config file, use this to turn off the behavior.
62+
static bool no_config = false;
63+
5364
static string config_dir = null;
5465
static string style = "linux";
5566
static bool bundled_header = false;
@@ -65,7 +76,7 @@ class MakeBundle {
6576
static string fetch_target = null;
6677
static bool custom_mode = true;
6778
static string embedded_options = null;
68-
79+
6980
static string runtime = null;
7081

7182
static bool aot_compile = false;
@@ -148,7 +159,7 @@ static int Main (string [] args)
148159
return 1;
149160
}
150161
if (sdk_path != null || runtime != null)
151-
Error ("You can only specify one of --runtime, --sdk or --cross");
162+
Error ("You can only specify one of --runtime, --sdk or --cross {sdk_path}/{runtime}");
152163
custom_mode = false;
153164
autodeps = true;
154165
cross_target = args [++i];
@@ -289,6 +300,12 @@ static int Main (string [] args)
289300
if (!quiet)
290301
Console.WriteLine ("WARNING:\n Check that the machine.config file you are bundling\n doesn't contain sensitive information specific to this machine.");
291302
break;
303+
case "--no-machine-config":
304+
no_machine_config = true;
305+
break;
306+
case "--no-config":
307+
no_config = true;
308+
break;
292309
case "--config-dir":
293310
if (i+1 == top) {
294311
Help ();
@@ -523,6 +540,18 @@ static void VerifySdk (string path)
523540
if (!Directory.Exists (lib_path))
524541
Error ($"The SDK location does not contain a {path}/lib/mono/4.5 directory");
525542
link_paths.Add (lib_path);
543+
if (machine_config_file == null && !no_machine_config) {
544+
machine_config_file = Path.Combine (path, "etc", "mono", "4.5", "machine.config");
545+
if (!File.Exists (machine_config_file)){
546+
Error ($"Could not locate the file machine.config file at ${machine_config_file} use --machine-config FILE or --no-machine-config");
547+
}
548+
}
549+
if (config_file == null && !no_config) {
550+
config_file = Path.Combine (path, "etc", "mono", "config");
551+
if (!File.Exists (config_file)){
552+
Error ($"Could not locate the file config file at ${config_file} use --config FILE or --no-config");
553+
}
554+
}
526555
}
527556

528557
static string targets_dir = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".mono", "targets");

0 commit comments

Comments
 (0)