terminal/src/cascadia
Dustin L. Howett (MSFT) 15505337d8
Introduce a WinRT utils library and "checked resources" (#3350)
This commit introduces a C++/WinRT utility library and moves
ScopedResourceLoader into it. I decided to get uppity and introduce
something I like to call "checked resources." The idea is that every
resource reference from a library is knowable at compile time, and we
should be able to statically ensure that all resources exist.

This is a system that lets us immediately failfast (on launch) when a
library makes a static reference to a resource that doesn't exist at
runtime.

It exposes two new (preprocessor) APIs:
* `RS_(wchar_t)`: loads a localizable string resource by name.
* `USES_RESOURCE(wchar_t)`: marks a resource key as used, but is intended
  for loading images or passing static resource keys as parameters to
  functions that will look them up later.

Resource checking relies on diligent use of `USES_RESOURCE()` and `RS_()`
(which uses `USES_RESOURCE`), but can make sure we don't ship something
that'll blow up at runtime.

It works like this:

**IN DEBUG MODE**
- All resource names referenced through `USES_RESOURCE()` are emitted
  alongside their referencing filenames and line numbers into a static
  section of the binary.
  That section is named `.util$res$m`.

- We emit two sentinel values into two different sections, `.util$res$a`
  and `.util$res$z`.

- The linker sorts all sections alphabetically before crushing them
  together into the final binary.

- When we first construct a library's scoped resource loader, we
  iterate over every resource reference between `$a` and `$z` and check
  residency.

**IN RELEASE MODE**
- All checked resource code is compiled out.

Fixes #2146.

Macros are the only way to do something this cool, incidentally.

## Validation Steps Performed
Made references to a bunch of bad resources, tried to break it a lot.

It looks like this when it fails:

### App.cpp
```
36  static const std::array<std::wstring_view, 2> settingsLoadErrorsLabels {
37      USES_RESOURCE(L"NoProfilesText"),
38      USES_RESOURCE(L"AllProfilesHiddenText_HA_JUST_KIDDING")
39  };
```

```
WinRTUtils\LibraryResources.cpp(68)\TerminalApp.dll:
    FailFast(1) tid(1034) 8000FFFF Catastrophic failure
    Msg:[Resource AllProfilesHiddenText_HA_JUST_KIDDING not found in
      scope TerminalApp/Resources (App.cpp:38)] [EnsureAllResourcesArePresent]
```
2019-11-01 15:47:05 -07:00
..
CascadiaPackage Switch to a non-release build of MUXc to fix elevated launch (#3278) 2019-10-22 11:48:09 -07:00
inc Don't copy text if there's no selection (#2446) 2019-08-16 15:43:51 -07:00
LocalTests_TerminalApp Switch to a non-release build of MUXc to fix elevated launch (#3278) 2019-10-22 11:48:09 -07:00
PublicTerminalCore prevent double handling of tab in wpf control (#3316) 2019-10-24 15:45:04 -07:00
TerminalApp Introduce a WinRT utils library and "checked resources" (#3350) 2019-11-01 15:47:05 -07:00
TerminalConnection Get rid of our hand-rolled sprintf->wstring helpers, prefer WIL (#3106) 2019-10-08 12:04:18 -07:00
TerminalControl Fix scrollbar update after terminal close (#3256) 2019-11-01 09:40:29 -07:00
TerminalCore Revert two cursor changes that cause crashing and rendering art… (#3292) 2019-10-22 14:42:57 -07:00
TerminalSettings teach wil about c++/winrt exceptions by including cppwinrt.h (#2927) 2019-09-30 15:52:27 -07:00
UnitTests_TerminalCore Revert "Patch fix for #1360 (#2924)" (#3212) 2019-10-15 17:33:32 -07:00
ut_app Switch to a non-release build of MUXc to fix elevated launch (#3278) 2019-10-22 11:48:09 -07:00
WindowsTerminal Switch to a non-release build of MUXc to fix elevated launch (#3278) 2019-10-22 11:48:09 -07:00
WinRTUtils Introduce a WinRT utils library and "checked resources" (#3350) 2019-11-01 15:47:05 -07:00
WpfTerminalControl Fix our parallel (and repeating) builds (#3412) 2019-11-01 14:38:13 -07:00