Add --runtimeconfig to the hostfxr, and use this option for the xunit scenario.

This commit is contained in:
Bryan Thornbury 2016-04-07 16:20:51 -07:00 committed by Eric Erhardt
parent 6fa859a354
commit 34d2445916
8 changed files with 51 additions and 39 deletions

View file

@ -17,7 +17,8 @@ namespace Microsoft.DotNet.Cli.Utils
IEnumerable<string> allowedExtensions, IEnumerable<string> allowedExtensions,
string nugetPackagesRoot, string nugetPackagesRoot,
CommandResolutionStrategy commandResolutionStrategy, CommandResolutionStrategy commandResolutionStrategy,
string depsFilePath); string depsFilePath,
string runtimeConfigPath);
} }
} }

View file

@ -17,7 +17,8 @@ namespace Microsoft.DotNet.Cli.Utils
IEnumerable<string> allowedExtensions, IEnumerable<string> allowedExtensions,
string nugetPackagesRoot, string nugetPackagesRoot,
CommandResolutionStrategy commandResolutionStrategy, CommandResolutionStrategy commandResolutionStrategy,
string depsFilePath) string depsFilePath,
string runtimeConfigPath)
{ {
var toolAssembly = toolLibrary?.RuntimeAssemblies var toolAssembly = toolLibrary?.RuntimeAssemblies
@ -35,7 +36,7 @@ namespace Microsoft.DotNet.Cli.Utils
return null; return null;
} }
var isPortable = IsPortableApp(commandPath); var isPortable = IsPortableApp(commandPath, runtimeConfigPath);
return CreateCommandSpecWrappingWithCorehostIfDll( return CreateCommandSpecWrappingWithCorehostIfDll(
commandPath, commandPath,
@ -43,7 +44,8 @@ namespace Microsoft.DotNet.Cli.Utils
depsFilePath, depsFilePath,
commandResolutionStrategy, commandResolutionStrategy,
nugetPackagesRoot, nugetPackagesRoot,
isPortable); isPortable,
runtimeConfigPath);
} }
private string GetCommandFilePath(string nugetPackagesRoot, LockFileTargetLibrary toolLibrary, LockFileItem runtimeAssembly) private string GetCommandFilePath(string nugetPackagesRoot, LockFileTargetLibrary toolLibrary, LockFileItem runtimeAssembly)
@ -62,7 +64,8 @@ namespace Microsoft.DotNet.Cli.Utils
string depsFilePath, string depsFilePath,
CommandResolutionStrategy commandResolutionStrategy, CommandResolutionStrategy commandResolutionStrategy,
string nugetPackagesRoot, string nugetPackagesRoot,
bool isPortable) bool isPortable,
string runtimeConfigPath)
{ {
var commandExtension = Path.GetExtension(commandPath); var commandExtension = Path.GetExtension(commandPath);
@ -74,7 +77,8 @@ namespace Microsoft.DotNet.Cli.Utils
depsFilePath, depsFilePath,
commandResolutionStrategy, commandResolutionStrategy,
nugetPackagesRoot, nugetPackagesRoot,
isPortable); isPortable,
runtimeConfigPath);
} }
return CreateCommandSpec(commandPath, commandArguments, commandResolutionStrategy); return CreateCommandSpec(commandPath, commandArguments, commandResolutionStrategy);
@ -86,7 +90,8 @@ namespace Microsoft.DotNet.Cli.Utils
string depsFilePath, string depsFilePath,
CommandResolutionStrategy commandResolutionStrategy, CommandResolutionStrategy commandResolutionStrategy,
string nugetPackagesRoot, string nugetPackagesRoot,
bool isPortable) bool isPortable,
string runtimeConfigPath)
{ {
var host = string.Empty; var host = string.Empty;
var arguments = new List<string>(); var arguments = new List<string>();
@ -110,6 +115,12 @@ namespace Microsoft.DotNet.Cli.Utils
arguments.Add(commandPath); arguments.Add(commandPath);
if (runtimeConfigPath != null)
{
arguments.Add("--runtimeconfig");
arguments.Add(runtimeConfigPath);
}
if (depsFilePath != null) if (depsFilePath != null)
{ {
arguments.Add("--depsfile"); arguments.Add("--depsfile");
@ -134,13 +145,14 @@ namespace Microsoft.DotNet.Cli.Utils
return new CommandSpec(commandPath, escapedArgs, commandResolutionStrategy); return new CommandSpec(commandPath, escapedArgs, commandResolutionStrategy);
} }
private bool IsPortableApp(string commandPath) private bool IsPortableApp(string commandPath, string runtimeConfigPath)
{ {
var commandDir = Path.GetDirectoryName(commandPath); var commandDir = Path.GetDirectoryName(commandPath);
var runtimeConfigPath = Directory.EnumerateFiles(commandDir) runtimeConfigPath = string.IsNullOrEmpty(runtimeConfigPath)
.FirstOrDefault(x => x.EndsWith("runtimeconfig.json")); ? Directory.EnumerateFiles(commandDir).FirstOrDefault(x => x.EndsWith("runtimeconfig.json"))
: runtimeConfigPath;
if (runtimeConfigPath == null) if (runtimeConfigPath == null)
{ {
return false; return false;

View file

@ -78,25 +78,11 @@ namespace Microsoft.DotNet.Cli.Utils
var depsFilePath = var depsFilePath =
projectContext.GetOutputPaths(configuration, buildBasePath, outputPath).RuntimeFiles.DepsJson; projectContext.GetOutputPaths(configuration, buildBasePath, outputPath).RuntimeFiles.DepsJson;
var runtimeConfigPath =
projectContext.GetOutputPaths(configuration, buildBasePath, outputPath).RuntimeFiles.RuntimeConfigJson;
var toolLibrary = GetToolLibraryForContext(projectContext, commandName); var toolLibrary = GetToolLibraryForContext(projectContext, commandName);
return ResolveFromDependencyLibrary(
toolLibrary,
depsFilePath,
commandName,
allowedExtensions,
commandArguments,
projectContext);
}
private CommandSpec ResolveFromDependencyLibrary(
LockFileTargetLibrary toolLibrary,
string depsFilePath,
string commandName,
IEnumerable<string> allowedExtensions,
IEnumerable<string> commandArguments,
ProjectContext projectContext)
{
return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary( return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary(
toolLibrary, toolLibrary,
commandName, commandName,
@ -104,7 +90,8 @@ namespace Microsoft.DotNet.Cli.Utils
allowedExtensions, allowedExtensions,
projectContext.PackagesDirectory, projectContext.PackagesDirectory,
s_commandResolutionStrategy, s_commandResolutionStrategy,
depsFilePath); depsFilePath,
runtimeConfigPath);
} }
private LockFileTargetLibrary GetToolLibraryForContext( private LockFileTargetLibrary GetToolLibraryForContext(

View file

@ -123,7 +123,8 @@ namespace Microsoft.DotNet.Cli.Utils
_allowedCommandExtensions, _allowedCommandExtensions,
projectContext.PackagesDirectory, projectContext.PackagesDirectory,
s_commandResolutionStrategy, s_commandResolutionStrategy,
depsFilePath); depsFilePath,
null);
} }
private LockFile GetToolLockFile( private LockFile GetToolLockFile(

View file

@ -304,15 +304,21 @@ int fx_muxer_t::parse_args_and_execute(const pal::string_t& own_dir, int argoff,
pal::string_t opts_deps_file = _X("--depsfile"); pal::string_t opts_deps_file = _X("--depsfile");
pal::string_t opts_probe_path = _X("--additionalprobingpath"); pal::string_t opts_probe_path = _X("--additionalprobingpath");
pal::string_t opts_runtime_config = _X("--runtimeconfig");
pal::string_t deps_file = get_last_known_arg(opts, opts_deps_file, _X("")); pal::string_t deps_file = get_last_known_arg(opts, opts_deps_file, _X(""));
pal::string_t runtime_config = get_last_known_arg(opts, opts_runtime_config, _X(""));
std::vector<pal::string_t> probe_paths = opts.count(opts_probe_path) ? opts[opts_probe_path] : std::vector<pal::string_t>(); std::vector<pal::string_t> probe_paths = opts.count(opts_probe_path) ? opts[opts_probe_path] : std::vector<pal::string_t>();
trace::verbose(_X("Current argv is %s"), app_candidate.c_str()); trace::verbose(_X("Current argv is %s"), app_candidate.c_str());
pal::string_t app_or_deps = deps_file.empty() ? app_candidate : deps_file; pal::string_t app_or_deps = deps_file.empty() ? app_candidate : deps_file;
pal::string_t no_json = app_candidate; pal::string_t app_or_runtime_config = runtime_config.empty() ? app_candidate : runtime_config;
pal::string_t dev_config_file; pal::string_t config_file, dev_config_file;
auto config_file = get_runtime_config_from_file(no_json, &dev_config_file);
trace::error(_X("Finding runtimeconfig.json from [%s]"), app_or_runtime_config.c_str());
get_runtime_config_paths_from_file(app_or_runtime_config, &config_file, &dev_config_file);
runtime_config_t config(config_file, dev_config_file); runtime_config_t config(config_file, dev_config_file);
for (const auto& path : config.get_probe_paths()) for (const auto& path : config.get_probe_paths())
{ {

View file

@ -246,9 +246,11 @@ SHARED_API int corehost_main(const int argc, const pal::char_t* argv[])
} }
else else
{ {
pal::string_t dev_config_file; pal::string_t config_file, dev_config_file;
auto config_path = get_runtime_config_from_file(args.managed_application, &dev_config_file);
runtime_config_t config(config_path, dev_config_file); get_runtime_config_paths_from_file(args.managed_application, &config_file, &dev_config_file);
runtime_config_t config(config_file, dev_config_file);
if (!config.is_valid()) if (!config.is_valid())
{ {
trace::error(_X("Invalid runtimeconfig.json [%s] [%s]"), config.get_path().c_str(), config.get_dev_path().c_str()); trace::error(_X("Invalid runtimeconfig.json [%s] [%s]"), config.get_path().c_str(), config.get_dev_path().c_str());

View file

@ -6,20 +6,23 @@
#include "trace.h" #include "trace.h"
#include "libhost.h" #include "libhost.h"
pal::string_t get_runtime_config_from_file(const pal::string_t& file, pal::string_t* dev_cfg) void get_runtime_config_paths_from_file(const pal::string_t& file, pal::string_t* cfg, pal::string_t* dev_cfg)
{ {
auto name = get_filename_without_ext(file); auto name = get_filename_without_ext(file);
auto json_name = name + _X(".runtimeconfig.json"); auto json_name = name + _X(".runtimeconfig.json");
auto dev_json_name = name + _X(".runtimeconfig.dev.json"); auto dev_json_name = name + _X(".runtimeconfig.dev.json");
auto json_path = get_directory(file); auto json_path = get_directory(file);
auto dev_json_path = json_path; auto dev_json_path = json_path;
append_path(&json_path, json_name.c_str()); append_path(&json_path, json_name.c_str());
append_path(&dev_json_path, dev_json_name.c_str()); append_path(&dev_json_path, dev_json_name.c_str());
trace::verbose(_X("Runtime config is cfg=%s dev=%s"), json_path.c_str(), dev_json_path.c_str()); trace::verbose(_X("Runtime config is cfg=%s dev=%s"), json_path.c_str(), dev_json_path.c_str());
dev_cfg->assign(dev_json_path); dev_cfg->assign(dev_json_path);
return json_path; cfg -> assign(json_path);
} }
host_mode_t detect_operating_mode(const int argc, const pal::char_t* argv[], pal::string_t* p_own_dir) host_mode_t detect_operating_mode(const int argc, const pal::char_t* argv[], pal::string_t* p_own_dir)

View file

@ -80,7 +80,7 @@ public:
} }
}; };
pal::string_t get_runtime_config_from_file(const pal::string_t& file, pal::string_t* dev_config_file); void get_runtime_config_paths_from_file(const pal::string_t& file, pal::string_t* config_file, pal::string_t* dev_config_file);
host_mode_t detect_operating_mode(const int argc, const pal::char_t* argv[], pal::string_t* own_dir = nullptr); host_mode_t detect_operating_mode(const int argc, const pal::char_t* argv[], pal::string_t* own_dir = nullptr);
void try_patch_roll_forward_in_dir(const pal::string_t& cur_dir, const fx_ver_t& start_ver, pal::string_t* max_str); void try_patch_roll_forward_in_dir(const pal::string_t& cur_dir, const fx_ver_t& start_ver, pal::string_t* max_str);