Exemplo n.º 1
0
bool pal::find_coreclr(pal::string_t* recv)
{
    pal::string_t candidate;

    // Try %LocalAppData%\dotnet
    if (pal::getenv(_X("LocalAppData"), &candidate)) {
        append_path(&candidate, _X("dotnet"));
        append_path(&candidate, _X("runtime"));
        append_path(&candidate, _X("coreclr"));
        if (coreclr_exists_in_dir(candidate)) {
            recv->assign(candidate);
            return true;
        }
    }


    // Try %ProgramFiles%. Note this works for both x86 and x64/wow64 as per:
    // https://msdn.microsoft.com/en-us/library/windows/desktop/aa384274(v=vs.85).aspx

    // candidate.clear(); getenv clears it.
    if (pal::getenv(_X("ProgramFiles"), &candidate)) {
        append_path(&candidate, _X("dotnet"));
        append_path(&candidate, _X("bin"));
        if (coreclr_exists_in_dir(candidate)) {
            recv->assign(candidate);
            return true;
        }
    }
    return false;
}
Exemplo n.º 2
0
// -----------------------------------------------------------------------------
// Resolve coreclr directory from the deps file.
//
// Description:
//    Look for CoreCLR from the dependency list in the package cache and then
//    the packages directory.
//
pal::string_t deps_resolver_t::resolve_coreclr_dir()
{
    auto process_coreclr = [&]
        (bool is_portable, const pal::string_t& deps_dir, deps_json_t* deps) -> pal::string_t
    {
        pal::string_t candidate;

        if (deps->has_coreclr_entry())
        {
            const deps_entry_t& entry = deps->get_coreclr_entry();
            if (probe_entry_in_configs(entry, &candidate))
            {
                return get_directory(candidate);
            }
            else if (entry.is_rid_specific && entry.to_rel_path(deps_dir, &candidate))
            {
                return get_directory(candidate);
            }
        }
        else
        {
            trace::verbose(_X("Deps has no coreclr entry."));
        }

        // App/FX main dir or standalone app dir.
        trace::verbose(_X("Probing for CoreCLR in deps directory=[%s]"), deps_dir.c_str());
        if (coreclr_exists_in_dir(deps_dir))
        {
            return deps_dir;
        }

        return pal::string_t();
    };

    trace::info(_X("-- Starting CoreCLR Probe from app deps.json"));
    pal::string_t clr_dir = process_coreclr(m_portable, m_app_dir, m_deps.get());
    if (clr_dir.empty() && m_portable)
    {
        trace::info(_X("-- Starting CoreCLR Probe from FX deps.json"));
        clr_dir = process_coreclr(false, m_fx_dir, m_fx_deps.get());
    }
    if (!clr_dir.empty())
    {
        return clr_dir;
    }

    // Use platform-specific search algorithm
    pal::string_t install_dir;
    if (pal::find_coreclr(&install_dir))
    {
        return install_dir;
    }

    return pal::string_t();
}
Exemplo n.º 3
0
bool pal::find_coreclr(pal::string_t* recv)
{
    pal::string_t candidate;
    pal::string_t test;

    // Try /usr/share/dotnet and /usr/local/share/dotnet/cli
    // TODO: These paths should be consistent
    candidate.assign("/usr/share/dotnet/runtime/coreclr");
    if (coreclr_exists_in_dir(candidate)) {
        recv->assign(candidate);
        return true;
    }

    candidate.assign("/usr/local/share/dotnet/runtime/coreclr");
    if (coreclr_exists_in_dir(candidate)) {
        recv->assign(candidate);
        return true;
    }
    return false;
}
Exemplo n.º 4
0
// ----------------------------------------------------------------------
// resolve_clr_path: Resolve CLR Path in priority order
//
// Description:
//   Check if CoreCLR library exists in runtime servicing dir or app
//   local or DOTNET_HOME directory in that order of priority. If these
//   fail to locate CoreCLR, then check platform-specific search.
//
// Returns:
//   "true" if path to the CoreCLR dir can be resolved in "clr_path"
//    parameter. Else, returns "false" with "clr_path" unmodified.
//
bool resolve_clr_path(const arguments_t& args, pal::string_t* clr_path)
{
    const pal::string_t* dirs[] = {
        &args.dotnet_runtime_servicing, // DOTNET_RUNTIME_SERVICING
        &args.app_dir,                  // APP LOCAL
        &args.dotnet_home               // DOTNET_HOME
    };
    for (int i = 0; i < sizeof(dirs) / sizeof(dirs[0]); ++i)
    {
        if (dirs[i]->empty())
        {
            continue;
        }

        // App dir should contain coreclr, so skip appending path.
        pal::string_t cur_dir = *dirs[i];
        if (dirs[i] != &args.app_dir)
        {
            append_path(&cur_dir, _X("runtime"));
            append_path(&cur_dir, _X("coreclr"));
        }

        // Found coreclr in priority order.
        if (coreclr_exists_in_dir(cur_dir))
        {
            clr_path->assign(cur_dir);
            return true;
        }
    }

    // Use platform-specific search algorithm
    pal::string_t home_dir = args.dotnet_home;
    if (pal::find_coreclr(&home_dir))
    {
        clr_path->assign(home_dir);
        return true;
    }
    return false;
}
Exemplo n.º 5
0
host_mode_t detect_operating_mode(const int argc, const pal::char_t* argv[], pal::string_t* p_own_dir)
{
    pal::string_t own_path;
    if (!pal::get_own_executable_path(&own_path) || !pal::realpath(&own_path))
    {
        trace::error(_X("Failed to locate current executable"));
        return host_mode_t::invalid;
    }

    pal::string_t own_name = get_filename(own_path);
    pal::string_t own_dir = get_directory(own_path);
    if (p_own_dir)
    {
        p_own_dir->assign(own_dir);
    }

    pal::string_t own_dll_filename = strip_file_ext(own_name) + _X(".dll");
    pal::string_t own_dll = own_dir;
    append_path(&own_dll, own_dll_filename.c_str());
    trace::info(_X("Own DLL path=[%s]"), own_dll.c_str());
    if (coreclr_exists_in_dir(own_dir) || pal::file_exists(own_dll))
    {
        pal::string_t own_deps_json = own_dir;
        pal::string_t own_deps_filename = strip_file_ext(own_name) + _X(".deps.json");
        pal::string_t own_config_filename = strip_file_ext(own_name) + _X(".runtimeconfig.json");
        append_path(&own_deps_json, own_deps_filename.c_str());
        if (trace::is_enabled())
        {
            trace::info(_X("Detecting mode... CoreCLR present in own dir [%s] and checking if [%s] file present=[%d]"),
                own_dir.c_str(), own_deps_filename.c_str(), pal::file_exists(own_deps_json));
        }
        return ((pal::file_exists(own_deps_json) || !pal::file_exists(own_config_filename)) && pal::file_exists(own_dll)) ? host_mode_t::standalone : host_mode_t::split_fx;
    }
    else
    {
        return host_mode_t::muxer;
    }
}