-
Notifications
You must be signed in to change notification settings - Fork 406
Adding headers to test common header files #5903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
1ee97ff
26bc944
54f6d09
dd2943e
50adacc
8a773ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| #ifndef __WINDOWSAPPRUNTIME_TEST_BOOTSTRAP_H | ||
| #define __WINDOWSAPPRUNTIME_TEST_BOOTSTRAP_H | ||
|
|
||
| #include <windows.h> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't include windows.h. As mentioned that's not always the right answer, and it's such a universal pervasive thing it's not helpful here and can be harmful |
||
| #include <MddBootstrap.h> | ||
| #include <MddBootstrapTest.h> | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| // Copyright (c) Microsoft Corporation and Contributors. All rights reserved. | ||
| // Copyright (c) Microsoft Corporation and Contributors. All rights reserved. | ||
guimafelipe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Licensed under the MIT License. | ||
|
|
||
| #ifndef __WINDOWSAPPRUNTIME_TEST_TAEF_CPPWINRT_H | ||
| #define __WINDOWSAPPRUNTIME_TEST_TAEF_CPPWINRT_H | ||
|
|
||
| #include <windows.h> | ||
guimafelipe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <winrt/base.h> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This leaves me uneasy for reasons I can't quite articulate at the moment (perhaps not enough coffee?) Aha. Found it. The source of my uneasiness... Is base.h a well defined part of C++/WinRT's API or just an implementation detail? e.g. https://learn.microsoft.com/en-us/uwp/cpp-ref-for-winrt/hstring but nowhere on that page does it say the header(s) you need to include (unlike, say, CreateFileW docs say what header (+lib) is needed), nor is it mentioned in any example. I know about this header, but I've pored over C++/WinRT's generated headers and implementation in more detail than most. Is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first mention of it I have is here, where it shows how to include |
||
| #include <WexTestClass.h> | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| namespace WEX::TestExecution | ||
| { | ||
| // Teach TAEF how to format a winrt::hstring | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
Is this currently a problem or is this a stylistic change?
This is the most obvious example - why does this need to include
windows.h? That's routinely the 1st include in any precompiled header, and in any source file in projects not using precompiled headers. Also, some include<unknown.h>rather thanwindows.h(the former includes the latter, plus other things).I don't see the value including
windows.hin any header file (except precomp.h/pch.h)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current problem is that for some of these headers, you can't include them alone without including these dependencies before in your file. Creating a new test that uses one of these headers requires knowing what they depend on, and it is not possible to just include the header that you actually want to use alone, requiring the include of
windows.hbefore including the desire header for example.I think it is a good practice to have headers that work as their own (by being possible to compile a
.cppfile including only it, which is what I mean when I say a header can be compiled) and it would make it easier for others to use them within the project.For this specific case, this header can be compile on its own because it includes
windows.hwithinappmodel.h, but it is hidden under a conditional macro. So I included it here to make it safer.Do you think there are any downsides on doing this change? We can close this PR if it is not desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be some merits to parts of it, but as is it's too broad a change e.g. don't add
windows.hto any header file (e.g. cause complications if someone usesunknown.h). There's a hard balance here as there's also the problem where includes can intersect in...interesting ways, if not identical includes and order, and headers including headers make any removal of includes problematic as the header evolves e.g. a.h includes b.h because it need something, but later a.h is split into a.h and x.h and now b.h isn't needed in a.h...but someone who included a.h assumed b.h's were available and now you create downstream build breaks, even though your code using a.h works fine TL;DR easy to add includes , hard to remove.I'd be more receptive to a PR making changes specifically because a new test was being stood up and it showed build errors because of some assumed includes, in which case (perhaps) add (some?) of those in these headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this desirable? For a simple example, we can have
a.hincluding<string>:And then, another header includes
a.hand uses the<string>that is exposed by it:If suddenly
a.hremoves the#include <string>, the files that only includessome-header.hand not<string>will break. But that break will be at compile time and will be correct in my opinion becausesome-header.hshould be including<string>as it is a direct dependency. So this build break will force a change in the correct direction, stopping a usage of a indirect include that was not clear.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is per C++ core guidelines and this too
if you can include less than
windows.hplease doUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is that there headers uses type definitions and functions that comes from header internal from
windows.h. And these internal headers are dependent on the macros defined inwindows.hto function.For example, here on
WindowsAppRuntime.Test.AppModel.h, the typeUINT32is defined inbasetsd.hWhich behaves well if included directly.But on
WindowsAppRuntime.Test.TAEF.hfor example, we use thePCWSTRandWCHARtypes, which are both defined inwinnt.h. This header depends of an architecture (something like_AMD64_) being defined, or it errors with#error "No Target Architecture". And this is defined by thewindows.hheader. The same would happen with we just include theminwindef.hheader that internally includeswinnt.h.I went to the
windows.hheader here because that is what essentially being included in thepch.hfile for the compilation of the tests alongside withunknwn.hin some of them (which internally includeswindows.hon line 29).Some of the tests include
windows.hright after a#define WIN32_LEAN_AND_MEANto exclude rerely-used stuff, which can also help to keep things small there.Any thoughts or suggestions?
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChrisGuzak do those guidelines also apply to windows.h? I'd generally find it extremely-weird to see code #include'ing basetsd.h, minwindef.h or other parts of windows.h. And there doesn't seem a lot of merit #include'ing windows.h in headers given nearly every .h uses basic constructs from windows.h (PCWSTR, UINT32, DWORD, ...). Perhaps this is worthy of discussion at our next API Design meeting?
@guimafelipe Any such definitions should occur in pch.h before any #include (pretty much the only thing I'd expect to see in pch.h between line1 //Copyright... and line2+ #include's)
TBH I never heard of
unknown.hbefore working in WinAppSDK 0.x, nor would I have expected the weird build errors mixing unknown.h vs windows.h if I it didn't draw blood on multiple occasions :-( Could be a dated problem buit this isn't the sort of stuff that changes often or quickly, so I'm hesitant to slather windows.h everywhere. Not without a better understanding of the merit (like, discussion at our next API meeting).