Skip to content

Commit f9e9004

Browse files
committed
Update:
Improved redub hashmap performance Added redub default compiler changing and redub compiler installer
1 parent f3945cd commit f9e9004

File tree

9 files changed

+271
-11
lines changed

9 files changed

+271
-11
lines changed

dub.selections.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"versions": {
44
"adv_diff": {"path": "adv_diff"},
55
"hipjson": {"path": "hipjson"},
6-
"d-segmented-hashmap": "1.0.5",
6+
"d-segmented-hashmap": "1.0.6",
77
"arsd-official": "12.1.0",
88
"colorize": {"path": "colorize"},
99
"d_dependencies": {"path": "d_dependencies"},

hipjson/dub.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"Hipreme"
44
],
55
"dependencies": {
6-
"d-segmented-hashmap": "~>1.0.5"
6+
"d-segmented-hashmap": "~>1.0.6"
77
},
88
"copyright": "Copyright © 2024, Hipreme",
99
"description": "HipJSON parser. Faster than STD one.",

source/app.d

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ int main(string[] args)
6868
"test": &testMain,
6969
"init": &initMain,
7070
"install": &installMain,
71+
"use": &useMain,
7172
// "watch": &watchMain,
7273
"run": cast(int function(string[]))null
7374
];
@@ -274,21 +275,27 @@ int installMain(string[] args)
274275
import std.string;
275276
import redub.cli.dub;
276277
import redub.logging;
278+
import redub.misc.dmd_install;
277279
setLogLevel(LogLevel.info);
278280
if(args.length == 1)
279281
{
280282
error("redub install requires 1 additional argument: ",
281283
"\n\topend: installs opend",
282-
"\n\tldc <version?|?>: installs ldc latest if version is unspecified.",
284+
"\n\tldc <version?|help>: installs ldc latest if version is unspecified.",
283285
"\n\t\thelp: Lists available ldc versions",
286+
"\n\tdmd <version?>: installs the dmd with the version "~DefaultDMDVersion~" if version is unspecified"
284287
);
285288
return 1;
286289
}
287290
string compiler = args[1];
288291
if(compiler.startsWith("opend"))
289292
{
290293
import redub.misc.opend_install;
291-
return installOpend();
294+
if(!installOpend())
295+
{
296+
error("Could not install OpenD");
297+
return 1;
298+
}
292299
}
293300
else if(compiler.startsWith("ldc"))
294301
{
@@ -313,11 +320,110 @@ int installMain(string[] args)
313320
}
314321
return 0;
315322
}
316-
return cast(int)installLdc(ldcVer);
323+
if(!installLdc(ldcVer))
324+
{
325+
error("Could not install LDC ", ldcVer);;
326+
return 1;
327+
}
317328
}
318-
else if(compiler.startsWith("dmd"))
329+
else if(compiler == "dmd")
330+
{
331+
import redub.misc.dmd_install;
332+
string dmdVer = args.length > 2 ? args[2] : DefaultDMDVersion;
333+
if(!installDmd(dmdVer))
334+
{
335+
error("Could not install DMD ", dmdVer);;
336+
return 1;
337+
}
338+
}
339+
return 0;
340+
}
341+
342+
int useMain(string[] args)
343+
{
344+
import std.string;
345+
import std.file;
346+
import redub.cli.dub;
347+
import redub.logging;
348+
import redub.meta;
349+
import redub.misc.path;
350+
import redub.misc.dmd_install;
351+
JSONValue meta = getRedubMeta();
352+
setLogLevel(LogLevel.info);
353+
if(args.length == 1)
354+
{
355+
error("redub use requires 1 additional argument: ",
356+
"\n\topend <dmd|ldc>: uses the wanted opend compiler as the default",
357+
"\n\tldc <version?>: uses the latest ldc latest if version is unspecified.",
358+
"\n\tdmd <version?>: uses the "~DefaultDMDVersion~" dmd if the version is unspecified.",
359+
"\n\treset: removes the default compiler and redub will set it again by the first one found in the PATH environment variable",
360+
);
361+
return 1;
362+
}
363+
string compiler = args[1];
364+
if(compiler.startsWith("opend"))
365+
{
366+
import redub.misc.opend_install;
367+
import redub.compiler_identification;
368+
string opendCompiler = args.length > 2 ? args[2] : null;
369+
if(opendCompiler != "dmd" && opendCompiler != "ldc2")
370+
{
371+
error("redub uses opend: requires either dmd or ldc2 as an argument");
372+
return 1;
373+
}
374+
string opendFolder = getOpendFolder();
375+
if(!exists(opendFolder))
376+
installOpend();
377+
version(Windows)
378+
opendCompiler~= ".exe";
379+
string opendBin = buildNormalizedPath(opendFolder, opendCompiler);
380+
saveGlobalCompiler(opendBin, meta, true, false);
381+
}
382+
else if(compiler == "ldc" || compiler == "ldc2")
383+
{
384+
import redub.api;
385+
import redub.misc.ldc_install;
386+
import redub.misc.github_tag_check;
387+
enum ldcRepo = "ldc-developers/ldc";
388+
string ldcVer = args.length > 2 ? args[2] : null;
389+
if(!ldcVer)
390+
ldcVer = getLatestGitRepositoryTag(ldcRepo);
391+
string ldcFolder = getLdcFolder(ldcVer);
392+
if(!exists(ldcFolder))
393+
installLdc(ldcVer);
394+
string ldcBin = "ldc2";
395+
version(Windows)
396+
ldcBin~= ".exe";
397+
ldcBin = buildNormalizedPath(ldcFolder, ldcBin);
398+
saveGlobalCompiler(ldcBin, meta, true, false);
399+
}
400+
else if(compiler == "dmd")
401+
{
402+
import redub.misc.dmd_install;
403+
string dmdVer = args.length > 2 ? args[2] : DefaultDMDVersion;
404+
string dmdFolder = getDmdFolder(dmdVer);
405+
if(!exists(dmdFolder) && !installDmd(dmdVer))
406+
{
407+
error("Could not install DMD for using it.");
408+
return 1;
409+
}
410+
string dmdBin = "dmd";
411+
version(Windows)
412+
dmdBin~= ".exe";
413+
dmdBin = buildNormalizedPath(dmdFolder, dmdBin);
414+
saveGlobalCompiler(dmdBin, meta, true, false);
415+
}
416+
else if(compiler.startsWith("reset"))
417+
{
418+
meta.data.object.remove("defaultCompiler");
419+
meta.data.object.remove("globalPaths");
420+
infos("Default redub compiler is now reset.");
421+
}
422+
423+
if("defaultCompiler" in meta)
319424
{
320-
//return installDmd();
425+
infos(meta["globalPaths"][meta["defaultCompiler"].str].str, " is now the default compiler");
321426
}
427+
saveRedubMeta(meta);
322428
return 0;
323429
}

source/redub/buildapi.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import redub.package_searching.api;
88

99

1010
///vX.X.X
11-
enum RedubVersionOnly = "v1.25.6";
11+
enum RedubVersionOnly = "v1.25.7";
1212
///Redub vX.X.X
1313
enum RedubVersionShort = "Redub "~RedubVersionOnly;
1414
///Redub vX.X.X - Description

source/redub/compiler_identification.d

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ private string getActualCompilerToUse(string preferredCompiler, ref string actua
235235
{
236236
throw new Exception(preferredCompiler~ " --version returned a non zero code. "~
237237
"In Addition, dmd and ldc2 were also tested and were not found. You may need to download or specify them before using redub.\n" ~
238+
"If you don't have any compiler added in the PATH, you can install it by using 'redub install dmd' and then do 'redub use dmd'\n" ~
239+
"it will setup the compiler to use with redub. \n"~
238240
"Last Shell Output: "~ compVersionRes.output);
239241
}
240242
if(actualCompiler != preferredCompiler)
@@ -407,6 +409,46 @@ private CompilerBinary inferCompiler(string compilerOrPath, string compilerAssum
407409
throw new Exception("Could not infer which compiler you're using from "~compilerOrPath);
408410
}
409411

412+
/**
413+
*
414+
* Params:
415+
* compilerPath = The path where the compiler is
416+
* compilerAssumption = Assumption that will make skip --version call
417+
* compilersInfo = Used for saving metadata
418+
* isDefault = Used for metadata
419+
* isGlobal = Used for metadata
420+
* isC = Used for metadata
421+
* Returns: The compiler that was inferrred from the given info
422+
*/
423+
public void saveGlobalCompiler(string compilerPath, JSONValue compilersInfo, bool isDefault, bool isC)
424+
{
425+
import redub.misc.find_executable;
426+
import std.process;
427+
import std.array;
428+
immutable inference = [
429+
&tryInferDmd,
430+
&tryInferLdc,
431+
&tryInferGcc,
432+
&tryInferGxx
433+
].staticArray;
434+
435+
CompilerBinary ret;
436+
string actualCompiler;
437+
auto res = executeShell(compilerPath~" --version");
438+
if(res.status)
439+
throw new Exception("saveGlobalCompiler was called in an inexistent compiler.");
440+
foreach(inf; inference)
441+
{
442+
if(inf(actualCompiler, res.output, ret))
443+
{
444+
ret.bin = compilerPath;
445+
saveCompilerInfo(compilersInfo, ret, isDefault, true, isC);
446+
return;
447+
}
448+
}
449+
throw new Exception("Could not infer which compiler you're using from "~compilerPath);
450+
}
451+
410452

411453
private CompilerBinary getCompilerFromCache(JSONValue allCompilersInfo, string compiler)
412454
{
@@ -466,7 +508,7 @@ private CompilerBinary getCompilerFromCache(JSONValue allCompilersInfo, string c
466508
* isGlobal = Saves the compiler as a globalPath. For example, it will use the path whenever expected to find in global path when "dmd" is sent or "ldc2" (i.e: no real path)
467509
* isC = If is a C compiler
468510
*/
469-
private void saveCompilerInfo(JSONValue allCompilersInfo, ref CompilerBinary compiler, bool isDefault, bool isGlobal, bool isC)
511+
void saveCompilerInfo(JSONValue allCompilersInfo, ref CompilerBinary compiler, bool isDefault, bool isGlobal, bool isC)
470512
{
471513
import redub.meta;
472514
import std.conv:to;

source/redub/misc/_7zip.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool extract7ZipToFolder(string zPath, string outputDirectory)
4747
chdir(outputDirectory);
4848
scope(exit)
4949
chdir(dir);
50-
auto res = executeShell(_7z ~ " x -y "~zPath, t);
50+
auto res = executeShell(_7z ~ " x -y "~zPath);
5151
if(res.status)
5252
error("Could not extract 7z '", zPath, "' to '", outputDirectory, "': ", res.output);
5353
return res.status == 0;

source/redub/misc/dmd_install.d

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
module redub.misc.dmd_install;
2+
import std.system;
3+
4+
enum DefaultDMDVersion = "2.111.0";
5+
6+
7+
string getDmdFolder(string ver, OS os = std.system.os, ISA isa = instructionSetArchitecture)
8+
{
9+
import redub.api;
10+
import redub.misc.path;
11+
return buildNormalizedPath(getDubWorkspacePath, "redub-dmd", getDmdFolderName(ver, os, isa));
12+
}
13+
14+
15+
bool installDmd(string dmdVersion, OS os = std.system.os, ISA isa = instructionSetArchitecture)
16+
{
17+
import std.string;
18+
import std.array;
19+
import std.file;
20+
import redub.api;
21+
import redub.meta;
22+
import redub.misc.path;
23+
import redub.misc.unzip;
24+
import redub.libs.package_suppliers.utils;
25+
import redub.misc.make_file_executable;
26+
import redub.logging;
27+
string downloadLink = getDmdDownloadLink(dmdVersion, os, isa);
28+
if(dmdVersion.startsWith("v"))
29+
dmdVersion = dmdVersion[1..$];
30+
31+
string workspace = buildNormalizedPath(getDubWorkspacePath, "redub-dmd");
32+
string binPath = buildNormalizedPath(workspace, getDmdFolderName(dmdVersion, os, isa), "bin");
33+
if(!exists(workspace))
34+
mkdirRecurse(workspace);
35+
if(exists(binPath))
36+
{
37+
infos("LDC ",dmdVersion," is already installed at path ", binPath);
38+
return true;
39+
}
40+
41+
if(!downloadAndExtract(downloadLink, workspace))
42+
return false;
43+
44+
rename(buildNormalizedPath(workspace, "dmd2"), buildNormalizedPath(workspace, "dmd-"~dmdVersion));
45+
foreach(executable; ["ldc2", "ldmd2", "rdmd", "dub"].staticArray)
46+
if(!makeFileExecutable(buildNormalizedPath(binPath, executable)))
47+
return false;
48+
return true;
49+
}
50+
51+
private string getDmdFolderName(string ver, OS os = std.system.os, ISA isa = instructionSetArchitecture)
52+
{
53+
import redub.misc.path;
54+
import redub.command_generators.commons;
55+
import redub.api;
56+
import core.interpolation;
57+
import std.conv:to,text;
58+
import std.string:startsWith;
59+
string sys;
60+
if(ver.startsWith("v"))
61+
ver = ver[1..$];
62+
63+
if(os.isWindows)
64+
sys = isa == ISA.x86 ? "winndows\\bin" : "windows\\bin64";
65+
else if(os.isApple)
66+
sys = "osx/bin";
67+
else if(os.isPosix)
68+
sys = isa == ISA.x86 ? "linux/bin32" : "linux/bin64";
69+
else
70+
throw new RedubException("Redub has no support to DMD for the OS '"~os.to!string~"'");
71+
return buildNormalizedPath("dmd-"~ver, sys);
72+
}
73+
string getDmdDownloadLink(string ver, OS os = std.system.os, ISA isa = instructionSetArchitecture)
74+
{
75+
import redub.command_generators.commons;
76+
import redub.api;
77+
import core.interpolation;
78+
import std.conv:to,text;
79+
import std.string:startsWith;
80+
string sys;
81+
if(ver.startsWith("v"))
82+
ver = ver[1..$];
83+
84+
if(os.isWindows)
85+
sys = "windows.7z";
86+
else if(os.isApple)
87+
{
88+
if(isa == ISA.aarch64)
89+
throw new RedubException("Redub is not able to install dmd for MacOS ARM");
90+
sys = "osx.tar.xz";
91+
}
92+
else if(os.isPosix)
93+
sys = "linux.tar.xz";
94+
else
95+
throw new RedubException("Redub has no support to DMD for the OS '"~os.to!string~"'");
96+
return i"https://downloads.dlang.org/releases/2.x/$(ver)/dmd.$(ver).$(sys)".text;
97+
}

source/redub/misc/ldc_install.d

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
module redub.misc.ldc_install;
22
import std.system;
33

4+
string getLdcFolder(string ver, OS os = std.system.os, ISA isa = instructionSetArchitecture)
5+
{
6+
import redub.api;
7+
import redub.misc.path;
8+
return buildNormalizedPath(getDubWorkspacePath, "redub-ldc", getLdcFolderName(ver, os, isa), "bin");
9+
}
10+
11+
412
bool installLdc(string ldcVersion, OS os = std.system.os, ISA isa = instructionSetArchitecture)
513
{
614
import std.array;
@@ -32,7 +40,7 @@ bool installLdc(string ldcVersion, OS os = std.system.os, ISA isa = instructionS
3240
return true;
3341
}
3442

35-
string getLdcFolderName(string ver, OS os = std.system.os, ISA isa = instructionSetArchitecture)
43+
private string getLdcFolderName(string ver, OS os = std.system.os, ISA isa = instructionSetArchitecture)
3644
{
3745
import redub.command_generators.commons;
3846
import redub.api;

source/redub/misc/opend_install.d

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
module redub.misc.opend_install;
22
import std.system;
33

4+
string getOpendFolder(OS os = std.system.os, ISA isa = instructionSetArchitecture)
5+
{
6+
import redub.api;
7+
import redub.misc.path;
8+
return buildNormalizedPath(getDubWorkspacePath, "redub-opend", getOpendFolderName(os, isa), "bin");
9+
}
10+
411
bool installOpend(OS os = std.system.os, ISA isa = instructionSetArchitecture)
512
{
613
import std.array;

0 commit comments

Comments
 (0)