Added new shim for uwp console. Removed the constriction for the number of args....
authorSergei Ognerubov <seog@microsoft.com>
Thu, 14 Dec 2017 22:34:23 +0000 (14:34 -0800)
committerSergei Ognerubov <seog@microsoft.com>
Thu, 14 Dec 2017 22:34:23 +0000 (14:34 -0800)
Commit migrated from https://github.com/dotnet/core-setup/commit/e523a1a355fb8a88f39def321afb40dc6c954893

src/installer/uwp/Host/UWPShim/CMakeLists.txt
src/installer/uwp/Host/UWPShim/Console/CMakeLists.txt [new file with mode: 0644]
src/installer/uwp/Host/UWPShim/UWPShim.cpp
src/installer/uwp/Host/UWPShim/Windows/CMakeLists.txt [new file with mode: 0644]
src/installer/uwp/build.proj

index dc5c00e..d499c6d 100644 (file)
@@ -1,23 +1,2 @@
-include(../../../settings.cmake)
-
-add_definitions(-DUNICODE)
-add_definitions(-D_UNICODE)
-set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS")
-set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmain")
-set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
-
-include_directories("${CLI_CMAKE_RESOURCE_DIR}/uwpshim")
-link_directories(${UWPHOST_LIB_PATH})
-set (PLATFORM STORE)
-
-add_executable(UWPShim
-  uwpshim.cpp
-  native.rc
-)
-
-target_link_libraries(UWPShim
-    UWPHost
-    vcruntime
-)
-
-install(TARGETS UWPShim DESTINATION .)
+add_subdirectory(Console)
+add_subdirectory(Windows)
\ No newline at end of file
diff --git a/src/installer/uwp/Host/UWPShim/Console/CMakeLists.txt b/src/installer/uwp/Host/UWPShim/Console/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e070fd3
--- /dev/null
@@ -0,0 +1,23 @@
+include(../../../../settings.cmake)
+
+add_definitions(-DUNICODE)
+add_definitions(-D_UNICODE)
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmain")
+set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
+
+include_directories("${CLI_CMAKE_RESOURCE_DIR}/uwpshim")
+link_directories(${UWPHOST_LIB_PATH})
+set (PLATFORM STORE)
+
+add_executable(ConsoleUWPShim
+  ../uwpshim.cpp
+  ../native.rc
+)
+
+target_link_libraries(ConsoleUWPShim
+    UWPHost
+    vcruntime
+)
+
+install(TARGETS ConsoleUWPShim DESTINATION .)
index aa479bd..93a7442 100644 (file)
@@ -162,25 +162,23 @@ int __cdecl wmain()
     DWORD exitCode = -1;
     int argc;
     LPCWSTR* wszArglist = const_cast<LPCWSTR*>(SegmentCommandLine(GetCommandLineW(), &argc));
-    
-    if (argc < 2)
-    {
-        // Invalid number of arguments
-        return exitCode;
-    }
-    
+
     // This module is merely a shim to figure out what the actual EntryPoint assembly is and call the Host with 
     // that information. The EntryPoint would be found based on the following assumptions
     //
     // 1) Current module lives under the "CoreRuntime" subfolder of the AppX package installation folder.
     // 2) It has the same name as the EntryPoint assembly that will reside in the parent folder (i.e. the AppX package installation folder).
     
-    const wchar_t* pActivationModulePath = wszArglist[0];
+    wchar_t pActivationModulePath[MAX_PATH];
+    if (!GetModuleFileName(nullptr, pActivationModulePath, MAX_PATH))
+    {
+        return GetLastError();
+    }
 
     const wchar_t *pLastSlash = wcsrchr(pActivationModulePath, L'\\');
     if (pLastSlash == NULL)
     {
-        return exitCode;
+        TerminateProcess(GetCurrentProcess(), exitCode);
     }
     
     wchar_t entryPointAssemblyFileName[MAX_PATH];
@@ -190,6 +188,6 @@ int __cdecl wmain()
     
     auto success = ExecuteAssembly(entryPointAssemblyFileName, argc-1, &(wszArglist[1]), &exitCode);
 
-    return exitCode;
+    TerminateProcess(GetCurrentProcess(), exitCode);
 }
 
diff --git a/src/installer/uwp/Host/UWPShim/Windows/CMakeLists.txt b/src/installer/uwp/Host/UWPShim/Windows/CMakeLists.txt
new file mode 100644 (file)
index 0000000..16b7003
--- /dev/null
@@ -0,0 +1,23 @@
+include(../../../../settings.cmake)
+
+add_definitions(-DUNICODE)
+add_definitions(-D_UNICODE)
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmain")
+set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
+
+include_directories("${CLI_CMAKE_RESOURCE_DIR}/uwpshim")
+link_directories(${UWPHOST_LIB_PATH})
+set (PLATFORM STORE)
+
+add_executable(UWPShim
+  ../uwpshim.cpp
+  ../native.rc
+)
+
+target_link_libraries(UWPShim
+    UWPHost
+    vcruntime
+)
+
+install(TARGETS UWPShim DESTINATION .)
index 895e18d..92d3236 100644 (file)
@@ -26,7 +26,8 @@
 
     <ItemGroup>
       <CMakeOutput Include="$(IntermediateOutputRootPath)uwphost\host\uwphost\$(ConfigurationGroup)\uwphost.dll" />
-      <CMakeOutput Include="$(IntermediateOutputRootPath)uwpshim\$(ConfigurationGroup)\uwpshim.exe" />
+      <CMakeOutput Include="$(IntermediateOutputRootPath)uwpshim\Windows\$(ConfigurationGroup)\uwpshim.exe" />
+      <CMakeOutput Include="$(IntermediateOutputRootPath)uwpshim\Console\$(ConfigurationGroup)\consoleuwpshim.exe" />
       <CMakeOutput Include="$(IntermediateOutputRootPath)uwphost\copywin32resources\$(ConfigurationGroup)\copywin32resources.exe" />
     </ItemGroup>