Welcome to mirror list, hosted at ThFree Co, Russian Federation.

args.cpp « hostpolicy « cli « corehost « installer « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f022d23ae5f3c38a5ea21bd5076444f5ad968bb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#include "args.h"
#include <utils.h>
#include "bundle/runner.h"

arguments_t::arguments_t()
    : host_mode(host_mode_t::invalid)
    , host_path(_X(""))
    , app_root(_X(""))
    , deps_path(_X(""))
    , core_servicing(_X(""))
    , managed_application(_X(""))
    , app_argc(0)
    , app_argv(nullptr)
{
}

/**
 *
 * Setup the shared store directories.
 *
 *  o %DOTNET_SHARED_STORE% -- multiple delimited paths
 *  o dotnet.exe relative shared store\<arch>\<tfm>
 *  o Global location
 *      Windows: global default location (Program Files) or globally registered location (registry) + store\<arch>\<tfm>
 *      Linux/macOS: none (no global locations are considered)
 */
void setup_shared_store_paths(const pal::string_t& tfm, host_mode_t host_mode,const pal::string_t& own_dir, arguments_t* args)
{
    if (tfm.empty())
    {
        // Old (MNA < 1.1.*) "runtimeconfig.json" files do not contain TFM property.
        return;
    }

    // Environment variable DOTNET_SHARED_STORE
    (void) get_env_shared_store_dirs(&args->env_shared_store, get_arch(), tfm);

    // "dotnet.exe" relative shared store folder
    if (host_mode == host_mode_t::muxer)
    {
        args->dotnet_shared_store = own_dir;
        append_path(&args->dotnet_shared_store, RUNTIME_STORE_DIRECTORY_NAME);
        append_path(&args->dotnet_shared_store, get_arch());
        append_path(&args->dotnet_shared_store, tfm.c_str());
    }

    // Global shared store dir
    bool multilevel_lookup = multilevel_lookup_enabled();
    if (multilevel_lookup)
    {
        get_global_shared_store_dirs(&args->global_shared_stores, get_arch(), tfm);
    }
}

bool parse_arguments(
    const hostpolicy_init_t& init,
    const int argc, const pal::char_t* argv[],
    arguments_t& args)
{
    pal::string_t managed_application_path;
    if (init.host_mode == host_mode_t::apphost)
    {
        // Find the managed app in the same directory
        managed_application_path = init.host_info.app_path;

        args.app_argv = &argv[1];
        args.app_argc = argc - 1;
    }
    else if (init.host_mode == host_mode_t::libhost)
    {
        // Find the managed assembly in the same directory
        managed_application_path = init.host_info.app_path;

        assert(argc == 0 && argv == nullptr);
    }
    else
    {
        // First argument is managed app
        if (argc < 2)
        {
            return false;
        }

        managed_application_path = pal::string_t(argv[1]);

        args.app_argc = argc - 2;
        args.app_argv = &argv[2];
    }

    return init_arguments(
        managed_application_path,
        init.host_info,
        init.tfm,
        init.host_mode,
        init.additional_deps_serialized,
        init.deps_file,
        init.probe_paths,
        args);
}

bool set_root_from_app(const pal::string_t& managed_application_path,
                       arguments_t& args)
{
    args.managed_application = managed_application_path;

    if (args.managed_application.empty())
    {
        // Managed app being empty by itself is not a failure. Host may be initialized from a config file. 
        assert(args.host_mode != host_mode_t::apphost);
        return true;
    }

    if (bundle::info_t::is_single_file_bundle())
    {
        const bundle::runner_t* app = bundle::runner_t::app();
        args.app_root = app->base_path();

        // Check for the main app within the bundle.
        // locate() sets args.managed_application to the full path of the app extracted to disk.
        pal::string_t managed_application_name = get_filename(managed_application_path);		
        if (app->locate(managed_application_name, args.managed_application))
        {
            return true;
        }

        trace::info(_X("Managed application [%s] not found in single-file bundle"), managed_application_name.c_str());
		
        // If the main assembly is not found in the bundle, continue checking on disk
        // for very unlikely case where the main app.dll was itself excluded from the app bundle.
        return pal::realpath(&args.managed_application);
    }

    if (pal::realpath(&args.managed_application))
    {
        args.app_root = get_directory(args.managed_application);
        return true;
    }

    return false;
}

bool init_arguments(
    const pal::string_t& managed_application_path,
    const host_startup_info_t& host_info,
    const pal::string_t& tfm,
    host_mode_t host_mode,
    const pal::string_t& additional_deps_serialized,
    const pal::string_t& deps_file,
    const std::vector<pal::string_t>& probe_paths,
    arguments_t& args)
{
    args.host_mode = host_mode;
    args.host_path = host_info.host_path;
    args.additional_deps_serialized = additional_deps_serialized;

    if (!set_root_from_app(managed_application_path, args))
    {
        trace::error(_X("Failed to locate managed application [%s]"), args.managed_application.c_str());
        return false;
    }

    if (!deps_file.empty())
    {
        args.deps_path = deps_file;
        args.app_root = get_directory(args.deps_path);
    }

    for (const auto& probe : probe_paths)
    {
        args.probe_paths.push_back(probe);
    }

    if (args.deps_path.empty())
    {
        args.deps_path = get_deps_from_app_binary(args.app_root, args.managed_application);
    }

    pal::get_default_servicing_directory(&args.core_servicing);

    setup_shared_store_paths(tfm, host_mode, get_directory(args.host_path), &args);

    return true;
}