Skip to content
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

[z-applocal] Reduce nonexistent and non-PE files to warnings. #1274

Merged
merged 3 commits into from
Nov 21, 2023

Conversation

BillyONeal
Copy link
Member

A customer tried to turn on our z-applocal built in replacement for applocal.ps1 and it failed on vcxprojs that produce no outputs, and vcxprojs that make static libraries in their testing. This change reduces both results to warnings and explains when there's an MZ signature mismatch better.

Before:

D:\vcpkg-tool\out\build\Win-x64-Debug-WithArtifacts\vcpkg.ps1 z-applocal --target-binary=D:\work\testing\applocal\basic\nonexisting.dll --installed-bin-dir=D:\work\testing/applocal/basic/installed/bin
vcpkg applocal processing: D:\work\testing\applocal\basic\nonexisting.dll
open_for_read("D:\work\testing\applocal\basic\nonexisting.dll"): no such file or directory

Exception: D:\vcpkg-tool\azure-pipelines\end-to-end-tests-dir\z-applocalcpp.ps1:94

D:\vcpkg-tool\out\build\Win-x64-Debug-WithArtifacts\vcpkg.ps1 z-applocal --target-binary=D:\work\testing/applocal/static-lib/static-lib.lib --installed-bin-dir=D:\work\testing/applocal/basic/installed/bin
vcpkg applocal processing: D:\work\testing\applocal\static-lib\static-lib.lib
Failed to read 4 bytes from D:\work\testing\applocal\static-lib\static-lib.lib at offset 538976288.

Exception: D:\vcpkg-tool\azure-pipelines\end-to-end-tests-dir\z-applocalcpp.ps1:113

After:

D:\vcpkg-tool\out\build\Win-x64-Debug-WithArtifacts\vcpkg.ps1 z-applocal --target-binary=D:\work\testing\applocal\basic\nonexisting.dll --installed-bin-dir=D:\work\testing/applocal/basic/installed/bin
D:\work\testing\applocal\basic\nonexisting.dll: message: deploying dependencies
D:\work\testing\applocal\basic\nonexisting.dll: warning: no such file or directory

D:\vcpkg-tool\out\build\Win-x64-Debug-WithArtifacts\vcpkg.ps1 z-applocal --target-binary=D:\work\testing/applocal/static-lib/static-lib.lib --installed-bin-dir=D:\work\testing/applocal/basic/installed/bin
D:\work\testing/applocal/static-lib/static-lib.lib: message: deploying dependencies
D:\work\testing/applocal/static-lib/static-lib.lib: warning: this file does not appear to be executable

ExpectedL<Unit> read_pe_signature_and_get_coff_header_offset(ReadFilePointer& f)
// reads f as a portable executable and checks for magic number signatures.
// if an I/O error occurs, returns the error; otherwise,
// returns iff signatures match
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// returns iff signatures match
// returns if signatures match

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentional (iff == if and only if)

AppLocalInvocation invocation(real_filesystem,

// the first binary is special in that it might not be a DLL or might not exist
const Path target_binary_path = target_binary->second;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const Path target_binary_path = target_binary->second;
const Path& target_binary_path = target_binary->second;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be wrong because there is a conversion intended here. (target_binary->second is a std::string, not a Path)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I'd use const Path target_binary_path(target_binary->second) to make the conversion more obvious.

Checks::exit_fail(VCPKG_LINE_INFO);
}

auto maybe_dll_metadata = vcpkg::try_read_dll_metadata(dll_file).value_or_exit(VCPKG_LINE_INFO);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use try_read_dll_metadata_required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the whole point of this is to use the not required one.

@BillyONeal BillyONeal merged commit a35ce80 into microsoft:main Nov 21, 2023
5 checks passed
@BillyONeal BillyONeal deleted the applocal-static-libs-and-empty branch November 21, 2023 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants