libzypp  17.38.7
language.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 ----------------------------------------------------------------------*/
9 #include "language.h"
10 
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 
20 namespace zyppng::sat::namespaces {
21 
23  {
24  const TrackedLocaleIds & localeIds( trackedLocaleIds() );
25  return localeIds.contains( IdString(value) );
26  }
27 
29  {
30  if ( _requestedLocalesTracker.setInitial( locales_r ) )
31  {
32  localeSetDirty( {"initRequestedLocales"} );
33  MIL << "Init RequestedLocales: " << _requestedLocalesTracker << " =" << locales_r << std::endl;
34  }
35  }
36 
38  {
39  if ( _requestedLocalesTracker.set( locales_r ) )
40  {
41  localeSetDirty( {"setRequestedLocales"} );
42  MIL << "New RequestedLocales: " << _requestedLocalesTracker << " =" << locales_r << std::endl;
43  }
44  }
45 
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 
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 
69  {
70  if ( ! _trackedLocaleIdsPtr )
71  {
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 
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 
138  {
139  _availableLocalesPtr.reset();
140  }
141 
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 }
#define MIL
Definition: Logger.h:103
A Solvable object within the sat Pool.
Definition: solvable.h:64
std::string code() const
Return the locale code asString.
Definition: Locale.h:89
base::SetTracker< LocaleSet > _requestedLocalesTracker
Definition: language.h:87
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:29
Orchestrator for a libsolv pool instance.
Definition: pool.h:36
sat::detail::IdType id() const
Expert backdoor.
Definition: capability.h:301
void initRequestedLocales(const LocaleSet &locales_r)
Start tracking changes based on this locales_r.
Definition: language.cc:28
Capability lhs() const
Definition: capability.h:399
std::unique_ptr< TrackedLocaleIds > _trackedLocaleIdsPtr
Definition: language.h:88
Capability rhs() const
Definition: capability.h:401
Helper providing more detailed information about a Capability.
Definition: capability.h:338
A sat capability.
Definition: capability.h:73
static void _getLocaleDeps(const Capability &cap_r, LocaleSet &store_r)
Definition: language.cc:109
const TrackedLocaleIds & trackedLocaleIds() const
Expanded _requestedLocalesTracker for solver.
Definition: language.cc:68
zypp::sat::detail::IdType IdType
Definition: poolconstants.h:43
&#39;Language[_Country]&#39; codes.
Definition: Locale.h:50
CapRel capRel() const
Definition: capability.h:400
bool addRequestedLocale(const Locale &locale_r)
User change (tracked).
Definition: language.cc:46
bool eraseRequestedLocale(const Locale &locale_r)
User change (tracked).
Definition: language.cc:57
base::SetTracker< IdStringSet > TrackedLocaleIds
Definition: language.h:75
bool isSatisfied(detail::IdType value) const override
Check if a specific value satisfies this namespace condition.
Definition: language.cc:22
const LocaleSet & getAvailableLocales() const
All Locales occurring in any repo.
Definition: language.cc:142
void localeSetDirty(std::initializer_list< std::string_view > reasons)
Definition: language.h:82
SolvableIterable solvables() const
Iterator to the first Solvable.
Definition: pool.cc:258
zypp::IdString IdString
Definition: idstring.h:16
void setRequestedLocales(const LocaleSet &locales_r)
User change (tracked).
Definition: language.cc:37
std::unique_ptr< LocaleSet > _availableLocalesPtr
Definition: language.h:89