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

[post build lint] Check for absolute paths #172

Merged
merged 68 commits into from
Jan 20, 2023

Conversation

autoantwort
Copy link
Contributor

@autoantwort autoantwort commented Aug 25, 2021

@Neumann-A
Copy link
Contributor

vcpkg_fixup_pkgconfig.cmake sets the cmake variable VCPKG_FIXUP_PKGCONFIG_CALLED so this could be moved into ports.cmake instead. Or make vcpkg read that additional variable.

@autoantwort autoantwort force-pushed the check-pkg-config-files branch from 6caebcb to a21a9c5 Compare August 25, 2021 18:13
@autoantwort
Copy link
Contributor Author

vcpkg_fixup_pkgconfig.cmake sets the cmake variable VCPKG_FIXUP_PKGCONFIG_CALLED so this could be moved into ports.cmake instead. Or make vcpkg read that additional variable.

Yeah possible, but theoretically one could pass the params RELEASE_FILES and DEBUG_FILES to vcpkg_fixup_pkgconfig so that it misses some files that are then not fixed.

@strega-nil-ms
Copy link
Contributor

I think I agree with @Neumann-A here; or at least, I think that'd be a better check. For here, I want to check for absolute paths generally, since someone might not set prefix in their pkgconfig file but it's still incorrect and needs to be fixup'd.

@autoantwort
Copy link
Contributor Author

For here, I want to check for absolute paths generally, since someone might not set prefix in their pkgconfig file but it's still incorrect and needs to be fixup'd.

That was now also proposed in microsoft/vcpkg#20321

@autoantwort autoantwort force-pushed the check-pkg-config-files branch from a21a9c5 to 2d4aab1 Compare September 24, 2021 15:56
@autoantwort autoantwort changed the title [post build lint] Check if vcpkg_fixup_pkgconfig was called [post build lint] Check for absolute paths Sep 24, 2021
@autoantwort
Copy link
Contributor Author

Same PR but now checks for absolute paths

@autoantwort autoantwort force-pushed the check-pkg-config-files branch from 67534e1 to 863231d Compare October 6, 2021 10:37
@strega-nil-ms
Copy link
Contributor

@autoantwort would you mind not force pushing to one commit? It makes it really difficult to review, and we're going to squash and merge at the end anyways.

Copy link
Contributor

@strega-nil-ms strega-nil-ms left a comment

Choose a reason for hiding this comment

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

Some more things to make sure this works well.

src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
@autoantwort
Copy link
Contributor Author

@autoantwort would you mind not force pushing to one commit? It makes it really difficult to review, and we're going to squash and merge at the end anyways.

Yeah sure. I normally use gitlab where you have compare to previous version, but github does not support that.

@autoantwort autoantwort force-pushed the check-pkg-config-files branch from 0689e6b to 326672e Compare October 12, 2021 19:26
include/vcpkg/base/util.h Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
Copy link
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

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

I agree with @vicroms that this needs e2e tests.

I prepared a commit with fixes for most of what I noticed I would like to see taken but it's enough change that I don't want to just push it on you:

https://github.com/BillyONeal/vcpkg-tool/tree/check-pkg-config-files /

BillyONeal@4eef012

src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
@@ -218,6 +220,8 @@ namespace vcpkg::Strings

Optional<StringView> find_at_most_one_enclosed(StringView input, StringView left_tag, StringView right_tag);

bool contains_any_ignoring_c_comments(const std::string& source, View<StringView> to_find);
Copy link
Member

Choose a reason for hiding this comment

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

source should be a StringView

src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
Comment on lines 1086 to 1096
for (size_t offset = 0;;)
{
const auto index = path_and_contents.second.find(path, offset);
if (index == std::string::npos) return false;
{ // .py, .sh, .cmake or .pc file
const auto before = path_and_contents.second.find_last_of("\n#", index);
if (before == std::string::npos) return true;
if (path_and_contents.second[before] == '\n') return true; // not a comment
}
offset = index + path.size();
}
Copy link
Member

Choose a reason for hiding this comment

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

This part looks extractable like contains_any_ignoring_c_comments. And it should handle #s not at the start of a line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does that

src/vcpkg/base/strings.cpp Outdated Show resolved Hide resolved
src/vcpkg/base/strings.cpp Outdated Show resolved Hide resolved
@@ -1088,6 +1090,11 @@ namespace vcpkg
"One or more {vendor} credential providers failed to authenticate. See '{url}' for more details "
"on how to provide credentials.");
DECLARE_MESSAGE(FeedbackAppreciated, (), "", "Thank you for your feedback!");
DECLARE_MESSAGE(FilesContainAbsolutePath,
Copy link
Member

Choose a reason for hiding this comment

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

This needs to tell the user about the policy now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought the policy should only be used internally to that merging this PR does the break the world. Imho we should not tell the users how to ignore warnings that warns before broken packages.

@autoantwort
Copy link
Contributor Author

I have tested your patch. It gives a lot of false positives (probably a bug somewhere) and it is 4 times slower then the current implementation (500 ms vs 2.2 seconds for qtbase)

@BillyONeal
Copy link
Member

I have tested your patch. It gives a lot of false positives (probably a bug somewhere)

For example? Note that the raw string literal bug effectively causes everything after the raw string literal to be considered part of it most of the time. I also didn't write tests around the python one so there are likely issues there.

it is 4 times slower then the current implementation (500 ms vs 2.2 seconds for qtbase)

Yeah I did no perf testing yet. What I did gives up on the potential simd that find_first_of does. I just spent over 4 hours trying to prove correctness of this PR yesterday and that's as far as I got. As written the cyclomatic complexity was ... high :)

@autoantwort
Copy link
Contributor Author

For example?

The problem was

            if (!file_contains_absolute_paths(fs, file, stringview_paths))
            {
                failing_files.push_back(file); // mark as failing file if it does not contains an absolute paths
            }

I just spent over 4 hours trying to prove correctness of this PR yesterday and that's as far as I got. As written the cyclomatic complexity was ... high :)

Thank you for the effort :) ❤️

@BillyONeal
Copy link
Member

OMG I flipped the answer? 🤣😂🤣

@BillyONeal
Copy link
Member

@vicroms outstanding comment is that he wants an e2e test for the failing cases.

Copy link
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

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

@vicroms Can you OK this?

@autoantwort autoantwort force-pushed the check-pkg-config-files branch from 7798f61 to 5222349 Compare January 18, 2023 12:50
@BillyONeal BillyONeal merged commit fcfbfa4 into microsoft:main Jan 20, 2023
@BillyONeal
Copy link
Member

Thank you for your efforts in making a better package catalog, and a better vcpkg <3

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.

8 participants