Skip to content

Commit 63bb47a

Browse files
committed
make package recipe const
So that only package_.d may modify it and it's easier to reload it from disk in the future.
1 parent 3cc17fc commit 63bb47a

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

source/dub/commandline.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,7 +2513,7 @@ class DustmiteCommand : PackageBuildCommand {
25132513
if (subp.path.length) {
25142514
auto sub_path = base_path ~ NativePath(subp.path);
25152515
auto pack = prj.packageManager.getOrLoadPackage(sub_path);
2516-
fixPathDependencies(pack.recipe, sub_path);
2516+
fixPathDependencies(pack.rawRecipe, sub_path);
25172517
pack.storeInfo(sub_path);
25182518
} else fixPathDependencies(subp.recipe, base_path);
25192519
}
@@ -2528,7 +2528,7 @@ class DustmiteCommand : PackageBuildCommand {
25282528
copyFolderRec(pack.path, dst_path);
25292529

25302530
// adjust all path based dependencies
2531-
fixPathDependencies(pack.recipe, dst_path);
2531+
fixPathDependencies(pack.rawRecipe, dst_path);
25322532

25332533
// overwrite package description file with additional version information
25342534
pack.storeInfo(dst_path);

source/dub/dub.d

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,10 @@ class Dub {
12411241

12421242
GeneratorSettings settings = this.makeAppSettings();
12431243
settings.runArgs = runArgs;
1244+
// used for compiler commands and for the CWD of the tool itself, or as
1245+
// base for relative paths.
1246+
settings.overrideToolWorkingDirectory = path;
12441247

1245-
initSubPackage.recipe.buildSettings.workingDirectory = path.toNativeString();
12461248
template_dub.generateProject("build", settings);
12471249
}
12481250

@@ -1293,7 +1295,7 @@ class Dub {
12931295
if (m_dryRun) return;
12941296

12951297
// allow to choose a custom ddox tool
1296-
auto tool = m_project.rootPackage.recipe.ddoxTool;
1298+
string tool = m_project.rootPackage.recipe.ddoxTool;
12971299
if (tool.empty) tool = "ddox";
12981300

12991301
auto tool_pack = m_packageManager.getBestPackage(tool);

source/dub/package_.d

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Package {
8585
PackageRecipe m_info;
8686
PackageRecipe m_rawRecipe;
8787
Package m_parentPackage;
88+
ConfigurationInfo m_testConfiguration;
8889
}
8990

9091
/** Constructs a `Package` using an in-memory package recipe.
@@ -219,14 +220,15 @@ class Package {
219220
/// ditto
220221
@property void version_(Version value) { assert(m_parentPackage is null); m_info.version_ = value.toString(); }
221222

222-
/** Accesses the recipe contents of this package.
223+
/** Accesses the recipe contents of this package. (only loaded once or after
224+
reloading)
223225
224226
The recipe contains any default values and configurations added by DUB.
225-
To access the raw user recipe, use the `rawRecipe` property.
227+
To access or modify the raw user recipe, use the `rawRecipe` property.
226228
227229
See_Also: `rawRecipe`
228230
*/
229-
@property ref inout(PackageRecipe) recipe() inout { return m_info; }
231+
@property ref const(PackageRecipe) recipe() const { return m_info; }
230232

231233
/** Accesses the original package recipe.
232234
@@ -236,7 +238,7 @@ class Package {
236238
237239
See_Also: `recipe`
238240
*/
239-
@property ref const(PackageRecipe) rawRecipe() const { return m_rawRecipe; }
241+
@property ref inout(PackageRecipe) rawRecipe() inout { return m_rawRecipe; }
240242

241243
/** Returns the path to the package recipe file.
242244
@@ -305,7 +307,7 @@ class Package {
305307
void storeInfo(NativePath path)
306308
const {
307309
auto filename = path ~ defaultPackageFilename;
308-
writeJsonFile(filename, m_info.toJson());
310+
writeJsonFile(filename, m_rawRecipe.toJson());
309311
}
310312

311313
/** Returns the package recipe of a non-path-based sub package.
@@ -448,6 +450,14 @@ class Package {
448450
}
449451
}
450452

453+
void addTestConfiguration(ConfigurationInfo config)
454+
{
455+
assert(m_testConfiguration is ConfigurationInfo.init,
456+
"can't call addTestConfiguration twice!");
457+
m_info.configurations ~= config;
458+
m_testConfiguration = config;
459+
}
460+
451461
/** Returns the selected configuration for a certain dependency.
452462
453463
If no configuration is specified in the package recipe, null will be

source/dub/project.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class Project {
344344
writeFile(mainfile, content);
345345
}
346346

347-
rootPackage.recipe.configurations ~= ConfigurationInfo(config, tcinfo);
347+
rootPackage.addTestConfiguration(ConfigurationInfo(config, tcinfo));
348348

349349
return config;
350350
}

0 commit comments

Comments
 (0)