Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dub: Cache PackageManager across dub{Package,Dependant} targets #281

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion payload/reggae/dub/interop/dublib.d
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,33 @@ package struct Dub {
// module that don't do that on purpose for speed reasons.
auto fullDub(in string projectPath) @trusted {
import dub.dub: DubClass = Dub;
import dub.packagemanager: PackageManager;
import dub.internal.vibecompat.inet.path: NativePath;

auto dub = new DubClass(projectPath);
// Cache the PackageManager.
// A reggaefile.d with lots of dub{Package,Dependant} targets benefits from
// this, also depending on the size of the dub packages cache.
static class DubWithCachedPackageManager : DubClass {
this(string rootPath) {
super(rootPath);
}

override PackageManager makePackageManager() const {
static PackageManager cachedPM = null;
if (!cachedPM) {
// The PackageManager wants a path to a local directory, for an
// implicit `<local>/.dub/packages` repo. The base
// implementation uses the dub root project directory; use the
// reggae project directory as our local root.
import reggae.config: options;
auto localRoot = NativePath(options.projectPath);
cachedPM = new PackageManager(localRoot, m_dirs.userPackages, m_dirs.systemSettings, false);
}
return cachedPM;
}
}

auto dub = new DubWithCachedPackageManager(projectPath);
dub.packageManager.getOrLoadPackage(NativePath(projectPath));
dub.loadPackage();
dub.project.validate();
Expand Down
12 changes: 8 additions & 4 deletions tests/it/runtime/dependencies.d
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,14 @@ unittest {
]
);

// but do write configuration if dub cfg has changed
auto lines = runIt("-d myvar=foo");
srcLine.should.not.be in lines;
cfgLine.should.be in lines;
// we cache dub's PackageManager per-thread; use a new thread to make sure the changed .sdl is reloaded
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means the test needs to know waaay too much about the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the test needs to reparse a changed .sdl, something a real reggae process never does, and I thought this is the least invasive method to make that test still work.

import core.thread: Thread;
new Thread(() {
// but do write configuration if dub cfg has changed
auto lines = runIt("-d myvar=foo");
srcLine.should.not.be in lines;
cfgLine.should.be in lines;
}).start().join();
}
}
}
Loading