Imported Upstream version 6.8.0.73

Former-commit-id: d18deab1b47cfd3ad8cba82b3f37d00eec2170af
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-12-10 18:00:56 +00:00
parent bceda29824
commit 73ee7591e8
1043 changed files with 16271 additions and 22080 deletions

275
netcore/Makefile Normal file
View File

@@ -0,0 +1,275 @@
ifneq ($(wildcard config.make),)
include config.make
NETCORETESTS_VERSION := $(shell cat ../eng/Versions.props | sed -n 's/.*MicrosoftPrivateCoreFxNETCoreAppVersion>\(.*\)<\/MicrosoftPrivateCoreFxNETCoreAppVersion.*/\1/p' )
NETCOREAPP_VERSION := $(shell cat ../eng/Versions.props | sed -n 's/.*MicrosoftNETCoreAppVersion>\(.*\)<\/MicrosoftNETCoreAppVersion.*/\1/p' )
ROSLYN_VERSION:= $(shell cat ../eng/Versions.props | sed -n 's/.*MicrosoftNetCompilersVersion>\(.*\)<\/MicrosoftNetCompilersVersion.*/\1/p' )
# Should be automated but not sure how for now
# the name is misleading osx version is used for any unix like systems
# the url is manually extracted from coreclr-outerloop (https://dev.azure.com/dnceng/public/_build?definitionId=98&_a=summary) Build artifacts published page
CORECLR_TESTS:=https://dev.azure.com/dnceng/9ee6d478-d288-47f7-aacc-f6e6d082ae6d/_apis/build/builds/368250/artifacts?artifactName=Tests_OSX_x64_checked_outerloop&api-version=5.2-preview.5&%24format=zip
# runtime version used by $(DOTNET) - local .net core sdk to bootstrap stuff
# it doesn't match NETCOREAPP_VERSION
BOOTSTRAP_RUNTIME = $(shell ls ../.dotnet/shared/Microsoft.NETCore.App | tail -1)
ifeq ($(HOST_PLATFORM),win32)
PLATFORM_AOT_SUFFIX := .dll
PLATFORM_AOT_PREFIX :=
NETCORESDK_EXT = zip
UNZIPCMD = python -c "import zipfile,sys; zipfile.ZipFile(sys.argv[1], 'r').extractall()"
XUNIT_FLAGS = -notrait category=nonwindowstests @../../../../CoreFX.issues_windows.rsp
TESTS_PLATFORM = Windows_NT.x64
ON_RUNTIME_EXTRACT = chmod -R 755 {host,shared,./dotnet}
DOTNET := $(shell powershell -ExecutionPolicy Bypass -Command "./init-tools.ps1")/dotnet.exe
DOTNET := "$(subst \,/,$(DOTNET))"
endif
ifeq ($(HOST_PLATFORM),macos)
PLATFORM_AOT_SUFFIX := .dylib
PLATFORM_AOT_PREFIX := lib
NETCORESDK_EXT = tar.gz
UNZIPCMD = tar -xvf
XUNIT_FLAGS = -notrait category=nonosxtests
TESTS_PLATFORM = OSX.x64
DOTNET := $(shell ./init-tools.sh | tail -1)
endif
ifeq ($(HOST_PLATFORM),linux)
PLATFORM_AOT_SUFFIX := .so
PLATFORM_AOT_PREFIX := lib
NETCORESDK_EXT = tar.gz
UNZIPCMD = tar -xvf
XUNIT_FLAGS = -notrait category=nonlinuxtests @../../../../CoreFX.issues_linux.rsp
ifeq ($(COREARCH), arm64)
XUNIT_FLAGS += @../../../../CoreFX.issues_linux_arm64.rsp
endif
TESTS_PLATFORM = Linux.x64
DOTNET := $(shell ./init-tools.sh | tail -1)
endif
NETCORESDK_FILE := dotnet-runtime-$(NETCOREAPP_VERSION)-$(RID).$(NETCORESDK_EXT)
NETCORE_URL := https://dotnetcli.blob.core.windows.net/dotnet/Runtime/$(NETCOREAPP_VERSION)/$(NETCORESDK_FILE)
FEED_BASE_URL := https://dotnetfeed.blob.core.windows.net/dotnet-core
TEST_ASSETS_PATH := corefx-tests/$(NETCORETESTS_VERSION)/$(TESTS_PLATFORM)/netcoreapp/corefx-test-assets.xml
# used to calculate exact version number for generating nupkg
BLAME = $(shell git blame ../configure.ac | grep AC_INIT | cut -f1 -d' ')
VERSTUB = .$(shell git rev-list --count $(BLAME)..HEAD)-preview
all: bcl
$(NETCORESDK_FILE):
curl $(NETCORE_URL) --output $(NETCORESDK_FILE)
rm -rf shared/Microsoft.NETCore.App
$(UNZIPCMD) $(NETCORESDK_FILE)
$(ON_RUNTIME_EXTRACT)
update-corefx: corefx/.stamp-dl-corefx-$(NETCORETESTS_VERSION)
corefx/.stamp-dl-corefx-$(NETCORETESTS_VERSION): corefx-restore.csproj
$(DOTNET) build corefx-restore.csproj --runtime $(RID) --packages corefx/packages -p:MicrosoftPrivateCoreFxNETCoreAppVersion=$(NETCORETESTS_VERSION) -p:OutputPath=corefx/restore/
touch $@
update-roslyn: roslyn/packages/microsoft.net.compilers.toolset/$(ROSLYN_VERSION)/microsoft.net.compilers.toolset.nuspec
roslyn/packages/microsoft.net.compilers.toolset/$(ROSLYN_VERSION)/microsoft.net.compilers.toolset.nuspec:
$(DOTNET) restore roslyn-restore.csproj -p:RoslynVersion=$(ROSLYN_VERSION) --packages roslyn/packages -p:OutputPath=roslyn/restore/
run-sample: prepare
$(DOTNET) build sample/HelloWorld
MONO_ENV_OPTIONS="--debug" COMPlus_DebugWriteToStdErr=1 ./dotnet --fx-version "$(NETCOREAPP_VERSION)" sample/HelloWorld/bin/netcoreapp3.0/HelloWorld.dll
run-sample-dbg: prepare
$(DOTNET) build sample/HelloWorld
MONO_ENV_OPTIONS="--debug --debugger-agent=transport=dt_socket,address=127.0.0.1:1235,server=y,suspend=y" COMPlus_DebugWriteToStdErr=1 ./dotnet --fx-version "$(NETCOREAPP_VERSION)" sample/HelloWorld/bin/netcoreapp3.0/HelloWorld.dll
run-sample-coreclr:
cd sample/HelloWorld && $(DOTNET) run
# build any app in "self contained" mode and patch coreclr.dll and corelib with mono bits
# e.g. `make patch-app APP_PATH=/my/aspnetapp`
patch-app: prepare
@if test -z "$(APP_PATH)"; then echo "APP_PATH is not set"; exit 1; fi
cp NuGet.config $(APP_PATH)
cd $(APP_PATH) && $(DOTNET) publish -c Release -r $(RID) -f netcoreapp3.0
cp ../mono/mini/.libs/libmonosgen-2.0$(PLATFORM_AOT_SUFFIX) $(APP_PATH)/bin/Release/netcoreapp3.0/$(RID)/publish/$(PLATFORM_AOT_PREFIX)coreclr$(PLATFORM_AOT_SUFFIX)
cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.dll $(APP_PATH)/bin/Release/netcoreapp3.0/$(RID)/publish
cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.pdb $(APP_PATH)/bin/Release/netcoreapp3.0/$(RID)/publish
# makes $(DOTNET) to use mono runtime (to run real-world apps using '$(DOTNET) run')
patch-local-dotnet: prepare
cp ../mono/mini/.libs/libmonosgen-2.0$(PLATFORM_AOT_SUFFIX) ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME)/$(PLATFORM_AOT_PREFIX)coreclr$(PLATFORM_AOT_SUFFIX)
cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.dll ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME)
cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.pdb ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME)
# Precompile BCL libs in $(DOTNET) using LLVM (requires `--enable-llvm` build)
patch-local-dotnet-aot-llvm: patch-local-dotnet
for assembly in ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME)/*.dll; do \
echo "[AOT] $$assembly"; \
PATH="../llvm/usr/bin/:$(PATH)" \
MONO_ENV_OPTIONS="--aot=llvm,llvmllc=\"-mcpu=native\"" \
$(DOTNET) $$assembly ; \
done; \
# run 'dotnet/performance' benchmarks
# e.g. 'make run-benchmarks DOTNET_PERF_REPO=/prj/performance'
# you can append BDN parameters at the end, e.g. ` -- --filter Burgers --keepFiles`
# NOTE: we have to delete a couple of System.Drawing files to make it work
run-benchmarks: patch-local-dotnet
@if test -z "$(DOTNET_PERF_REPO)"; then echo "DOTNET_PERF_REPO is not set"; exit 1; fi
cd $(DOTNET_PERF_REPO)/src/benchmarks/micro/ && \
> corefx/System.Drawing/Perf_Color.cs && \
> corefx/System.Drawing/Perf_Graphics_DrawBeziers.cs && \
> corefx/System.Drawing/Perf_Graphics_Transforms.cs && \
> corefx/System.Drawing/Perf_Image_Load.cs && \
$(DOTNET) run -c Release -f netcoreapp5.0 --cli $(CURDIR)/../.dotnet/dotnet
# run HelloWorld using --aot=llvm (requires `--enable-llvm` build)
run-sample-local-dotnet-llvm: patch-local-dotnet
$(DOTNET) build -c Release sample/HelloWorld
PATH="../llvm/usr/bin/:$(PATH)" \
MONO_ENV_OPTIONS="--aot=llvm,mcpu=native" \
$(DOTNET) sample/HelloWorld/bin/netcoreapp3.0/HelloWorld.dll
$(DOTNET) sample/HelloWorld/bin/netcoreapp3.0/HelloWorld.dll
# COREHOST_TRACE=1
SHAREDRUNTIME := shared/Microsoft.NETCore.App/$(NETCOREAPP_VERSION)
System.Private.CoreLib/src/System/Environment.Mono.cs: System.Private.CoreLib/src/System/Environment.Mono.in config.make
test -n '$(MONO_CORLIB_VERSION)'
sed -e 's,@''MONO_CORLIB_VERSION@,$(MONO_CORLIB_VERSION),' $< > $@
CORLIB_BUILD_FLAGS?=-c Release
bcl: update-roslyn System.Private.CoreLib/src/System/Environment.Mono.cs
$(DOTNET) build $(CORETARGETS) $(CORLIB_BUILD_FLAGS) -p:BuildArch=$(COREARCH) \
-p:OutputPath=bin/$(COREARCH) \
-p:RoslynPropsFile="../roslyn/packages/microsoft.net.compilers.toolset/$(ROSLYN_VERSION)/build/Microsoft.Net.Compilers.Toolset.props" \
System.Private.CoreLib/System.Private.CoreLib.csproj
debug-bcl:
$(MAKE) bcl CORLIB_BUILD_FLAGS="-c Debug"
runtime:
$(MAKE) -C ../mono
link-mono: $(SHAREDRUNTIME)/.stamp-link-mono
$(SHAREDRUNTIME)/.stamp-link-mono: ../mono/mini/.libs/libmonosgen-2.0$(PLATFORM_AOT_SUFFIX) System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.dll System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.pdb
cp ../mono/mini/.libs/libmonosgen-2.0$(PLATFORM_AOT_SUFFIX) $(SHAREDRUNTIME)/$(PLATFORM_AOT_PREFIX)coreclr$(PLATFORM_AOT_SUFFIX)
cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.dll $(SHAREDRUNTIME)
cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.pdb $(SHAREDRUNTIME)
touch $@
prepare: $(NETCORESDK_FILE) update-corefx update-roslyn link-mono
pack-%:
$(DOTNET) pack roslyn-restore.csproj -p:IsPackable=true -p:NuspecFile=$*.nuspec -p:NuspecProperties=\"RID=$(RID)\;VERSION=$(VERSION)$(VERSTUB)\;PLATFORM_AOT_SUFFIX=$(PLATFORM_AOT_SUFFIX)\;COREARCH=$(COREARCH)\;PLATFORM_AOT_PREFIX=$(PLATFORM_AOT_PREFIX)\" --output ../artifacts/ --no-build
nupkg: pack-metapackage pack-runtime
nupkg-llvm: pack-metapackage-llvm pack-runtime-llvm
clean:
rm -rf .configured ../.dotnet sdk shared host dotnet tests obj corefx roslyn LICENSE.txt ThirdPartyNotices.txt $(NETCORESDK_FILE)
update-tests-corefx: corefx/.stamp-dl-corefx-tests-$(NETCORETESTS_VERSION)
corefx/.stamp-dl-corefx-tests-$(NETCORETESTS_VERSION):
rm -rf corefx/tests
$(DOTNET) msbuild corefx-tests-restore.proj -m -t:DownloadAllTests -p:TEST_ASSETS_PATH="$(TEST_ASSETS_PATH)" -p:FEED_BASE_URL="$(FEED_BASE_URL)"
rm -rf corefx/tests/extracted/System.Utf8String.Experimental.Tests
touch $@
#
# Running CoreFX tests
#
# You can run either individual test assembly or run all CoreFX tests. The tests are automatically downloaded
# from the shared location and built locally.
#
# Running all test: `make run-tests-corefx`
#
# Running individual test: MONO_ENV_OPTIONS="--debug" make run-tests-corefx-System.Collections.Tests
#
run-tests-corefx: prepare update-tests-corefx
@rm -f .failures; \
counter=0; \
tests_count=$(words $(dir $(wildcard corefx/tests/extracted/*/))); \
for testdir in corefx/tests/extracted/*; do \
counter=$$((counter+1)); \
testname=$$(basename $$testdir); \
if [ -n "$$USE_TIMEOUT" ]; then timeoutcmd="../scripts/ci/run-step.sh --label=$$testname --timeout=10m --fatal"; fi; \
$$timeoutcmd $(MAKE) run-tests-corefx-$$testname TEST_COUNTER="($$counter / $$tests_count) " || echo $$testname >> .failures; \
done; \
$(MAKE) xunit-summary; \
if [ -e ".failures" ]; then \
echo ""; \
echo "Failures in test suites:"; \
cat .failures; \
echo ""; \
exit 1; \
fi
run-tests-corefx-%: prepare update-tests-corefx
@echo ""
@echo "***************** $* $${TEST_COUNTER}*********************"
@cp corefx/restore/corefx-restore.deps.json corefx/tests/extracted/$*/$*.deps.json
@cp corefx/restore/corefx-restore.runtimeconfig.dev.json corefx/tests/extracted/$*/$*.runtimeconfig.dev.json
@cp corefx/restore/corefx-restore.dll corefx/tests/extracted/$*/corefx-restore.dll
@sed -i -e 's/5.0.0\"/$(NETCOREAPP_VERSION)\"/g' corefx/tests/extracted/$*/*.runtimeconfig.json
cd corefx/tests/extracted/$* && \
MONO_ENV_OPTIONS="--debug" COMPlus_DebugWriteToStdErr=1 $(CURDIR)/./dotnet exec \
--runtimeconfig $*.runtimeconfig.json --additional-deps $*.deps.json \
--fx-version "$(NETCOREAPP_VERSION)" xunit.console.dll $*.dll \
-html ../../TestResult-$*.html -xml ../../TestResult-$*-netcore-xunit.xml \
$(XUNIT_FLAGS) @../../../../CoreFX.issues.rsp \
$(FIXTURE)
# build a test assembly in COREFX_ROOT (path to a fully built corefx repo) and copy it to corefx/tests/extracted
# e.g. `make build-test-corefx-System.Runtime COREFX_ROOT=/prj/corefx-master`
build-test-corefx-%:
cd $(COREFX_ROOT)/src/$*/tests && $(DOTNET) msbuild /p:OutputPath=tmp
cp $(COREFX_ROOT)/src/$*/tests/tmp/$*.Tests.{dll,pdb} $(CURDIR)/corefx/tests/extracted/$*.Tests/
rm -rf $(COREFX_ROOT)/src/$*/tests/tmp
xunit-summary:
./xunit-summary.py "corefx/tests"
update-tests-coreclr: coreclr/.stamp-tests
coreclr/.stamp-tests:
rm -rf coreclr/tests
curl -L "$(CORECLR_TESTS)" --output coreclr/tests.zip
tar -xvf coreclr/tests.zip -C coreclr/
mkdir coreclr/tests
tar -xvf coreclr/Tests_OSX_x64_checked_outerloop/Tests_OSX_x64_checked_outerloop.tar.gz -C coreclr/tests
touch $@
.PHONY: corerun
corerun:
cp corerun/corerun $(SHAREDRUNTIME)
run-tests-coreclr: prepare update-tests-coreclr corerun
rm -rf coreclr/output.log
@counter=0; \
failures=0; \
test_files=$$(find coreclr/tests -type f -name "*.sh"); \
for testdir in $$test_files; do \
counter=$$((counter+1)); \
echo "Running $$testdir"; \
if sh $$testdir -coreroot=$(realpath $(SHAREDRUNTIME)) >>coreclr/output.log 2>&1 ; then \
echo "FAILED"; \
failures=$$((failures+1)); \
fi; \
done; \
echo "Tests Count: $$counter"; \
echo "Failed: $$failures"
endif
distdir:
distclean:

View File

@@ -0,0 +1,7 @@
# Files copied from coreclr/src/coreclr/hosts/unixcorerun repo
AM_CPPFLAGS = $(SHARED_CFLAGS)
bin_PROGRAMS = corerun
corerun_SOURCES = corerun.cpp coreruncommon.cpp coreruncommon.h coreclrhost.h

816
netcore/corerun/Makefile.in Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,125 @@
// 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.
//
// APIs for hosting CoreCLR
//
#ifndef __CORECLR_HOST_H__
#define __CORECLR_HOST_H__
#if defined(_WIN32) && defined(_M_IX86)
#define CORECLR_CALLING_CONVENTION __stdcall
#else
#define CORECLR_CALLING_CONVENTION
#endif
// For each hosting API, we define a function prototype and a function pointer
// The prototype is useful for implicit linking against the dynamic coreclr
// library and the pointer for explicit dynamic loading (dlopen, LoadLibrary)
#define CORECLR_HOSTING_API(function, ...) \
extern "C" int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \
typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__)
//
// Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain
//
// Parameters:
// exePath - Absolute path of the executable that invoked the ExecuteAssembly (the native host application)
// appDomainFriendlyName - Friendly name of the app domain that will be created to execute the assembly
// propertyCount - Number of properties (elements of the following two arguments)
// propertyKeys - Keys of properties of the app domain
// propertyValues - Values of properties of the app domain
// hostHandle - Output parameter, handle of the created host
// domainId - Output parameter, id of the created app domain
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_initialize,
const char* exePath,
const char* appDomainFriendlyName,
int propertyCount,
const char** propertyKeys,
const char** propertyValues,
void** hostHandle,
unsigned int* domainId);
//
// Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host.
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_shutdown,
void* hostHandle,
unsigned int domainId);
//
// Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host.
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
// latchedExitCode - Latched exit code after domain unloaded
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_shutdown_2,
void* hostHandle,
unsigned int domainId,
int* latchedExitCode);
//
// Create a native callable function pointer for a managed method.
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
// entryPointAssemblyName - Name of the assembly which holds the custom entry point
// entryPointTypeName - Name of the type which holds the custom entry point
// entryPointMethodName - Name of the method which is the custom entry point
// delegate - Output parameter, the function stores a native callable function pointer to the delegate at the specified address
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_create_delegate,
void* hostHandle,
unsigned int domainId,
const char* entryPointAssemblyName,
const char* entryPointTypeName,
const char* entryPointMethodName,
void** delegate);
//
// Execute a managed assembly with given arguments
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
// argc - Number of arguments passed to the executed assembly
// argv - Array of arguments passed to the executed assembly
// managedAssemblyPath - Path of the managed assembly to execute (or NULL if using a custom entrypoint).
// exitCode - Exit code returned by the executed assembly
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_execute_assembly,
void* hostHandle,
unsigned int domainId,
int argc,
const char** argv,
const char* managedAssemblyPath,
unsigned int* exitCode);
#undef CORECLR_HOSTING_API
#endif // __CORECLR_HOST_H__

162
netcore/corerun/corerun.cpp Normal file
View File

@@ -0,0 +1,162 @@
// 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 <coreruncommon.h>
#include <string>
#include <string.h>
#include <sys/stat.h>
// Display the command line options
void DisplayUsage()
{
fprintf(
stderr,
"Usage: corerun [OPTIONS] assembly [ARGUMENTS]\n"
"Execute the specified managed assembly with the passed in arguments\n\n"
"Options:\n"
"-c, --clr-path path to the libcoreclr.so and the managed CLR assemblies\n");
}
// Parse the command line arguments
bool ParseArguments(
const int argc,
const char* argv[],
const char** clrFilesPath,
const char** managedAssemblyPath,
int* managedAssemblyArgc,
const char*** managedAssemblyArgv)
{
bool success = false;
*clrFilesPath = nullptr;
*managedAssemblyPath = nullptr;
*managedAssemblyArgv = nullptr;
*managedAssemblyArgc = 0;
// The command line must contain at least the current exe name and the managed assembly path
if (argc >= 2)
{
for (int i = 1; i < argc; i++)
{
// Check for an option
if (argv[i][0] == '-')
{
// Path to the libcoreclr.so and the managed CLR assemblies
if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--clr-path") == 0)
{
i++;
if (i < argc)
{
*clrFilesPath = argv[i];
}
else
{
fprintf(stderr, "Option %s: missing path\n", argv[i - 1]);
break;
}
}
else if (strcmp(argv[i], "-?") == 0 || strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
{
DisplayUsage();
break;
}
else
{
fprintf(stderr, "Unknown option %s\n", argv[i]);
break;
}
}
else
{
// First argument that is not an option is the managed assembly to execute
*managedAssemblyPath = argv[i];
int managedArgvOffset = (i + 1);
*managedAssemblyArgc = argc - managedArgvOffset;
if (*managedAssemblyArgc != 0)
{
*managedAssemblyArgv = &argv[managedArgvOffset];
}
success = true;
break;
}
}
}
else
{
DisplayUsage();
}
return success;
}
int corerun(const int argc, const char* argv[])
{
const char* clrFilesPath;
const char* managedAssemblyPath;
const char** managedAssemblyArgv;
int managedAssemblyArgc;
if (!ParseArguments(
argc,
argv,
&clrFilesPath,
&managedAssemblyPath,
&managedAssemblyArgc,
&managedAssemblyArgv))
{
// Invalid command line
return -1;
}
// Check if the specified managed assembly file exists
struct stat sb;
if (stat(managedAssemblyPath, &sb) == -1)
{
perror("Managed assembly not found");
return -1;
}
// Verify that the managed assembly path points to a file
if (!S_ISREG(sb.st_mode))
{
fprintf(stderr, "The specified managed assembly is not a file\n");
return -1;
}
// Make sure we have a full path for argv[0].
std::string argv0AbsolutePath;
if (!GetEntrypointExecutableAbsolutePath(argv0AbsolutePath))
{
perror("Could not get full path");
return -1;
}
std::string clrFilesAbsolutePath;
if(!GetClrFilesAbsolutePath(argv0AbsolutePath.c_str(), clrFilesPath, clrFilesAbsolutePath))
{
return -1;
}
std::string managedAssemblyAbsolutePath;
if (!GetAbsolutePath(managedAssemblyPath, managedAssemblyAbsolutePath))
{
perror("Failed to convert managed assembly path to absolute path");
return -1;
}
int exitCode = ExecuteManagedAssembly(
argv0AbsolutePath.c_str(),
clrFilesAbsolutePath.c_str(),
managedAssemblyAbsolutePath.c_str(),
managedAssemblyArgc,
managedAssemblyArgv);
return exitCode;
}
int main(const int argc, const char* argv[])
{
return corerun(argc, argv);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,56 @@
// 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 <string>
// Get the path to entrypoint executable
bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable);
// Get absolute path from the specified path.
// Return true in case of a success, false otherwise.
bool GetAbsolutePath(const char* path, std::string& absolutePath);
// Get directory of the specified path.
// Return true in case of a success, false otherwise.
bool GetDirectory(const char* absolutePath, std::string& directory);
//
// Get the absolute path to use to locate libcoreclr.so and the CLR assemblies are stored. If clrFilesPath is provided,
// this function will return the absolute path to it. Otherwise, the directory of the current executable is used.
//
// Return true in case of a success, false otherwise.
//
bool GetClrFilesAbsolutePath(const char* currentExePath, const char* clrFilesPath, std::string& clrFilesAbsolutePath);
// Add all *.dll, *.ni.dll, *.exe, and *.ni.exe files from the specified directory to the tpaList string.
void AddFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList);
//
// Execute the specified managed assembly.
//
// Parameters:
// currentExePath - Path to the current executable
// clrFilesAbsolutePath - Absolute path to the folder where the libcoreclr.so and CLR managed assemblies are stored
// managedAssemblyPath - Path to the managed assembly to execute
// managedAssemblyArgc - Number of arguments passed to the executed assembly
// managedAssemblyArgv - Array of arguments passed to the executed assembly
//
// Returns:
// ExitCode of the assembly
//
int ExecuteManagedAssembly(
const char* currentExeAbsolutePath,
const char* clrFilesAbsolutePath,
const char* managedAssemblyAbsolutePath,
int managedAssemblyArgc,
const char** managedAssemblyArgv);
#if defined(__APPLE__)
#include <mach-o/dyld.h>
static const char * const coreClrDll = "libcoreclr.dylib";
#else
static const char * const coreClrDll = "libcoreclr.so";
#endif