Repository navigation
Add fallback for MrmGetFilePathFromName - #5828
Yuyi Wang (Berrysoft) wants to merge 4 commits into
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| if ((pass == SearchPass::DefaultFallback) || | ||
| ((attributes != INVALID_FILE_ATTRIBUTES) && !(attributes & FILE_ATTRIBUTE_DIRECTORY))) |
There was a problem hiding this comment.
I think this is going to need an audit of all the code in MUX and WAS where MRM was expected to fail right? (e.g., https://github.com/microsoft/WindowsAppSDK/blob/main/dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/Helper.cpp#L77-L103)
There was a problem hiding this comment.
There are two paths calling this method. One is the ResourceManager:
which is OK if the file not found, and is expected (
WindowsAppSDK/dev/MRTCore/mrt/Core/src/MRM.cpp
Lines 966 to 967 in 9bde038
which will fail if it cannot find the pri file.
There was a problem hiding this comment.
Indeed - thanks for the heads up. Code like that will now need to test for nonexistent path as well (not just S_OK).
There was a problem hiding this comment.
Do I need to add tests in this PR?
There was a problem hiding this comment.
that would be great, Yuyi Wang (@Berrysoft) - thanks
There was a problem hiding this comment.
Well. I have to admit that the PR was created more than half a year before. I need some time to investigate how to add the tests. If it is a must, I'll do it later. But if it is not, I think I'll keep the PR as-is.
Before 1.8, all code works well with the nonexistent path. Furthermore, I have been live-patching the MRM.dll since 1.8 to the latest 2.2. The patch always works well with all versions' WinUI. So I think this PR doesn't break the code.
There was a problem hiding this comment.
Hello, Scott Jones (@Scottj1s) Rafael Rivera (@riverar) . I read the test code in this repo and found that it already contains tests for this case:
WindowsAppSDK/dev/MRTCore/mrt/Core/unittests/MrmTests.cpp
Lines 687 to 690 in e858676
But I don't know why it didn't fail before this PR. I think I don't need to add other tests. They already fill the need.
There was a problem hiding this comment.
Did the audit. Both callers of MrmGetFilePathFromName are fine: ResourceManager already tolerates a missing PRI (only its check_hresult(GetDefaultPriFile) gate was breaking on the 1.8 ERROR_FILE_NOT_FOUND regression), and ResourceLoader throws with or without the change by design. The one internal path that keyed off the failure was GetDefaultPriFile's sparse-packaged [modulename].pri fallback (added in #6376), which gated on IsResourceNotFound(hr) — since the fix makes MrmGetFilePathFromName return S_OK, that now gates on actual file existence (CheckFile) instead. Handled in #6603.
There was a problem hiding this comment.
On tests: MrmTests::GetFilePath and MrtCoreUnpackagedTests.TestClass.DefaultResourceManager already cover this — they just didn't catch the original regression because they were on the BypassTests.json allowlist (added in #5498, extended in #5919, after the regression). #6603 un-bypasses both and strengthens GetFilePath. Verified locally: MrmUnitTest 21/21, MrtCoreUnpackagedTests 27/27.
There was a problem hiding this comment.
Awesome work Scott Jones (@Scottj1s), thank you. Squeaking a little more to get this landed too.
Co-authored-by: Rafael Rivera <rafael@withinwindows.com>
|
Can we slot this in for the next preview build Scott Jones (@Scottj1s) Roy (@RDMacLachlan)? This is impacting reactor projects downstream. |
|
Hello Scott Jones (@Scottj1s) , is it still possible to merge this PR? |
|
Thanks for this, Yuyi Wang (@Berrysoft) — I've opened #6603 to wrap it up on top of your change. The |
|
Thanks! |
Thanks for opening the issue, suggesting a fix, and waiting patiently - much appreciated. |
…(supersedes #5828) (#6603) * Add fallback for MrmGetFilePathFromName * Update dev/MRTCore/mrt/Core/src/MRM.cpp Co-authored-by: Rafael Rivera <rafael@withinwindows.com> * Complete MrmGetFilePathFromName fallback: return S_OK with a valid path PR #5828 added a DefaultFallback search pass to restore the documented "always succeed, return a best-effort path" contract of MrmGetFilePathFromName (regressed in #4965 to return ERROR_FILE_NOT_FOUND, breaking ResourceManager creation when no resources.pri exists - #5814 / #5940). However DefaultFallback was unreachable: both terminal passes (ParentPathForFileName, exeDirForModulePri) jumped to Final, skipping it. The function therefore returned S_OK with *filePath == nullptr, which crashes callers that dereference the path (e.g. MrmCreateResourceManager rejects an empty path with E_INVALIDARG, and the GetFilePath unit test AVs on wcsstr). Changes: - MRM.cpp: route both terminal passes into DefaultFallback so it runs as the final pass; return S_OK with a non-null best-effort path (the provided filename, else resources.pri) under the base directory (if set) otherwise the module directory - matching pre-#4965 (legacy) behavior. Preserve the module directory since the parent-folder search mutates exeDir in place. - Helper.cpp (GetDefaultPriFile): the sparse-packaged [modulename].pri fallback gated on IsResourceNotFound(hr); since MrmGetFilePathFromName now returns S_OK, gate on actual file existence (CheckFile) instead, and only adopt the unpackaged result if it resolves to an existing file (avoids re-regressing #6376 / microsoft-ui-xaml#10856). - MrmTests.cpp: strengthen GetFilePath to assert the fallback path is under the module directory. - BypassTests.json: remove the now-passing UnitTest::BasicTest::GetFilePath and MrtCoreUnpackagedTests.TestClass.DefaultResourceManager entries so they gate again (they were bypassed in #5498 / #5919 after the #4965 regression, which is why the regression shipped undetected). Verified locally (x64 Debug): MrmUnitTest 21/21, MrtCoreUnpackagedTests 27/27. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: 王宇逸 <Strawberry_Str@hotmail.com> Co-authored-by: Rafael Rivera <rafael@withinwindows.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
This PR is not needed now, I think? Regarding that #6603 has been merged. |
|
Did that fix ship in a release we can test with? |
|
Any updates on this? cc: Scott Jones (@Scottj1s) |
|
I don't know if there's a release, but it seems that this PR is not needed. |
|
I'm confused because it seems like Scott Jones (@Scottj1s) was building on top of this PR, not replacing it. |
|
I see now, you're right. This PR was superseded and never cleaned up. The lack of normal GitHub usage patterns by this team continues to frustrate me. |
|
Yuyi Wang (@Berrysoft) , Rafael Rivera (@riverar) - fix has been cherry picked for August's 1.8 and 2.0 servicing releases (note: usual caveats, schedules always subject to change) |
fair - I considered building on top of this PR, and do appreciate your contribution, Yuyi Wang (@Berrysoft). there was enough divergence to warrant a new PR. |
Thanks, Scott Jones (@Scottj1s) ! However, when I'm using the latest WinUI3 (2.3.1.0), |
|
I was confused too because at one point the PR or commits were tagged 2.3.1.0. Update: This commit is tagged 2.3.1.0. 91160b0 So now we wait for August release! |
Closes #5814
Closes #5940
According to the docs, this method should success even if no resource file is found.