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

Implemented recipe files for dub #2684 #2685

Merged
merged 11 commits into from
Aug 13, 2023
9 changes: 6 additions & 3 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ struct CommonOptions {
bool verbose, vverbose, quiet, vquiet, verror, version_;
bool help, annotate, bare;
string[] registry_urls;
string root_path;
string root_path, recipeFile;
enum Color { automatic, on, off }
Color colorMode = Color.automatic;
SkipPackageSuppliers skipRegistry = SkipPackageSuppliers.none;
Expand Down Expand Up @@ -568,6 +568,7 @@ struct CommonOptions {
{
args.getopt("h|help", &help, ["Display general or command specific help"]);
args.getopt("root", &root_path, ["Path to operate in instead of the current working dir"]);
args.getopt("recipe", &recipeFile, ["Make dub use custom path as its recipe file"]);
MrcSnm marked this conversation as resolved.
Show resolved Hide resolved
args.getopt("registry", &registry_urls, [
"Search the given registry URL first when resolving dependencies. Can be specified multiple times. Available registry types:",
" DUB: URL to DUB registry (default)",
Expand Down Expand Up @@ -836,10 +837,10 @@ class Command {
dub = new Dub(options.root_path, package_suppliers, options.skipRegistry);
dub.dryRun = options.annotate;
dub.defaultPlacementLocation = options.placementLocation;

dub.mainRecipePath = options.recipeFile;
// make the CWD package available so that for example sub packages can reference their
// parent package.
try dub.packageManager.getOrLoadPackage(NativePath(options.root_path), NativePath.init, false, StrictMode.Warn);
try dub.packageManager.getOrLoadPackage(NativePath(options.root_path), NativePath(options.recipeFile), false, StrictMode.Warn);
catch (Exception e) { logDiagnostic("No valid package found in current working directory: %s", e.msg); }

return dub;
Expand Down Expand Up @@ -1168,6 +1169,7 @@ abstract class PackageBuildCommand : Command {
return true;
}


bool from_cwd = package_name.length == 0 || package_name.startsWith(":");
// load package in root_path to enable searching for sub packages
if (loadCwdPackage(dub, from_cwd)) {
Expand Down Expand Up @@ -1272,6 +1274,7 @@ class GenerateCommand : PackageBuildCommand {
if (!gensettings.config.length)
gensettings.config = m_defaultConfig;
gensettings.runArgs = app_args;
gensettings.recipeName = dub.mainRecipePath;
// legacy compatibility, default working directory is always CWD
gensettings.overrideToolWorkingDirectory = getWorkingDirectory();

Expand Down
11 changes: 11 additions & 0 deletions source/dub/dub.d
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ class Dub {
PackageManager m_packageManager;
PackageSupplier[] m_packageSuppliers;
NativePath m_rootPath;
string m_mainRecipePath;
SpecialDirs m_dirs;
Settings m_config;
Project m_project;
string m_defaultCompiler;
}

///Whenever the switch --recipe= is supplied, this member will be populated.
MrcSnm marked this conversation as resolved.
Show resolved Hide resolved

/** The default placement location of fetched packages.

This property can be altered, so that packages which are downloaded as part
Expand Down Expand Up @@ -391,6 +394,14 @@ class Dub {
/// application.
@property string projectName() const { return m_project.name; }

@property string mainRecipePath() const { return m_mainRecipePath; }
@property string mainRecipePath(string recipePath)
{
import std.path:stripExtension, baseName;
return m_mainRecipePath = recipePath.baseName.stripExtension;
MrcSnm marked this conversation as resolved.
Show resolved Hide resolved
}


@property NativePath projectPath() const { return this.m_project.rootPackage.path; }

@property string[] configurations() const { return m_project.configurations; }
Expand Down
6 changes: 3 additions & 3 deletions source/dub/generators/build.d
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ string computeBuildName(string config, in GeneratorSettings settings, const stri
addHash(settings.platform.compilerVersion);
const hashstr = Base64URL.encode(hash.finish()[0 .. $ / 2]).stripRight("=");

return format("%s-%s-%s", config, settings.buildType, hashstr);

return format("%s-%s-%s-%s", config, settings.buildType, settings.recipeName, hashstr);
MrcSnm marked this conversation as resolved.
Show resolved Hide resolved
}

class BuildGenerator : ProjectGenerator {
Expand Down Expand Up @@ -747,10 +748,9 @@ private string computeBuildID(in BuildSettings buildsettings, string config, Gen
(cast(uint)(buildsettings.options & ~BuildOption.color)).to!string, // exclude color option from id
settings.platform.compilerBinary,
settings.platform.compiler,
settings.platform.compilerVersion,
settings.platform.compilerVersion
],
];

return computeBuildName(config, settings, hashing);
}

Expand Down
1 change: 1 addition & 0 deletions source/dub/generators/generator.d
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ struct GeneratorSettings {
BuildPlatform platform;
Compiler compiler;
string config;
string recipeName;
MrcSnm marked this conversation as resolved.
Show resolved Hide resolved
string buildType;
BuildSettings buildSettings;
BuildMode buildMode = BuildMode.separate;
Expand Down
16 changes: 16 additions & 0 deletions test/issue2684-recipe-file/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.dub
docs.json
__dummy.html
docs/
/issue2684-recipe-file
issue2684-recipe-file.so
issue2684-recipe-file.dylib
issue2684-recipe-file.dll
issue2684-recipe-file.a
issue2684-recipe-file.lib
issue2684-recipe-file-test-*
*.exe
*.pdb
*.o
*.obj
*.lst
7 changes: 7 additions & 0 deletions test/issue2684-recipe-file/anotherSource/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module app;
import std.stdio;

void main()
{
writeln("This was built using dubWithAnotherSource.json");
}
9 changes: 9 additions & 0 deletions test/issue2684-recipe-file/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"authors": [
"Hipreme"
],
"copyright": "Copyright © 2023, Hipreme",
"description": "A minimal D application.",
"license": "public domain",
"name": "issue2684-recipe-file"
}
10 changes: 10 additions & 0 deletions test/issue2684-recipe-file/dubWithAnotherSource.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"authors": [
"Hipreme"
],
"copyright": "Copyright © 2023, Hipreme",
"description": "A minimal D application.",
"sourcePaths": ["anotherSource"],
"license": "public domain",
"name": "issue2684-recipe-file"
}
10 changes: 10 additions & 0 deletions test/issue2684-recipe-file/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module app;
import std.stdio;

void main()
{
writeln("This was built using dub.json.
Try using the other configuration by calling dub with:
dub --recipe=dubWithAnotherSource.json
");
}