Skip to content

Commit ee97fcd

Browse files
committed
Fix packages with empty sources
Ensure transitive dependencies are still included, export_incdirs are still passed to calling package
1 parent 0264e98 commit ee97fcd

1 file changed

Lines changed: 56 additions & 41 deletions

File tree

src/sess.rs

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::diagnostic::{Diagnostics, Warnings};
3737
use crate::error::*;
3838
use crate::git::Git;
3939
use crate::progress::{GitProgressOps, ProgressHandler};
40-
use crate::src::SourceGroup;
40+
use crate::src::{SourceFile, SourceGroup, SourceType};
4141
use crate::target::TargetSpec;
4242
use crate::util::try_modification_time;
4343

@@ -423,23 +423,21 @@ impl<'ctx> Session<'ctx> {
423423
config::SourceFile::File(ref path) => {
424424
let ty = match path.extension().and_then(std::ffi::OsStr::to_str) {
425425
Some("sv") | Some("v") | Some("vp") | Some("svh") => {
426-
Some(crate::src::SourceType::Verilog)
426+
Some(SourceType::Verilog)
427427
}
428-
Some("vhd") | Some("vhdl") => Some(crate::src::SourceType::Vhdl),
428+
Some("vhd") | Some("vhdl") => Some(SourceType::Vhdl),
429429
_ => None,
430430
};
431-
crate::src::SourceFile::File(path as &Path, ty)
431+
SourceFile::File(path as &Path, ty)
432+
}
433+
config::SourceFile::SvFile(ref path) => {
434+
SourceFile::File(path as &Path, Some(SourceType::Verilog))
435+
}
436+
config::SourceFile::VerilogFile(ref path) => {
437+
SourceFile::File(path as &Path, Some(SourceType::Verilog))
432438
}
433-
config::SourceFile::SvFile(ref path) => crate::src::SourceFile::File(
434-
path as &Path,
435-
Some(crate::src::SourceType::Verilog),
436-
),
437-
config::SourceFile::VerilogFile(ref path) => crate::src::SourceFile::File(
438-
path as &Path,
439-
Some(crate::src::SourceType::Verilog),
440-
),
441439
config::SourceFile::VhdlFile(ref path) => {
442-
crate::src::SourceFile::File(path as &Path, Some(crate::src::SourceType::Vhdl))
440+
SourceFile::File(path as &Path, Some(SourceType::Vhdl))
443441
}
444442
config::SourceFile::Group(ref group) => self
445443
.load_sources(
@@ -1616,33 +1614,29 @@ impl<'io, 'sess: 'io, 'ctx: 'sess> SessionIo<'sess, 'ctx> {
16161614
let files = manifests
16171615
.into_iter()
16181616
.flatten()
1619-
.filter_map(|m| {
1620-
m.sources.as_ref().map(|s| {
1621-
// Collect include dirs from export_include_dirs of package and direct dependencies
1622-
let mut export_include_dirs: IndexMap<
1623-
String,
1624-
Vec<(TargetSpec, &Path)>,
1625-
> = IndexMap::new();
1626-
export_include_dirs.insert(
1627-
m.package.name.clone(),
1628-
m.export_include_dirs
1629-
.iter()
1630-
.map(|(trgt, path)| (trgt.clone(), path.as_path()))
1631-
.collect(),
1632-
);
1633-
if !m.dependencies.is_empty() {
1634-
for i in m.dependencies.keys() {
1635-
if !all_export_include_dirs.contains_key(i) {
1636-
Warnings::ExportDirNameIssue(i.clone()).emit();
1637-
export_include_dirs.insert(i.to_string(), Vec::new());
1638-
} else {
1639-
export_include_dirs.insert(
1640-
i.to_string(),
1641-
all_export_include_dirs[i].clone(),
1642-
);
1643-
}
1617+
.map(|m| {
1618+
// Collect include dirs from export_include_dirs of package and direct dependencies
1619+
let mut export_include_dirs: IndexMap<String, Vec<(TargetSpec, &Path)>> =
1620+
IndexMap::new();
1621+
export_include_dirs.insert(
1622+
m.package.name.clone(),
1623+
m.export_include_dirs
1624+
.iter()
1625+
.map(|(trgt, path)| (trgt.clone(), path.as_path()))
1626+
.collect(),
1627+
);
1628+
if !m.dependencies.is_empty() {
1629+
for i in m.dependencies.keys() {
1630+
if !all_export_include_dirs.contains_key(i) {
1631+
Warnings::ExportDirNameIssue(i.clone()).emit();
1632+
export_include_dirs.insert(i.to_string(), Vec::new());
1633+
} else {
1634+
export_include_dirs
1635+
.insert(i.to_string(), all_export_include_dirs[i].clone());
16441636
}
16451637
}
1638+
}
1639+
if let Some(s) = m.sources.as_ref() {
16461640
self.sess
16471641
.load_sources(
16481642
s,
@@ -1655,7 +1649,24 @@ impl<'io, 'sess: 'io, 'ctx: 'sess> SessionIo<'sess, 'ctx> {
16551649
},
16561650
)
16571651
.into()
1658-
})
1652+
} else {
1653+
// Create an empty source group to preserve the
1654+
// package and its dependency information, so that
1655+
// get_package_list can discover transitive deps.
1656+
SourceFile::Group(Box::new(SourceGroup {
1657+
package: Some(m.package.name.as_str()),
1658+
dependencies: m.dependencies.keys().cloned().collect(),
1659+
export_incdirs: export_include_dirs,
1660+
version: match self
1661+
.sess
1662+
.dependency_with_name(m.package.name.as_str())
1663+
{
1664+
Ok(dep_id) => self.sess.dependency(dep_id).version.clone(),
1665+
Err(_) => None,
1666+
},
1667+
..Default::default()
1668+
}))
1669+
}
16591670
})
16601671
.collect();
16611672

@@ -1670,11 +1681,15 @@ impl<'io, 'sess: 'io, 'ctx: 'sess> SessionIo<'sess, 'ctx> {
16701681
.collect();
16711682

16721683
// Create a source group covering all ranks, i.e. the root source group.
1684+
// Note: we do not call simplify() here so that empty package groups
1685+
// (packages with no sources but with dependencies or export_include_dirs)
1686+
// are preserved for get_package_list to discover transitive dependencies.
1687+
// Downstream consumers (filter_packages, filter_targets) call simplify()
1688+
// and will remove these empty groups before output.
16731689
let sources = SourceGroup {
16741690
files,
16751691
..Default::default()
1676-
}
1677-
.simplify();
1692+
};
16781693

16791694
*self.sess.sources.lock().unwrap() = Some(sources.clone());
16801695
Ok(sources)

0 commit comments

Comments
 (0)