AppHost: Support bundles (stage 1) (dotnet/core-setup#5742)
authorSwaroop Sridhar <Swaroop.Sridhar@microsoft.com>
Sun, 14 Apr 2019 06:29:25 +0000 (23:29 -0700)
committerGitHub <noreply@github.com>
Sun, 14 Apr 2019 06:29:25 +0000 (23:29 -0700)
commit15537d9321d7b3aef4c8da62eefbd71df371076a
treef557e11003fe33abf7a29e1a0a90ffa734addac9
parentf1f1e931bc66a9c8a0acd16a231d4134330d1509
AppHost: Support bundles (stage 1) (dotnet/core-setup#5742)

* AppHost: Support bundles (stage 1)

This changes implements the [app-host support](https://github.com/dotnet/designs/blob/master/accepted/single-file/design.md#the-host )
for executing .net core apps published as a single file.

This change implements [stage 1](https://github.com/dotnet/designs/blob/master/accepted/single-file/staging.mddotnet/core-setup#1-self-extractor),
which [extracts out](https://github.com/dotnet/designs/blob/master/accepted/single-file/extract.md ) the embedded files to disk.

On startup, the AppHost detects whether it's own binary is a .net core bundle.
If so, on the first run, the host extracts embedded files to:
  * if `DOTNET_BUNDLE_EXTRACT_BASE_DIR` is set, to `$DOTNET_BUNDLE_EXTRACT_BASE_DIR/.net/<app>/<id>/...` . Otherwise,
  * On Windows, to `%TEMP%/.net/<app>/<id>/...`
  * On Unix systems, if `$TMPDIR` is set, to `$TMPDIR/.net/<app>/<id>/...` . Otherwise to `/var/tmp` or `/tmp` if those paths are available and accessible.

On subsequent runs, the files extracted above are reused.

AppHost (X64) size increase:
Windows 5KB
Linux 11KB
Mac 6KB

Testing:
Tested the single-file extraction locally with several kinds of dotnet apps
(wpf, winforms, web, mvc, console, etc.)
Added a test case that runs a bundled apps with sub directories
Also fixed a bug in the Microsoft.NET.HostModel.extractor wrt processing bundled files in chunks.

Commit migrated from https://github.com/dotnet/core-setup/commit/4a01e55806b0849a08b820518e8cdcbeaaf07476
19 files changed:
src/installer/corehost/cli/apphost/CMakeLists.txt
src/installer/corehost/cli/apphost/bundle/bundle_runner.cpp [new file with mode: 0644]
src/installer/corehost/cli/apphost/bundle/bundle_runner.h [new file with mode: 0644]
src/installer/corehost/cli/apphost/bundle/file_entry.cpp [new file with mode: 0644]
src/installer/corehost/cli/apphost/bundle/file_entry.h [new file with mode: 0644]
src/installer/corehost/cli/apphost/bundle/file_type.h [new file with mode: 0644]
src/installer/corehost/cli/apphost/bundle/manifest.cpp [new file with mode: 0644]
src/installer/corehost/cli/apphost/bundle/manifest.h [new file with mode: 0644]
src/installer/corehost/common/pal.h
src/installer/corehost/common/pal.unix.cpp
src/installer/corehost/common/pal.windows.cpp
src/installer/corehost/common/utils.cpp
src/installer/corehost/corehost.cpp
src/installer/corehost/error_codes.h
src/installer/managed/Microsoft.NET.HostModel/Bundle/Extractor.cs
src/installer/managed/Microsoft.NET.HostModel/Bundle/FileEntry.cs
src/installer/managed/Microsoft.NET.HostModel/Bundle/Manifest.cs
src/installer/test/HostActivationTests/BundledAppWithSubDirs.cs [new file with mode: 0644]
src/installer/test/HostActivationTests/HostActivationTests.csproj