libzypp: zypp/ng/sat/namespaces/language.cc Source File

libzypp 17.38.13

language.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------*/
9#include "language.h"
10
11#include <zypp-core/base/LogTools.h>
12#include <zypp/ng/sat/capability.h>
13
14#include <zypp/ng/sat/pool.h>
15#include <zypp/ng/sat/solvable.h>
16
17#undef ZYPP_BASE_LOGGER_LOGGROUP
18#define ZYPP_BASE_LOGGER_LOGGROUP "zyppng::satpool::namespaces"
19
20namespace zyppng::sat::namespaces {
21
22 bool LanguageNamespaceProvider::isSatisfied(detail::IdType value) const
23 {
24 const TrackedLocaleIds & localeIds( trackedLocaleIds() );
25 return localeIds.contains( IdString(value) );
26 }
27
28 void LanguageNamespaceProvider::initRequestedLocales( const LocaleSet & locales_r )
29 {
30 if ( _requestedLocalesTracker.setInitial( locales_r ) )
31 {
32 localeSetDirty( {"initRequestedLocales"} );
33 MIL << "Init RequestedLocales: " << _requestedLocalesTracker << " =" << locales_r << std::endl;
34 }
35 }
36
37 void LanguageNamespaceProvider::setRequestedLocales( const LocaleSet & locales_r )
38 {
39 if ( _requestedLocalesTracker.set( locales_r ) )
40 {
41 localeSetDirty( {"setRequestedLocales"} );
42 MIL << "New RequestedLocales: " << _requestedLocalesTracker << " =" << locales_r << std::endl;
43 }
44 }
45
46 bool LanguageNamespaceProvider::addRequestedLocale( const Locale & locale_r )
47 {
48 bool done = _requestedLocalesTracker.add( locale_r );
49 if ( done )
50 {
51 localeSetDirty( {"addRequestedLocale", locale_r.code().c_str()} );
52 MIL << "New RequestedLocales: " << _requestedLocalesTracker << " +" << locale_r << std::endl;
53 }
54 return done;
55 }
56
57 bool LanguageNamespaceProvider::eraseRequestedLocale( const Locale & locale_r )
58 {
59 bool done = _requestedLocalesTracker.remove( locale_r );
60 if ( done )
61 {
62 localeSetDirty( {"eraseRequestedLocale", locale_r.code().c_str()} );
63 MIL << "New RequestedLocales: " << _requestedLocalesTracker << " -" << locale_r << std::endl;
64 }
65 return done;
66 }
67
68 const LanguageNamespaceProvider::TrackedLocaleIds & LanguageNamespaceProvider::trackedLocaleIds() const
69 {
70 if ( ! _trackedLocaleIdsPtr )
71 {
72 _trackedLocaleIdsPtr.reset( new TrackedLocaleIds );
73
74 const auto& localesTracker( _requestedLocalesTracker );
75 TrackedLocaleIds & localeIds( *_trackedLocaleIdsPtr );
76
77 // Add current locales+fallback except for added ones
78 for ( Locale lang: localesTracker.current() )
79 {
80 if ( localesTracker.wasAdded( lang ) )
81 continue;
82 for ( ; lang; lang = lang.fallback() )
83 { localeIds.current().insert( IdString(lang) ); }
84 }
85
86 // Add added locales+fallback except they are already in current
87 for ( Locale lang: localesTracker.added() )
88 {
89 for ( ; lang && localeIds.current().insert( IdString(lang) ).second; lang = lang.fallback() )
90 { localeIds.added().insert( IdString(lang) ); }
91 }
92
93 // Add removed locales+fallback except they are still in current
94 for ( Locale lang: localesTracker.removed() )
95 {
96 for ( ; lang && ! localeIds.current().count( IdString(lang) ); lang = lang.fallback() )
97 { localeIds.removed().insert( IdString(lang) ); }
98 }
99
100 // bsc#1155678: We try to differ between an empty RequestedLocales
101 // and one containing 'en' (explicit or as fallback). An empty RequestedLocales
102 // should not even drag in recommended 'en' packages. So we no longer enforce
103 // 'en' being in the set.
104 }
105 return *_trackedLocaleIdsPtr;
106 }
107
108
109 static void _getLocaleDeps( const Capability & cap_r, LocaleSet & store_r )
110 {
111 // Collect locales from any 'namespace:language(lang)' dependency
112 CapDetail detail( cap_r );
113 if ( detail.kind() == CapDetail::EXPRESSION )
114 {
115 switch ( detail.capRel() )
116 {
117 case CapDetail::CAP_AND:
118 case CapDetail::CAP_OR:
119 // expand
120 _getLocaleDeps( detail.lhs(), store_r );
121 _getLocaleDeps( detail.rhs(), store_r );
122 break;
123
124 case CapDetail::CAP_NAMESPACE:
125 if ( detail.lhs().id() == NAMESPACE_LANGUAGE )
126 {
127 store_r.insert( Locale( IdString(detail.rhs().id()) ) );
128 }
129 break;
130
131 default:
132 break; // unwanted
133 }
134 }
135 }
136
137 void LanguageNamespaceProvider::onReset( Pool & )
138 {
139 _availableLocalesPtr.reset();
140 }
141
142 const LocaleSet & LanguageNamespaceProvider::getAvailableLocales() const
143 {
144 if ( !_availableLocalesPtr ) {
145
146 _availableLocalesPtr.reset( new LocaleSet );
147 LocaleSet & localeSet( *_availableLocalesPtr );
148
149 for ( const Solvable & pi : _pool->solvables() )
150 {
151 for ( const Capability & cap : pi.dep_supplements() )
152 {
153 _getLocaleDeps( cap, localeSet );
154 }
155 }
156 }
157 return *_availableLocalesPtr;
158 }
159
160}
LogTools.h
MIL
#define MIL
Definition Logger.h:103
zypp::Locale
'Language[_Country]' codes.
Definition Locale.h:51
zypp::Locale::code
std::string code() const
Return the locale code asString.
Definition Locale.h:89
zyppng::sat::CapDetail
Helper providing more detailed information about a Capability.
Definition capability.h:339
zyppng::sat::CapDetail::EXPRESSION
@ EXPRESSION
Definition capability.h:346
zyppng::sat::CapDetail::CAP_OR
@ CAP_OR
or
Definition capability.h:356
zyppng::sat::CapDetail::CAP_NAMESPACE
@ CAP_NAMESPACE
Definition capability.h:365
zyppng::sat::CapDetail::CAP_AND
@ CAP_AND
and
Definition capability.h:355
zyppng::sat::Capability
A sat capability.
Definition capability.h:74
zyppng::sat::NamespaceProvider::_pool
Pool * _pool
Definition namespaceprovider.h:85
zyppng::sat::Pool
Orchestrator for a libsolv pool instance.
Definition pool.h:37
zyppng::sat::Solvable
A Solvable object within the sat Pool.
Definition solvable.h:66
zyppng::sat::namespaces::LanguageNamespaceProvider::initRequestedLocales
void initRequestedLocales(const LocaleSet &locales_r)
Start tracking changes based on this locales_r.
Definition language.cc:28
zyppng::sat::namespaces::LanguageNamespaceProvider::setRequestedLocales
void setRequestedLocales(const LocaleSet &locales_r)
User change (tracked).
Definition language.cc:37
zyppng::sat::namespaces::LanguageNamespaceProvider::isSatisfied
bool isSatisfied(detail::IdType value) const override
Check if a specific value satisfies this namespace condition.
Definition language.cc:22
zyppng::sat::namespaces::LanguageNamespaceProvider::_availableLocalesPtr
std::unique_ptr< LocaleSet > _availableLocalesPtr
Definition language.h:89
zyppng::sat::namespaces::LanguageNamespaceProvider::onReset
void onReset(Pool &pool) override
Definition language.cc:137
zyppng::sat::namespaces::LanguageNamespaceProvider::_requestedLocalesTracker
base::SetTracker< LocaleSet > _requestedLocalesTracker
Definition language.h:87
zyppng::sat::namespaces::LanguageNamespaceProvider::localeSetDirty
void localeSetDirty(std::initializer_list< std::string_view > reasons)
Definition language.h:82
zyppng::sat::namespaces::LanguageNamespaceProvider::addRequestedLocale
bool addRequestedLocale(const Locale &locale_r)
User change (tracked).
Definition language.cc:46
zyppng::sat::namespaces::LanguageNamespaceProvider::_trackedLocaleIdsPtr
std::unique_ptr< TrackedLocaleIds > _trackedLocaleIdsPtr
Definition language.h:88
zyppng::sat::namespaces::LanguageNamespaceProvider::getAvailableLocales
const LocaleSet & getAvailableLocales() const
All Locales occurring in any repo.
Definition language.cc:142
zyppng::sat::namespaces::LanguageNamespaceProvider::trackedLocaleIds
const TrackedLocaleIds & trackedLocaleIds() const
Expanded _requestedLocalesTracker for solver.
Definition language.cc:68
zyppng::sat::namespaces::LanguageNamespaceProvider::eraseRequestedLocale
bool eraseRequestedLocale(const Locale &locale_r)
User change (tracked).
Definition language.cc:57
zyppng::sat::namespaces::LanguageNamespaceProvider::TrackedLocaleIds
base::SetTracker< IdStringSet > TrackedLocaleIds
Definition language.h:75
language.h
zypp::LocaleSet
std::unordered_set< Locale > LocaleSet
Definition Locale.h:29
zyppng::sat::detail
CLASS NAME : detail::DIWrap.
Definition cap2str.cc:14
zyppng::sat::detail::IdType
zypp::sat::detail::IdType IdType
Definition poolconstants.h:43
zyppng::sat::namespaces
Definition filesystem.cc:18
zyppng::sat::namespaces::_getLocaleDeps
static void _getLocaleDeps(const Capability &cap_r, LocaleSet &store_r)
Definition language.cc:109
zyppng::IdString
zypp::IdString IdString
Definition idstring.h:16
pool.h
capability.h
solvable.h