Skip to content

Allow features with platform expressions #813

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

Merged

Conversation

autoantwort
Copy link
Contributor

@autoantwort autoantwort commented Nov 15, 2022

Allows

{
  "dependencies": [{
    "name": "spdlog",
    "features": [{"name": "wchar", "platform": "windows"}]
  }]
}

and

{
  "default-features": [{
    "name": "wchar",
    "platform": "windows"
  }]
}

@autoantwort autoantwort marked this pull request as ready for review November 16, 2022 16:55
…tead of using magic "core" feature.

This also solves the "issue" that I can pass ImplicitDefault::No to Dependency::to_full_spec to get default_features = false even when Dependency comes from a parsed manifest file with "default-features": true.
@ras0219-msft ras0219-msft self-requested a review December 21, 2022 18:46
autoantwort added a commit to autoantwort/vcpkg that referenced this pull request Jan 5, 2023
# Conflicts:
#	src/vcpkg/sourceparagraph.cpp
# Conflicts:
#	include/vcpkg/paragraphparser.h
#	src/vcpkg/paragraphs.cpp
@BillyONeal
Copy link
Member

BillyONeal commented Mar 16, 2023

Quoth @ras0219-msft:

I think "platform" is the correct term for both of the use cases here. "supports" is attached to an object (e.g. a feature definition or the top-level manifest) and indicates, without source, where the object is valid. "platform" is a qualifier on an 'edge' (e.g. dependency). The PR is adding qualifications to two edges: the default features (morally: x[default] -> x[<feature>]) and a new way to write the qualification of a standard dependency.

(That is to say, agreement with what you did here)

{
std::string name;
PlatformExpression::Expr platform;
Feature(std::string name) : Feature(std::move(name), PlatformExpression::Expr::Empty()) { }
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit nervous about this implicit conversion; too easy to accidentally chop the expression off.

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 is only relevant for the tests. It changes

{
     Dependency{"semver", {{"x"}}},
},

to

{
    Dependency{"semver", {Dependency::Feature{"x"}}},
},

I can change the 18 occurrences if you want.

const std::string& str,
StringView origin = "<unknown>",
TextRowCol textrowcol = {},
ImplicitDefault implicit_defaults = ImplicitDefault::YES);
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this is a layering problem. Just parsing the file shouldn't be doing the semantic transform to figure out what defaults are. Ideally we would have two types: one which is just the parsed guts, and another which is the parsed guts with expressions evaluated and applied.

I understand this suggestion is kind of a large/structural change though :(. @ras0219-msft Would you characterize my statement here as consistent with the dependencies stuff or do you think it's out of left field? (I think it's worth asking autowantwort to go here if this situation is a problem he created but not if we are already filthy about this elsewhere)

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 have now removed the parameter.

just parsing the file shouldn't be doing the semantic transform to figure out what defaults are.

It is not about what defaults are. It is about if defaults are requested or not. So currently we always use ImplicitDefault::YES while parsing.
liba => default-features: true
liba[core] => default-features: false
If we add a ImplicitDefault implicit_defaults parameter the following would be possible if ImplicitDefault::NO is passed:
liba => default-features: false
But this is semantic currently is never needed (except in one test) so I removed the parameter.

We could also introduce a new data type for the return value of this function but I currently don't see a value in that. If you really want it I would suggest do not do that in this PR to keep this PR small.

# Conflicts:
#	include/vcpkg/packagespec.h
#	include/vcpkg/paragraphparser.h
#	src/vcpkg/packagespec.cpp
# Conflicts:
#	src/vcpkg/sourceparagraph.cpp
# Conflicts:
#	src/vcpkg-test/dependencies.cpp
#	src/vcpkg/binaryparagraph.cpp
#	src/vcpkg/commands.build.cpp
#	src/vcpkg/dependencies.cpp
# Conflicts:
#	src/vcpkg-test/dependencies.cpp
#	src/vcpkg/dependencies.cpp
# Conflicts:
#	src/vcpkg-test/dependencies.cpp
@autoantwort
Copy link
Contributor Author

Resolving conflicts after #1014 was ... fun

@autoantwort
Copy link
Contributor Author

@ras0219-msft Anything that needs to be done here or is this PR only waiting for design approval?

Copy link
Contributor

@dan-shaw dan-shaw left a comment

Choose a reason for hiding this comment

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

Can you also open a new PR on vcpkg-docs to add documentation?

@autoantwort
Copy link
Contributor Author

Can you also open a new PR on vcpkg-docs to add documentation?

@dan-shaw I have created MicrosoftDocs/vcpkg-docs#114

@BillyONeal BillyONeal merged commit 51bd5bd into microsoft:main Jul 26, 2023
@BillyONeal
Copy link
Member

Thanks for the new feature!

@autoantwort autoantwort deleted the feature/features-with-platform-expressions branch July 26, 2023 01:00
@autoantwort
Copy link
Contributor Author

Whoop whoop 🥳 Thank you all for reviewing :)

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.

4 participants