-pub fn list_files<'a>(krate: &'a ast::Crate,
- codemap: &codemap::CodeMap)
- -> HashMap<PathBuf, &'a ast::Mod> {
- let mut result = HashMap::new();
- let root_filename: PathBuf = codemap.span_to_filename(krate.span).into();
- list_submodules(&krate.module, root_filename.parent().unwrap(), codemap, &mut result);
- result.insert(root_filename, &krate.module);
- result
+pub fn list_files<'a>(
+ krate: &'a ast::Crate,
+ source_map: &source_map::SourceMap,
+) -> Result<BTreeMap<FileName, &'a ast::Mod>, io::Error> {
+ let mut result = BTreeMap::new(); // Enforce file order determinism
+ let root_filename = source_map.span_to_filename(krate.span);
+ {
+ let parent = match root_filename {
+ source_map::FileName::Real(ref path) => path.parent().unwrap(),
+ _ => Path::new(""),
+ };
+ list_submodules(&krate.module, parent, None, source_map, &mut result)?;
+ }
+ result.insert(root_filename.into(), &krate.module);
+ Ok(result)
+}
+
+fn path_value(attr: &ast::Attribute) -> Option<Symbol> {
+ if attr.name() == "path" {
+ attr.value_str()
+ } else {
+ None
+ }
+}
+
+// N.B. Even when there are multiple `#[path = ...]` attributes, we just need to
+// examine the first one, since rustc ignores the second and the subsequent ones
+// as unused attributes.
+fn find_path_value(attrs: &[ast::Attribute]) -> Option<Symbol> {
+ attrs.iter().flat_map(path_value).next()