Resolve sym links to probe paths on Unix

This commit is contained in:
schellap 2016-01-16 19:30:41 -08:00 committed by Senthil
parent c055db7464
commit 45bee52522
6 changed files with 47 additions and 30 deletions

View file

@ -78,7 +78,7 @@ bool parse_arguments(const int argc, const pal::char_t* argv[], arguments_t& arg
args.app_argc = argc - 1; args.app_argc = argc - 1;
} }
if(args.app_argc > 0) if (args.app_argc > 0)
{ {
auto depsfile_candidate = pal::string_t(args.app_argv[0]); auto depsfile_candidate = pal::string_t(args.app_argv[0]);

View file

@ -96,7 +96,12 @@ void add_tpa_asset(
} }
trace::verbose(_X("Adding tpa entry: %s"), asset_path.c_str()); trace::verbose(_X("Adding tpa entry: %s"), asset_path.c_str());
output->append(asset_path);
// Workaround for CoreFX not being able to resolve sym links.
pal::string_t real_asset_path = asset_path;
pal::realpath(&real_asset_path);
output->append(real_asset_path);
output->push_back(PATH_SEPARATOR); output->push_back(PATH_SEPARATOR);
items->insert(asset_name); items->insert(asset_name);
} }
@ -133,15 +138,21 @@ void add_unique_path(
std::set<pal::string_t>* existing, std::set<pal::string_t>* existing,
pal::string_t* output) pal::string_t* output)
{ {
if (existing->count(path)) // Resolve sym links.
pal::string_t real = path;
pal::realpath(&real);
if (existing->count(real))
{ {
return; return;
} }
trace::verbose(_X("Adding to %s path: %s"), type.c_str(), path.c_str()); trace::verbose(_X("Adding to %s path: %s"), type.c_str(), real.c_str());
output->append(path);
output->append(real);
output->push_back(PATH_SEPARATOR); output->push_back(PATH_SEPARATOR);
existing->insert(path); existing->insert(real);
} }
} // end of anonymous namespace } // end of anonymous namespace

View file

@ -196,6 +196,8 @@ int run(const arguments_t& args, const pal::string_t& clr_path)
argv[i] = argv_strs[i].c_str(); argv[i] = argv_strs[i].c_str();
} }
std::string managed_app = pal::to_stdstring(args.managed_application);
// Execute the application // Execute the application
unsigned int exit_code = 1; unsigned int exit_code = 1;
hr = coreclr::execute_assembly( hr = coreclr::execute_assembly(
@ -203,7 +205,7 @@ int run(const arguments_t& args, const pal::string_t& clr_path)
domain_id, domain_id,
argv.size(), argv.size(),
argv.data(), argv.data(),
pal::to_stdstring(args.managed_application).c_str(), managed_app.c_str(),
&exit_code); &exit_code);
if (!SUCCEEDED(hr)) if (!SUCCEEDED(hr))
{ {
@ -225,6 +227,8 @@ int run(const arguments_t& args, const pal::string_t& clr_path)
SHARED_API int corehost_main(const int argc, const pal::char_t* argv[]) SHARED_API int corehost_main(const int argc, const pal::char_t* argv[])
{ {
trace::setup();
// Take care of arguments // Take care of arguments
arguments_t args; arguments_t args;
if (!parse_arguments(argc, argv, args)) if (!parse_arguments(argc, argv, args))
@ -239,5 +243,6 @@ SHARED_API int corehost_main(const int argc, const pal::char_t* argv[])
trace::error(_X("Could not resolve coreclr path")); trace::error(_X("Could not resolve coreclr path"));
return StatusCode::CoreClrResolveFailure; return StatusCode::CoreClrResolveFailure;
} }
pal::realpath(&clr_path);
return run(args, clr_path); return run(args, clr_path);
} }

View file

@ -5,6 +5,26 @@
static bool g_enabled = false; static bool g_enabled = false;
//
// Turn on tracing for the corehost based on "COREHOST_TRACE" env.
//
void trace::setup()
{
// Read trace environment variable
pal::string_t trace_str;
if (!pal::getenv(_X("COREHOST_TRACE"), &trace_str))
{
return;
}
auto trace_val = pal::xtoi(trace_str.c_str());
if (trace_val > 0)
{
trace::enable();
trace::info(_X("Tracing enabled"));
}
}
void trace::enable() void trace::enable()
{ {
g_enabled = true; g_enabled = true;

View file

@ -8,6 +8,7 @@
namespace trace namespace trace
{ {
void setup();
void enable(); void enable();
bool is_enabled(); bool is_enabled();
void verbose(const pal::char_t* format, ...); void verbose(const pal::char_t* format, ...);

View file

@ -59,26 +59,6 @@ StatusCode load_host_lib(const pal::string_t& lib_dir, pal::dll_t* h_host, coreh
: StatusCode::CoreHostEntryPointFailure; : StatusCode::CoreHostEntryPointFailure;
} }
//
// Turn on tracing for the corehost based on "COREHOST_TRACE" env.
//
void setup_tracing()
{
// Read trace environment variable
pal::string_t trace_str;
if (!pal::getenv(_X("COREHOST_TRACE"), &trace_str))
{
return;
}
auto trace_val = pal::xtoi(trace_str.c_str());
if (trace_val > 0)
{
trace::enable();
trace::info(_X("Tracing enabled"));
}
}
}; // end of anonymous namespace }; // end of anonymous namespace
#if defined(_WIN32) #if defined(_WIN32)
@ -87,7 +67,7 @@ int __cdecl wmain(const int argc, const pal::char_t* argv[])
int main(const int argc, const pal::char_t* argv[]) int main(const int argc, const pal::char_t* argv[])
#endif #endif
{ {
setup_tracing(); trace::setup();
pal::dll_t corehost; pal::dll_t corehost;