Repository navigation
Expand file tree
/
Copy pathDN.ProjectInfo.pas
More file actions
216 lines (195 loc) · 6.72 KB
/
Copy pathDN.ProjectInfo.pas
File metadata and controls
216 lines (195 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.ProjectInfo;
interface
uses
Classes,
Types,
SysUtils,
XMLIntf,
DN.ProjectInfo.Intf,
DN.Compiler.Intf;
type
TDNProjectInfo = class(TInterfacedObject, IDNProjectInfo)
private
FBinaryName: string;
FDCPName: string;
FFileName: string;
FIsPackage: Boolean;
FIsRuntimeOnlyPackage: Boolean;
FSupportedPlatforms: TDNCompilerPlatforms;
function GetBinaryName: string;
function GetDCPName: string;
function GetIsPackage: Boolean;
function GetDefaultExtension(const AAppType: string): string;
function GetPropertyGroupOfConfig(const AProject: IXMLNode; const AConfig: string): IXMLNode;
function GetIsRuntimeOnlyPackage: Boolean;
function GetFileName: string;
function GetSupportedPlatforms: TDNCompilerPlatforms;
public
function LoadFromFile(const AProjectFile: string): Boolean;
property IsPackage: Boolean read GetIsPackage;
property IsRuntimeOnlyPackage: Boolean read GetIsRuntimeOnlyPackage;
property BinaryName: string read GetBinaryName;
property DCPName: string read GetDCPName;
property FileName: string read GetFileName;
property SupportedPlatforms: TDNCompilerPlatforms read GetSupportedPlatforms;
end;
implementation
uses
IOUtils,
XMLDoc,
StrUtils,
Variants;
const
CPropertyGroup = 'PropertyGroup';
CProject = 'Project';
CCondition = '''$(%s)''!=''''';
CBase = 'Base';
CBaseWin32 = 'Base_Win32';
CBaseWin64 = 'Base_Win64';
{ TDNProjectInfo }
function TDNProjectInfo.GetBinaryName: string;
begin
Result := FBinaryName;
end;
function TDNProjectInfo.GetDCPName: string;
begin
Result := FDCPName;
end;
function TDNProjectInfo.GetDefaultExtension(const AAppType: string): string;
begin
if SameText('Library', AAppType) then
Result := '.dll'
else if SameText('Package', AAppType) then
Result := '.bpl'
else
Result := '.exe';
end;
function TDNProjectInfo.GetFileName: string;
begin
Result := FFileName;
end;
function TDNProjectInfo.GetIsPackage: Boolean;
begin
Result := FIsPackage;
end;
function TDNProjectInfo.GetIsRuntimeOnlyPackage: Boolean;
begin
Result := FIsRuntimeOnlyPackage;
end;
function TDNProjectInfo.GetPropertyGroupOfConfig(const AProject: IXMLNode;
const AConfig: string): IXMLNode;
var
LGroup: IXMLNode;
LCondition: string;
begin
Result := nil;
LCondition := Format(CCondition, [AConfig]);
LGroup := AProject.ChildNodes.First();
while Assigned(LGroup) do
begin
if SameText(LGroup.LocalName, CPropertyGroup) then
begin
if LGroup.HasAttribute('Condition') and SameText(LGroup.Attributes['Condition'], LCondition) then
begin
Exit(LGroup);
end;
end;
LGroup := LGroup.NextSibling;
end;
end;
function TDNProjectInfo.GetSupportedPlatforms: TDNCompilerPlatforms;
begin
Result := FSupportedPlatforms;
end;
function TDNProjectInfo.LoadFromFile(const AProjectFile: string): Boolean;
var
LXML: IXMLDocument;
LBaseName, LCoreFile, LAppType, LExtension: string;
LPrefix, LSuffix, LVersion: string;
LProject, LPropertyGroup, LBase: IXMLNode;
LProjectExtension, LBorlandProject, LPlatforms, LPlatform: IXMLNode;
begin
Result := False;
if TFile.Exists(AProjectFile) then
begin
FFileName := AProjectFile;
LXML := TXMLDocument.Create(nil);
LXML.LoadFromFile(AProjectFile);
LProject := LXML.ChildNodes.FindNode(CProject);
if Assigned(LProject) then
begin
LPropertyGroup := LProject.ChildNodes.FindNode(CPropertyGroup);
if Assigned(LPropertyGroup) then
begin
LCoreFile := LPropertyGroup.ChildValues['MainSource'];
LBaseName := ChangeFileExt(LCoreFile, '');
LAppType := VarToStr(LPropertyGroup.ChildValues['AppType']);
FIsPackage := SameText(LAppType, 'Package');
if FIsPackage then
FDCPName := LBaseName + '.dcp'
else
FDCPName := '';
FIsRuntimeOnlyPackage := False;
LBase := GetPropertyGroupOfConfig(LProject, CBase);
if Assigned(LBase) then
begin
FIsRuntimeOnlyPackage := StrToBool(VarToStrDef(LBase.ChildValues['RuntimeOnlyPackage'], 'False'));
//read extensions, post/suffix and version
LExtension := VarToStr(LBase.ChildValues['OutputExt']);
if (LExtension <> '') and (not StartsText('.', LExtension)) then
LExtension := '.' + LExtension;
LPrefix := VarToStr(LBase.ChildValues['DllPrefix']);
LSuffix := VarToStr(LBase.ChildValues['DllSuffix']);
LVersion := VarToStr(LBase.ChildValues['DllVersion']);
if LVersion <> '' then
LVersion := '.' + LVersion;
end;
if LExtension = '' then
LExtension := GetDefaultExtension(LAppType);
FBinaryName := LPrefix + LBaseName + LSuffix + LVersion + LExtension;
//detect supported platforms
FSupportedPlatforms := [];
LProjectExtension := LProject.ChildNodes.FindNode('ProjectExtensions');
if Assigned(LProjectExtension) then
begin
LBorlandProject := LProjectExtension.ChildNodes.FindNode('BorlandProject');
if Assigned(LBorlandProject) then
begin
LPlatforms := LBorlandProject.ChildNodes.FindNode('Platforms');
if Assigned(LPlatforms) then
begin
LPlatform := LPlatforms.ChildNodes.First;
while Assigned(LPlatform) do
begin
if SameText(LPlatform.Text, 'True') then
begin
if LPlatform.HasAttribute('value') then
begin
if SameText(LPlatform.Attributes['value'], 'Win32') then
FSupportedPlatforms := FSupportedPlatforms + [cpWin32]
else if SameText(LPlatform.Attributes['value'], 'Win64') then
FSupportedPlatforms := FSupportedPlatforms + [cpWin64]
else if SameText(LPlatform.Attributes['value'], 'OSX32') then
FSupportedPlatforms := FSupportedPlatforms + [cpOSX32]
end;
end;
LPlatform := LPlatform.NextSibling;
end;
end;
end;
end;
if FSupportedPlatforms = [] then
FSupportedPlatforms := [cpWin32];
Result := True;
end;
end;
end;
end;
end.