@@ -100,38 +100,41 @@ bool StdLayout::find_kernels()
100100{
101101 const std::string& boot_path = opts_.boot_path ;
102102 const std::string& module_path = opts_.module_path ;
103+ const bool ignore_module_dir = opts_.ignore_module_dir ;
103104
104105 std::unordered_map<std::string, FileSet> file_map;
105106 typedef std::unordered_map<std::string,
106107 std::vector<std::shared_ptr<File>>>
107108 module_map_type;
108109 module_map_type module_map;
109110
110- // collect all moduledirs first
111- modules_dir_.reset (new DirectoryStream (module_path));
112- while (modules_dir_->read ())
113- {
114- // skip ., .. and all hidden files
115- if (modules_dir_->filename ()[0 ] == ' .' )
116- continue ;
117- // skip non-directories and symlinks
118- if (!modules_dir_->is_regular_directory ())
119- continue ;
120-
121- std::shared_ptr<RelativePath> rpath{
122- new RelativePath (modules_dir_, modules_dir_->filename ())};
123- std::shared_ptr<ModulesDir> f{
124- new ModulesDir (rpath)};
125-
126- std::shared_ptr<RelativePath> build_path{f->build_path ()};
127- if (build_path)
128- module_map[f->filename ()].push_back (
129- BuildDir::try_construct (build_path));
130-
131- // add moduledir after dependant dirs
132- // otherwise moduledir will be removed first and a later failure
133- // would make it impossible to find builddir again
134- module_map[f->filename ()].push_back (f);
111+ if (!ignore_module_dir) {
112+ // collect all moduledirs first
113+ modules_dir_.reset (new DirectoryStream (module_path));
114+ while (modules_dir_->read ())
115+ {
116+ // skip ., .. and all hidden files
117+ if (modules_dir_->filename ()[0 ] == ' .' )
118+ continue ;
119+ // skip non-directories and symlinks
120+ if (!modules_dir_->is_regular_directory ())
121+ continue ;
122+
123+ std::shared_ptr<RelativePath> rpath{
124+ new RelativePath (modules_dir_, modules_dir_->filename ())};
125+ std::shared_ptr<ModulesDir> f{
126+ new ModulesDir (rpath)};
127+
128+ std::shared_ptr<RelativePath> build_path{f->build_path ()};
129+ if (build_path)
130+ module_map[f->filename ()].push_back (
131+ BuildDir::try_construct (build_path));
132+
133+ // add moduledir after dependant dirs
134+ // otherwise moduledir will be removed first and a later failure
135+ // would make it impossible to find builddir again
136+ module_map[f->filename ()].push_back (f);
137+ }
135138 }
136139
137140 // collect all kernel files from /boot
@@ -187,12 +190,14 @@ bool StdLayout::find_kernels()
187190 fset.internal_version (internal_ver);
188191
189192 // associate the module dir
190- module_map_type::iterator mi
191- = module_map.find (internal_ver);
192- if (mi != module_map.end ())
193- {
194- std::copy (mi->second .begin (), mi->second .end (),
195- std::back_inserter (fset.files ()));
193+ if (!ignore_module_dir) {
194+ module_map_type::iterator mi
195+ = module_map.find (internal_ver);
196+ if (mi != module_map.end ())
197+ {
198+ std::copy (mi->second .begin (), mi->second .end (),
199+ std::back_inserter (fset.files ()));
200+ }
196201 }
197202 }
198203 // otherwise, check if it matches the previous one
@@ -226,20 +231,23 @@ bool StdLayout::find_kernels()
226231
227232 // leave only unused moduledirs in modules map
228233 // others should have been copied into kernels already
229- module_map.erase (kf.second .internal_version ());
234+ if (!ignore_module_dir)
235+ module_map.erase (kf.second .internal_version ());
230236
231237 // finally, move the FileSet to kernels
232238 kernels_.push_back (std::move (kf.second ));
233239 }
234240
235- // add orphaned moduledirs to the final list
236- for (std::pair<const std::string, std::vector<std::shared_ptr<File>>>& km : module_map)
237- {
238- FileSet module_set;
239- module_set.internal_version (km.first );
240- std::move (km.second .begin (), km.second .end (),
241- std::back_inserter (module_set.files ()));
242- kernels_.push_back (std::move (module_set));
241+ if (!ignore_module_dir) {
242+ // add orphaned moduledirs to the final list
243+ for (std::pair<const std::string, std::vector<std::shared_ptr<File>>>& km : module_map)
244+ {
245+ FileSet module_set;
246+ module_set.internal_version (km.first );
247+ std::move (km.second .begin (), km.second .end (),
248+ std::back_inserter (module_set.files ()));
249+ kernels_.push_back (std::move (module_set));
250+ }
243251 }
244252
245253 return true ;
0 commit comments