Skip to content

Commit c9e2970

Browse files
committed
Fix some parallel races. Improve cmake generation.
1 parent d05f0d9 commit c9e2970

5 files changed

Lines changed: 229 additions & 195 deletions

File tree

src/common/package_store.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -489,32 +489,39 @@ PackageStore::read_packages_from_file(path p, const String &config_name, bool di
489489

490490
std::set<Package> packages;
491491
auto configs = conf.split();
492-
// batch resolve of deps first in parallel; merge flags?
492+
493+
// batch resolve of deps first; merge flags?
494+
495+
// seq
496+
for (auto &c : configs)
497+
{
498+
auto &project = c.getDefaultProject();
499+
auto root_directory = (fs::is_regular_file(p) ? p.parent_path() : p) / project.root_directory;
500+
501+
// to prevent possible errors
502+
// pkg must have small scope
503+
Package pkg;
504+
pkg.ppath = ppath;
505+
if (!project.name.empty())
506+
pkg.ppath.push_back(project.name);
507+
pkg.version = Version(LOCAL_VERSION_NAME);
508+
pkg.flags.set(pfLocalProject);
509+
pkg.flags.set(pfDirectDependency, direct_dependency);
510+
pkg.createNames();
511+
project.applyFlags(pkg.flags);
512+
c.setPackage(pkg);
513+
local_packages[pkg.ppath] = root_directory;
514+
}
515+
493516
Executor e(std::thread::hardware_concurrency() * 2);
494517
e.throw_exceptions = true;
495518
for (auto &c : configs)
496519
{
497-
e.push([&]()
520+
e.push([&c, &p, &cpp_fn, &ppath]()
498521
{
499522
auto &project = c.getDefaultProject();
500523
auto root_directory = (fs::is_regular_file(p) ? p.parent_path() : p) / project.root_directory;
501524

502-
// to prevent possible errors
503-
// pkg must have small scope
504-
{
505-
Package pkg;
506-
pkg.ppath = ppath;
507-
if (!project.name.empty())
508-
pkg.ppath.push_back(project.name);
509-
pkg.version = Version(LOCAL_VERSION_NAME);
510-
pkg.flags.set(pfLocalProject);
511-
pkg.flags.set(pfDirectDependency, direct_dependency);
512-
pkg.createNames();
513-
project.applyFlags(pkg.flags);
514-
c.setPackage(pkg);
515-
local_packages[pkg.ppath] = root_directory;
516-
}
517-
518525
// sources
519526
if (!cpp_fn.empty() && !project.files_loaded)
520527
{
@@ -523,6 +530,7 @@ PackageStore::read_packages_from_file(path p, const String &config_name, bool di
523530
project.sources.insert(cpp_fn.filename().string());
524531
}
525532
project.root_directory = root_directory;
533+
LOG_INFO(logger, "Finding sources for " + project.pkg.ppath.slice(2).toString());
526534
project.findSources(root_directory);
527535
// maybe remove? let user see cppan.yml in local project
528536
project.files.erase(CPPAN_FILENAME);
@@ -550,16 +558,18 @@ PackageStore::read_packages_from_file(path p, const String &config_name, bool di
550558
d.second.createNames();
551559
project.dependencies.insert({ d.second.ppath.toString(), d.second });
552560
}
553-
554-
// add package for result
555-
packages.insert(project.pkg);
556561
});
557562
}
558563
e.wait();
559564

560565
// seq
561566
for (auto &c : configs)
562567
{
568+
auto &project = c.getDefaultProject();
569+
570+
// add package for result
571+
packages.insert(project.pkg);
572+
563573
// add config to storage
564574
rd.add_local_config(c);
565575
}

src/common/project_path.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ bool is_valid_project_path_symbol(int c)
2626
;
2727
}
2828

29+
void fix_root_project(yaml &root, const ProjectPath &ppath)
30+
{
31+
auto rp = root["root_project"];
32+
if (!rp.IsDefined())
33+
{
34+
rp = ppath.toString();
35+
return;
36+
}
37+
if (!ppath.is_root_of(rp.as<String>()))
38+
rp = ppath.toString();
39+
}
40+
2941
ProjectPath::ProjectPath(String s)
3042
{
3143
if (s.size() > 2048)
@@ -233,14 +245,12 @@ ProjectPath &ProjectPath::operator/=(const ProjectPath &e)
233245
return *this = *this / e;
234246
}
235247

236-
void fix_root_project(yaml &root, const ProjectPath &ppath)
248+
ProjectPath ProjectPath::slice(int start, int end) const
237249
{
238-
auto rp = root["root_project"];
239-
if (!rp.IsDefined())
240-
{
241-
rp = ppath.toString();
242-
return;
243-
}
244-
if (!ppath.is_root_of(rp.as<String>()))
245-
rp = ppath.toString();
250+
auto p = *this;
251+
if (end == -1)
252+
p.path_elements = decltype(path_elements)(path_elements.begin() + start, path_elements.end());
253+
else
254+
p.path_elements = decltype(path_elements)(path_elements.begin() + start, path_elements.begin() + end);
255+
return p;
246256
}

src/common/project_path.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class ProjectPath
128128
auto get_name() const { return back(); }
129129
ProjectPath parent() const { return PathElements(path_elements.begin(), path_elements.end() - 1); }
130130

131+
ProjectPath slice(int start, int end = -1) const;
132+
131133
bool operator<(const ProjectPath &rhs) const;
132134

133135
operator String() const

0 commit comments

Comments
 (0)