Skip to content

Commit fc8a3ef

Browse files
committed
initial commit
0 parents  commit fc8a3ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+7803
-0
lines changed

.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.dub/
2+
.idea/
3+
.models.json
4+
.vagrant/
5+
.vscode/
6+
*-test-*
7+
*.a
8+
*.db
9+
*.exe
10+
*.h
11+
*.hpp
12+
*.iml
13+
*.lst
14+
*.o
15+
*.obj
16+
*.sqlite3*
17+
**/migrations/
18+
database.toml
19+
docs.json
20+
dorm.a
21+
dorm.dll
22+
dorm.dylib
23+
dorm.lib
24+
dorm.so
25+
./dorm
26+
dub.selections.json
27+
./update_downloader

build-models/dub.sdl

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name "build-models"
2+
3+
targetType "sourceLibrary"
4+
5+
configuration "application" {
6+
postBuildCommands "./$DUB_ROOT_PACKAGE_TARGET_PATH$DUB_ROOT_PACKAGE_TARGET_NAME --DORM-dump-models-json"
7+
versions "DormBuildModels"
8+
}
9+
10+
configuration "unittest" {
11+
postBuildCommands `echo "Not building models in unittest"`
12+
}
13+
14+
configuration "library" {
15+
postBuildCommands `echo "Not building models in library"`
16+
}

build-models/source/_dorm_dummy.d

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module _dorm_dummy;
2+
3+
// just here for source library targetType

download-map.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# rorm-cli
2+
linux_x86 https://github.com/rorm-orm/rorm-cli/releases/download/v0.3.0/rorm-cli-linux-x86_64.tar.gz 36CC2217750AB7DBD53061E9A625F51F7FE1C5F959DE27BA49A958F8CB2634B250988E16AE1A9BF5B6650A7984251858DA6C3474165DD27C8AD41274C8E56F45
3+
# rorm-lib
4+
linux_x86 https://github.com/rorm-orm/rorm-lib/releases/download/v0.3.0/librorm-linux-x86_64.a.tar.gz 7CEC207467FD6969711FEFFFB146D7CEC26AFBC5806F6AA1AF502792F69120A91817B12FC0E7176054208801354DB131E9B860634D22A4B1CE592F6C45296CA8

download_dependencies.d

+222
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
import fs = std.file;
2+
import std.algorithm;
3+
import std.array;
4+
import std.process;
5+
import std.stdio;
6+
import std.string;
7+
8+
int main(string[] args)
9+
{
10+
auto archIndex = args.countUntil("ARCH");
11+
auto platformIndex = args.countUntil("PLATFORM");
12+
13+
if (archIndex == -1 || platformIndex == -1)
14+
{
15+
stderr.writeln("Usage: ", args[0], " ARCH [archs...] PLATFORM [platforms...]");
16+
return 1;
17+
}
18+
19+
auto platforms = determinePlatforms(args[archIndex + 1 .. platformIndex], args[platformIndex + 1 .. $]);
20+
21+
if (!platforms.mapNames.length)
22+
{
23+
stderr.writeln("The target platform is not yet supported by DORM, ",
24+
"please open an issue or pull request for the target binary name! (DUB arguments: ",
25+
args[1 .. $], ")");
26+
27+
return 1;
28+
}
29+
30+
if (fs.exists(platforms.libname))
31+
return 0; // already downloaded & validated or manually compiled
32+
33+
try
34+
{
35+
downloadTool("rorm-cli", platforms.cliname, platforms, false, "`dub run dorm` will not work properly - download rorm-cli manually!");
36+
downloadTool("rorm-lib", platforms.libname, platforms, true, "Please manually compile rorm-lib for this platform.");
37+
38+
return 0;
39+
}
40+
catch (Exception e)
41+
{
42+
stderr.writeln("Failed to download precompiled rorm binaries: ", e.msg);
43+
stderr.writeln();
44+
stderr.writeln("TIP: you can manually compile rorm-lib to skip the automatic download step");
45+
stderr.writeln("Expected to find or download '", platforms.libname, "' in '", fs.getcwd, "'");
46+
stderr.writeln("DUB target: ", args[1 .. $]);
47+
return 1;
48+
}
49+
}
50+
51+
void downloadTool(string name, string output, TargetPlatform target, bool required, string errorSupplemental = null)
52+
{
53+
bool inSection = false;
54+
MapLine[] foundLines;
55+
foreach (line; File("download-map.txt", "r").byLine)
56+
{
57+
if (line.startsWith("# " ~ name))
58+
inSection = true;
59+
else if (line.startsWith("#"))
60+
inSection = false;
61+
else if (inSection)
62+
{
63+
auto mapLine = MapLine.fromString(line.idup);
64+
if (target.mapNames.canFind(mapLine.platformName))
65+
foundLines ~= mapLine;
66+
}
67+
}
68+
69+
if (!foundLines.length)
70+
{
71+
if (required)
72+
throw new Exception("Does not have any precompiled binaries for this platform for " ~ name
73+
~ (errorSupplemental.length ? " - " ~ errorSupplemental : ""));
74+
else
75+
stderr.writeln("Warning: Does not have any precompiled binaries for this platform for " ~ name
76+
~ (errorSupplemental.length ? " - " ~ errorSupplemental : ""));
77+
return;
78+
}
79+
80+
// first mapName takes priority
81+
foreach (wanted; target.mapNames)
82+
{
83+
foreach (found; foundLines)
84+
{
85+
if (found.platformName == wanted)
86+
{
87+
auto unverifiedOutput = output ~ ".unverified";
88+
download(found.url, unverifiedOutput);
89+
validateSHA512(unverifiedOutput, found.sha512);
90+
fs.rename(unverifiedOutput, output);
91+
extractAndDelete(output);
92+
return;
93+
}
94+
}
95+
}
96+
97+
assert(false);
98+
}
99+
100+
struct MapLine
101+
{
102+
string platformName;
103+
string url;
104+
string sha512;
105+
106+
static MapLine fromString(string s)
107+
{
108+
auto parts = s.split("\t");
109+
if (parts.length != 3)
110+
throw new Exception("malformed download-map.txt line: " ~ s);
111+
return MapLine(parts[0], parts[1], parts[2]);
112+
}
113+
}
114+
115+
struct TargetPlatform
116+
{
117+
string[] mapNames, archs, platforms;
118+
string os;
119+
120+
static TargetPlatform osx(string[] mapNames, string[] archs, string[] platforms)
121+
{
122+
return TargetPlatform(mapNames, archs, platforms, "osx");
123+
}
124+
125+
static TargetPlatform linux(string[] mapNames, string[] archs, string[] platforms)
126+
{
127+
return TargetPlatform(mapNames, archs, platforms, "linux");
128+
}
129+
130+
static TargetPlatform windows(string[] mapNames, string[] archs, string[] platforms)
131+
{
132+
return TargetPlatform(mapNames, archs, platforms, "windows");
133+
}
134+
135+
string libname() const @property
136+
{
137+
if (platforms.canFind("posix"))
138+
return "librorm.a";
139+
else if (platforms.canFind("windows"))
140+
return "rorm.lib";
141+
else
142+
throw new Exception("unsupported platform for libname");
143+
}
144+
145+
string cliname() const @property
146+
{
147+
if (platforms.canFind("posix"))
148+
return "rorm-cli";
149+
else if (platforms.canFind("windows"))
150+
return "rorm-cli.exe";
151+
else
152+
throw new Exception("unsupported platform for cliname");
153+
}
154+
}
155+
156+
TargetPlatform determinePlatforms(string[] archs, string[] platforms)
157+
{
158+
if (archs.canFind("aarch64"))
159+
{
160+
if (platforms.canFind("osx"))
161+
return TargetPlatform.osx(["osx_arm64", "osx_x86"], archs, platforms);
162+
else if (platforms.canFind("linux"))
163+
return TargetPlatform.linux(["linux_arm64"], archs, platforms);
164+
else
165+
return TargetPlatform.init;
166+
}
167+
else if (archs.canFind("x86_64"))
168+
{
169+
if (platforms.canFind("osx"))
170+
return TargetPlatform.osx(["osx_x86"], archs, platforms);
171+
else if (platforms.canFind("linux"))
172+
return TargetPlatform.linux(["linux_x86"], archs, platforms);
173+
else if (platforms.canFind("windows"))
174+
return TargetPlatform.windows(["windows_x86"], archs, platforms);
175+
else
176+
return TargetPlatform.init;
177+
}
178+
else
179+
return TargetPlatform.init;
180+
}
181+
182+
void download(string url, string file)
183+
{
184+
auto res = spawnProcess(["wget", url, "-O", file]).wait;
185+
if (res != 0)
186+
throw new Exception("Failed to download " ~ url ~ " to " ~ file);
187+
}
188+
189+
void validateSHA512(string file, string sha512)
190+
{
191+
import std.digest;
192+
import std.digest.sha;
193+
import std.string;
194+
195+
auto got = sha512Of(cast(ubyte[]) fs.read(file));
196+
197+
if (got.toHexString.toUpper != sha512.toUpper)
198+
throw new Exception("SHA512 validation failed for file " ~ file);
199+
}
200+
201+
void extractAndDelete(string file)
202+
{
203+
if (file.endsWith(".tar.gz"))
204+
{
205+
if (spawnProcess(["tar", "-xvf", file]).wait != 0)
206+
throw new Exception("Failed extracting release binary " ~ file);
207+
}
208+
else if (file.endsWith(".zip"))
209+
{
210+
import std.zip;
211+
212+
auto zip = new ZipArchive(fs.read(file));
213+
214+
foreach (name, am; zip.directory)
215+
{
216+
zip.expand(am);
217+
name = name.chompPrefix("/").chompPrefix("\\");
218+
if (!name.startsWith("."))
219+
fs.write(name, am.expandedData);
220+
}
221+
}
222+
}

dscanner.ini

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; Configure which static analysis checks are enabled
2+
[analysis.config.StaticAnalysisConfig]
3+
; Checks for undocumented public declarations
4+
undocumented_declaration_check="enabled"

dub.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "dorm",
3+
"license": "MIT",
4+
"authors": [
5+
"WebFreak <[email protected]>",
6+
"myOmikron <[email protected]>"
7+
],
8+
"copyright": "Copyright © 2022, WebFreak",
9+
"dependencies": {
10+
"mir-ion": "~>2.1"
11+
},
12+
"preBuildCommands": ["\"$DC\" -run download_dependencies.d ARCH $DUB_ARCH PLATFORM $DUB_PLATFORM"],
13+
"extraDependencyFiles-posix": [
14+
"download-map.txt", "librorm.a"
15+
],
16+
"extraDependencyFiles-windows": [
17+
"download-map.txt", "rorm.lib"
18+
],
19+
"libs": ["rorm"],
20+
"lflags-linux": ["-L$PACKAGE_DIR", "-R$PACKAGE_DIR"],
21+
"lflags-osx": [
22+
"-L$PACKAGE_DIR",
23+
"-framework", "CoreFoundation",
24+
"-framework", "SystemConfiguration",
25+
"-framework", "SecurityFoundation"
26+
],
27+
"lflags-windows": ["/DEFAULTLIB:MSVCRT", "/NODEFAULTLIB:libcmt"],
28+
"libs-windows": ["Ws2_32", "ntdll", "ucrt", "Bcrypt", "Userenv", "Ole32"],
29+
"description": "A D ORM.",
30+
"dflags": [
31+
"-lowmem"
32+
],
33+
"subPackages": [
34+
"build-models"
35+
]
36+
}

integration-tests/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!dub.selections.json
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/all-fields

integration-tests/all-fields/dub.sdl

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name "all-fields"
2+
3+
dependency "dorm" path="../.."
4+
dependency "dorm:build-models" path="../.."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"fileVersion": 1,
3+
"versions": {
4+
"dorm": {"path":"../.."},
5+
"mir-algorithm": "3.18.2",
6+
"mir-core": "1.3.14",
7+
"mir-cpuid": "1.2.10",
8+
"mir-ion": "2.1.0",
9+
"silly": "1.1.1"
10+
}
11+
}

integration-tests/all-fields/run.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
dub build
5+
$RORM_CLI make-migrations
6+
$RORM_CLI migrate
7+
./all-fields

0 commit comments

Comments
 (0)