Skip to content

Commit

Permalink
[mkbundle] Automatically bundle config files and machine.config files (
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
migueldeicaza authored and marek-safar committed Feb 15, 2018
1 parent b90d8ec commit 3bd630e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
29 changes: 24 additions & 5 deletions man/mkbundle.1
Expand Up @@ -111,10 +111,11 @@ directory.
.SH OPTIONS
.TP
.I "--config FILE"
Specifies that a machine.config file must be bundled as well.
Typically this is $prefix/etc/mono/1.0/machine.config or
$prefix/etc/mono/2.0/machine.config depending on the profile that you
are using (1.0 or 2.0)
Specifies that a DLLMAP Mono config file must be bundled as well. In
the simple and cross compiler modes, if no config file is specified
the one for the current target is picked (either the system one in the
case of the simple mode, or the one that came from the cross
compilation target for the cross compiling mode).
.TP
.I "--config-dir DIR"
When passed, DIR will be set for the MONO_CFG_DIR environment variable
Expand Down Expand Up @@ -202,13 +203,31 @@ Provides mkbundle access to a managed linker to preprocess the assemblies.
.TP
.I "--machine-config FILE"
Uses the given FILE as the machine.config file for the generated
application.
application. The machine config contains an XML file that is used by
System.Configuration APIs to configure the .NET stack. Typically this
is
.I $prefix/etc/mono/4.5/machine.config.
.Sp
If you want to disable this automatic bundling, you can use the
.I "--no-machine-config"
flag. In the simple and cross compiler modes, if no machine.config file is specified
the one for the current target is picked (either the system one in the
case of the simple mode, or the one that came from the cross
compilation target for the cross compiling mode).
.TP
.I "--no-config"
In simple or cross compiling mode, this prevents mkbundle from
automatically bundling a config file.
.TP
.I "--nodeps"
This is the default: \fImkbundle\fP will only include the assemblies that
were specified on the command line to reduce the size of the resulting
image created.
.TP
.I "--no-machine-config"
In simple or cross compiling mode, this prevents mkbundle from
automatically bundling a machine.config file.
.TP
.I "-o filename"
Places the output on `out'. If the flag -c is specified, this is the
C host program. If not, this contains the resulting executable.
Expand Down
35 changes: 32 additions & 3 deletions mcs/tools/mkbundle/mkbundle.cs
Expand Up @@ -48,8 +48,19 @@ class MakeBundle {
static bool keeptemp = false;
static bool compile_only = false;
static bool static_link = false;
static string config_file = null;

// Points to the $sysconfig/mono/4.5/machine.config, which contains System.Configuration settings
static string machine_config_file = null;

// By default, we automatically bundle a machine-config, use this to turn off the behavior.
static bool no_machine_config = false;

// Points to the $sysconfig/mono/config file, contains <dllmap> and others
static string config_file = null;

// By default, we automatically bundle the above config file, use this to turn off the behavior.
static bool no_config = false;

static string config_dir = null;
static string style = "linux";
static bool bundled_header = false;
Expand All @@ -65,7 +76,7 @@ class MakeBundle {
static string fetch_target = null;
static bool custom_mode = true;
static string embedded_options = null;

static string runtime = null;

static bool aot_compile = false;
Expand Down Expand Up @@ -148,7 +159,7 @@ static int Main (string [] args)
return 1;
}
if (sdk_path != null || runtime != null)
Error ("You can only specify one of --runtime, --sdk or --cross");
Error ("You can only specify one of --runtime, --sdk or --cross {sdk_path}/{runtime}");
custom_mode = false;
autodeps = true;
cross_target = args [++i];
Expand Down Expand Up @@ -289,6 +300,12 @@ static int Main (string [] args)
if (!quiet)
Console.WriteLine ("WARNING:\n Check that the machine.config file you are bundling\n doesn't contain sensitive information specific to this machine.");
break;
case "--no-machine-config":
no_machine_config = true;
break;
case "--no-config":
no_config = true;
break;
case "--config-dir":
if (i+1 == top) {
Help ();
Expand Down Expand Up @@ -523,6 +540,18 @@ static void VerifySdk (string path)
if (!Directory.Exists (lib_path))
Error ($"The SDK location does not contain a {path}/lib/mono/4.5 directory");
link_paths.Add (lib_path);
if (machine_config_file == null && !no_machine_config) {
machine_config_file = Path.Combine (path, "etc", "mono", "4.5", "machine.config");
if (!File.Exists (machine_config_file)){
Error ($"Could not locate the file machine.config file at ${machine_config_file} use --machine-config FILE or --no-machine-config");
}
}
if (config_file == null && !no_config) {
config_file = Path.Combine (path, "etc", "mono", "config");
if (!File.Exists (config_file)){
Error ($"Could not locate the file config file at ${config_file} use --config FILE or --no-config");
}
}
}

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

0 comments on commit 3bd630e

Please sign in to comment.