[question] Define aliases that depends on settings and options
See original GitHub issueIt possible to define alias packages that use the settings and options to define the target packages?
My first approach, would be, for being able to get access to the settings
and options
when Conan is loading the recipe, to re-define the attribute alias
as a property using python decorator @property
. By doing this, the self
context is accessible. Here the recipe for the alias.
from conans import ConanFile
from conans.errors import ConanInvalidConfiguration
class BoostAliasConan(ConanFile):
name = 'boost'
version = 'latest'
revision_mode = 'hash'
settings = 'os', 'compiler'
options = {
'shared': [True, False],
}
default_options = {
'shared': True,
}
@property
def alias(self):
if self.settings.os == 'Windows':
if self.options.shared:
boost_version = '1.57.0'
else:
boost_version = '1.63.0'
elif self.settings.os == 'Linux':
boost_version = '1.72.0'
else:
raise ConanInvalidConfiguration('This configuration is not supported')
return f'boost/{boost_version}@user/stable'
When using the alias package boost/latest@user/stable
without specifying any option, the alias resolution is fine. But specifying option shared=False
on install
, then the alias recipe still will have the default value set. this results in getting boost version 1.57.0
instead of 1.63.0
.
What would be the right way to define such aliases?
- I’ve read the CONTRIBUTING guide.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
An Introduction to Useful Bash Aliases and Functions
Let's create a common bash alias now. One idiomatic command phrase that many people use frequently is ls -lha or ls -lhA (the...
Read more >Is it a good practice to use aliases? [closed]
First, you need to set the same alias on each computer. They behave differently on different computers, which can confuse others. Unless you ......
Read more >Aliases in Windows command prompt - Stack Overflow
To define a console alias, use Doskey.exe to create a macro, or use the AddConsoleAlias function. doskey. doskey test=cd \a_very_long_path\test. To also pass ......
Read more >Bash aliases you can't live without - Opensource.com
A Bash alias is a method of supplementing or overriding Bash commands with new ones. Bash aliases make it easy for users to...
Read more >Linux alias Command: How to Use It With Examples
In this tutorial, learn how to create, view, and remove temporary and permanent command shortcuts in Linux using the alias command.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
To follow up: it is not possible to use settings and options in alias to decide dynamically, and it would be quite complicated to implement, adding too much extra complexity when we are trying to simplify the alias logic.
In any case, it is possible to define a “proxy” recipe that implements the logic, (and can remove the variance of packages removing settings and options in
package_id()
.) That would be a regular recipe, not an alias, and will be represented in the dependency graph, but I don’t see a reason this won’t work.I’d say the question is responded and can be closed, if that approach doesn’t work, we could discuss why and what are the alternatives, but at the moment I am closing this because because it doesn’t seem something possible to implement reasonably.
I am afraid that such is some bad behavior, possibly because some internal caching in the legacy
requires = "foo/latest"
syntax. The new explicit alias syntax approved by the Tribe for 2.0 (and already available at least since 1.39), will fail exactly in this step, because the settings and options are not initialized, this test proves it: