1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 #include <coreruncommon.h>
10 // Display the command line options
15 "Usage: corerun [OPTIONS] assembly [ARGUMENTS]\n"
16 "Execute the specified managed assembly with the passed in arguments\n\n"
18 "-c, --clr-path path to the libcoreclr.so and the managed CLR assemblies\n");
21 // Parse the command line arguments
25 const char** clrFilesPath
,
26 const char** managedAssemblyPath
,
27 int* managedAssemblyArgc
,
28 const char*** managedAssemblyArgv
)
32 *clrFilesPath
= nullptr;
33 *managedAssemblyPath
= nullptr;
34 *managedAssemblyArgv
= nullptr;
35 *managedAssemblyArgc
= 0;
37 // The command line must contain at least the current exe name and the managed assembly path
40 for (int i
= 1; i
< argc
; i
++)
42 // Check for an option
43 if (argv
[i
][0] == '-')
45 // Path to the libcoreclr.so and the managed CLR assemblies
46 if (strcmp(argv
[i
], "-c") == 0 || strcmp(argv
[i
], "--clr-path") == 0)
51 *clrFilesPath
= argv
[i
];
55 fprintf(stderr
, "Option %s: missing path\n", argv
[i
- 1]);
59 else if (strcmp(argv
[i
], "-?") == 0 || strcmp(argv
[i
], "-h") == 0 || strcmp(argv
[i
], "--help") == 0)
66 fprintf(stderr
, "Unknown option %s\n", argv
[i
]);
72 // First argument that is not an option is the managed assembly to execute
73 *managedAssemblyPath
= argv
[i
];
75 int managedArgvOffset
= (i
+ 1);
76 *managedAssemblyArgc
= argc
- managedArgvOffset
;
77 if (*managedAssemblyArgc
!= 0)
79 *managedAssemblyArgv
= &argv
[managedArgvOffset
];
94 int corerun(const int argc
, const char* argv
[])
96 const char* clrFilesPath
;
97 const char* managedAssemblyPath
;
98 const char** managedAssemblyArgv
;
99 int managedAssemblyArgc
;
105 &managedAssemblyPath
,
106 &managedAssemblyArgc
,
107 &managedAssemblyArgv
))
109 // Invalid command line
113 // Check if the specified managed assembly file exists
115 if (stat(managedAssemblyPath
, &sb
) == -1)
117 perror("Managed assembly not found");
121 // Verify that the managed assembly path points to a file
122 if (!S_ISREG(sb
.st_mode
))
124 fprintf(stderr
, "The specified managed assembly is not a file\n");
128 // Make sure we have a full path for argv[0].
129 std::string argv0AbsolutePath
;
130 if (!GetEntrypointExecutableAbsolutePath(argv0AbsolutePath
))
132 perror("Could not get full path");
136 std::string clrFilesAbsolutePath
;
137 if(!GetClrFilesAbsolutePath(argv0AbsolutePath
.c_str(), clrFilesPath
, clrFilesAbsolutePath
))
142 std::string managedAssemblyAbsolutePath
;
143 if (!GetAbsolutePath(managedAssemblyPath
, managedAssemblyAbsolutePath
))
145 perror("Failed to convert managed assembly path to absolute path");
149 int exitCode
= ExecuteManagedAssembly(
150 argv0AbsolutePath
.c_str(),
151 clrFilesAbsolutePath
.c_str(),
152 managedAssemblyAbsolutePath
.c_str(),
154 managedAssemblyArgv
);
159 int main(const int argc
, const char* argv
[])
161 return corerun(argc
, argv
);