terminal/src
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
..
buffer Replace some macros with constexpr (#3362) 2019-11-01 10:33:09 -07:00
cascadia Introduce a WinRT utils library and "checked resources" (#3350) 2019-11-01 15:47:05 -07:00
host Replace some macros with constexpr (#3362) 2019-11-01 10:33:09 -07:00
inc Add support for passing through extended text attributes, like… (#2917) 2019-10-04 15:53:54 -05:00
interactivity Switch all of the UIA providers to WRL::RuntimeClass (#3213) 2019-10-17 15:32:30 -07:00
internal add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
propsheet Prevent the v1 propsheet from zeroing colors, causing black text on black background. (#2651) 2019-10-02 16:04:59 -07:00
propslib Prevent the v1 propsheet from zeroing colors, causing black text on black background. (#2651) 2019-10-02 16:04:59 -07:00
renderer Introduce UiaRenderer project (#2930) 2019-10-28 09:42:54 -07:00
server Replace ExpandEnvironmentStrings double calling with wil helper (#3198) 2019-10-15 14:51:33 -07:00
terminal Replace some macros with constexpr (#3362) 2019-11-01 10:33:09 -07:00
testlist inbox: Merge accumulated build fixes from RS_ONECORE_DEP_ACIOSS (#1002) 2019-05-24 12:28:30 -07:00
tools Sync with latest inbox changes 2019-10-17 15:11:07 -07:00
tsf Reflect inbox changes in 8c63dff 2019-09-03 13:32:31 -07:00
types Switch all of the UIA providers to WRL::RuntimeClass (#3213) 2019-10-17 15:32:30 -07:00
winconpty Combined changes to make the build work again (see inside) (#2945) 2019-09-30 10:39:55 -07:00
common.build.dll.props Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
common.build.exe.or.dll.props Switch to v5 UUIDs as profile GUIDs for the default profiles (#913) 2019-05-21 13:29:16 -07:00
common.build.exe.props Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
common.build.lib.props Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
common.build.post.props Fix our parallel (and repeating) builds (#3412) 2019-11-01 14:38:13 -07:00
common.build.pre.props Set utf-8 for the entire project (#1929) 2019-07-11 13:13:10 -07:00
common.build.tests.props Refactor TerminalApp and Add Tests for Xaml Content (#1164) 2019-07-15 14:27:56 -05:00
ConsolePerf.regions.xml Tab to spaces (#578) 2019-05-13 18:06:36 -07:00
ConsolePerf.wprp Tab to spaces (#578) 2019-05-13 18:06:36 -07:00
cppwinrt.build.post.props Update a number of our dependencies (#2301) 2019-08-07 16:43:49 -07:00
cppwinrt.build.pre.props Introduce a WinRT utils library and "checked resources" (#3350) 2019-11-01 15:47:05 -07:00
dirs Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
project.inc Sync with latest inbox changes 2019-10-17 15:11:07 -07:00
project.unittest.inc inbox: merge refactoring payload from FI 2019-06-11 17:01:26 -07:00
StaticAnalysis.ruleset Combined changes to make the build work again (see inside) (#2945) 2019-09-30 10:39:55 -07:00
unit.tests.x64.runsettings Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
unit.tests.x86.runsettings Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
wap-common.build.post.props Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
wap-common.build.pre.props Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00