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

Alternative way of setting properties that depend on generator specific features. #8727

Merged
merged 60 commits into from Apr 15, 2021

Conversation

czoido
Copy link
Contributor

@czoido czoido commented Mar 29, 2021

Changelog: Feature: Add set_property and get_property to set properties and access them in generators. Can be set only for a specific generator or as a default value for all of them.
Changelog: Feature: Use set_property and get_property to support custom defined content in pkg_config generator.
Changelog: Feature: Add new property names: cmake_target_name, cmake_file_name, pkg_config_name and cmake_build_modules that can be used for multiple generators of the same type allowing also an easier migration of names, filenames and build_modules properties to this model.
Docs: conan-io/docs#2082

Closes: #7661 , #8600

Set properties of the cpp_info that are related to generators (things like names, filenames, build_modules...) with set_property and get_property. Tests with filenames, names and build_modules properties.
Using new properties names cmake_target_name, cmake_file_name, pkg_config_name and cmake_build_modules will make the migration a little bit less risky. The new property name will be given preferences over the old one.

This:

self.cpp_info.components["mycomponent"].names["cmake_find_package"] = "mycomponent-name"
self.cpp_info.components["mycomponent"].names["cmake_find_package_multi"] = "mycomponent-name"

would be expressed as this:

self.cpp_info.components["mycomponent"].set_property("cmake_target_name", "mycomponent-name")

It's also possible to make it specific for generator but that most of cases it won't be necessary:

self.cpp_info.components["mycomponent"].set_property("cmake_target_name", "mypkg-name", "cmake_find_package")

Also, not specifying the generator will set this value as a default for every generator. So if you set:

self.cpp_info.components["mycomponent"].set_property("my-property", "mycomponent-name")

A new custom generator can access that information with:

for pkg_name, cpp_info in self.deps_build_info.dependencies:
    names = cpp_info.get_property("my-property", generator=self.name))

Related to: #8600, #8568 and #7661

#tags: slow

@czoido czoido marked this pull request as draft March 29, 2021 15:37
Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

I like the idea of generalizing the information for generators, keep going

Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

This is looking very good, I like it.

conans/model/build_info.py Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
@czoido czoido marked this pull request as ready for review April 6, 2021 17:13
Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

Some points to consider and to discuss, I still need to understand a bit more the new migration proposal, now that it seems there is no longer an internal translation to properties.

import textwrap
import os

class custom_generator(GeneratorComponentsMixin, Generator):
Copy link
Member

Choose a reason for hiding this comment

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

We need to get rid of this inheritance too. New generators do not need to extend anything, just implement generate() method. Components helpers should go elsewhere.

Not now, not in this PR, but in the future.

conans/model/build_info.py Outdated Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
conans/model/build_info.py Outdated Show resolved Hide resolved
Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

A couple of minor stylistic things, but overall good job, I think this is ready to be merged

if result:
return result
return self.get_name(generator)

# TODO: Deprecate for 2.0. Use get_property for 2.0
def get_build_modules(self):
Copy link
Member

Choose a reason for hiding this comment

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

It is a bit undesired that this is called so many times, it could be cached, but the above is redefining self.build_modules = BuildModulesDict.from_list(self.get_build_modules()), which is used in the method, so that might break such caching.

Recall that things in CppInfo might be called mamy many times while propagating graph, so this is one of the bottlenecks in graph resolution, we should be careful with adding here inefficient things.

client.run("create mypkg.py")
client.run("install consumer.py -s build_type=Release")

old_approach_contents = get_files_contents(client.current_folder, files_to_compare)
Copy link
Member

Choose a reason for hiding this comment

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

I like very much these tests comparing the previous and new results, good job

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.

[feature] Allow arbitrary sections in pkg_config .pc files
2 participants