This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
PackageCompiler.pas
246 lines (208 loc) · 7.3 KB
/
PackageCompiler.pas
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
{**
DelphiPI (Delphi Package Installer)
Author : ibrahim dursun (ibrahimdursun gmail)
License : GNU General Public License 2.0
**}
unit PackageCompiler;
interface
uses JclIDEUtils, PackageInfo, PackageList, SysUtils, Classes, CompilationData, ProgressMonitor;
type
TPackageCompiler = class
private
fCompilationData: TCompilationData;
fCancel: boolean;
fSourceFilePaths: TStringList;
function ConvertToShortPaths(const paths : TStringList): string;
function GetInstallation: TJclBorRADToolInstallation;
function GetPackageList: TPackageList;
protected
fExtraOptions: String;
fAllPaths: TStringList;
procedure PrepareExtraOptions; virtual;
procedure ResolveHelpFiles(const compilationData: TCompilationData);
procedure AddSourcePathsToIDE(const sourceFilePaths: TStrings; const installation: TJclBorRADToolInstallation);
procedure ResolveSourcePaths; virtual;
property Installation: TJclBorRADToolInstallation read GetInstallation;
property PackageList: TPackageList read GetPackageList;
public
constructor Create(const compilationData: TCompilationData); virtual;
destructor Destroy; override;
procedure Compile; virtual;
function CompilePackage(const packageInfo : TPackageInfo): Boolean; virtual;
function InstallPackage(const packageInfo : TPackageInfo): Boolean; virtual;
//Properties
property Cancel: boolean read fCancel write fCancel;
property SourceFilePaths: TStringList read fSourceFilePaths write fSourceFilePaths;
property AllPaths: TStringList read fAllPaths;
property ExtraOptions: string read fExtraOptions;
end;
implementation
uses JclFileUtils, JclStrings;
{ TPackageCompiler }
constructor TPackageCompiler.Create(const compilationData: TCompilationData);
begin
fCompilationData := compilationData;
fSourceFilePaths := TStringList.Create;
fAllPaths := TStringList.Create;
fAllPaths.Delimiter := ';';
end;
destructor TPackageCompiler.Destroy;
begin
fSourceFilePaths.Free;
fAllPaths.Free;
inherited;
end;
function TPackageCompiler.GetInstallation: TJclBorRADToolInstallation;
begin
Result := fCompilationData.Installation;
end;
function TPackageCompiler.GetPackageList: TPackageList;
begin
Result := fCompilationData.PackageList;
end;
procedure TPackageCompiler.Compile;
var
i: integer;
info: TPackageInfo;
compilationSuccessful: boolean;
begin
if SourceFilePaths.Count = 0 then
ResolveSourcePaths;
PrepareExtraOptions;
AddSourcePathsToIDE(SourceFilePaths, fCompilationData.Installation);
if fCompilationData.HelpFiles.Count = 0 then
ResolveHelpFiles(fCompilationData);
PackageList.SortList;
for i := 0 to PackageList.Count - 1 do
begin
info := PackageList[i];
compilationSuccessful := CompilePackage(info);
if compilationSuccessful and (not info.RunOnly) then
InstallPackage(info);
if fCancel then
break;
end;
end;
function TPackageCompiler.CompilePackage(
const packageInfo: TPackageInfo): Boolean;
begin
Result := Installation.DCC32.MakePackage(
packageInfo.filename,
fCompilationData.BPLOutputFolder,
fCompilationData.DCPOutputFolder,
fExtraOptions);
end;
procedure TPackageCompiler.PrepareExtraOptions;
var
shortPaths: string;
I: Integer;
begin
fAllPaths.Clear;
ExtractStrings([';'],[' '],PWideChar(Installation.LibrarySearchPath[bpWin32]),fAllPaths);
fAllPaths.Add(Installation.BPLOutputPath[bpWin32]);
fAllPaths.AddStrings(SourceFilePaths);
for I := 0 to fAllPaths.Count - 1 do
fAllPaths[i] := Installation.SubstitutePath(StrTrimQuotes(fAllPaths[i]));
fAllPaths.Add('c:\Program Files (x86)\Embarcadero\RAD Studio\9.0\source\rtl\common');
shortPaths := ConvertToShortPaths(fAllPaths);
fExtraOptions := '-B -Q -CC';
fExtraOptions := fExtraOptions + ' -NSSystem;System.Win;WinAPI;Vcl;Vcl.Imaging;Data';
fExtraOptions := fExtraOptions + ' -I'+shortPaths;
fExtraOptions := fExtraOptions + ' -U'+shortPaths;
fExtraOptions := fExtraOptions + ' -O'+shortPaths;
fExtraOptions := fExtraOptions + ' -R'+shortPaths;
fExtraOptions := fExtraOptions + ' -N'+PathGetShortName(fCompilationData.DCUOutputFolder);
if Length(fCompilationData.Conditionals) > 0 then
fExtraOptions := fExtraOptions + ' -D'+fCompilationData.Conditionals;
end;
function TPackageCompiler.ConvertToShortPaths(const paths : TStringList):string;
var
path : string;
begin
Result := '';
for path in paths do
Result := Result + StrDoubleQuote(PathGetShortName(path)) + ';';
end;
function TPackageCompiler.InstallPackage(
const packageInfo: TPackageInfo): Boolean;
var
BPLFileName : String;
begin
BPLFileName := PathAddSeparator(Installation.BPLOutputPath[bpWin32]) + PathExtractFileNameNoExt(packageInfo.FileName) + packageInfo.Suffix + '.bpl';
Result := Installation.RegisterPackage(BPLFileName, packageInfo.Description);
end;
procedure TPackageCompiler.ResolveSourcePaths;
var
i,j: integer;
files, containedFiles: TStringList;
fileExt: string;
begin
Assert(assigned(SourceFilePaths));
files := TStringList.Create;
files.Sorted := true;
files.Duplicates := dupIgnore;
containedFiles := TStringList.Create;
containedFiles.Sorted := true;
containedFiles.Duplicates := dupIgnore;
SourceFilePaths.Clear;
SourceFilePaths.Sorted := true;
SourceFilePaths.Duplicates := dupIgnore;
for i := 0 to PackageList.Count - 1 do
begin
SourceFilePaths.Add(ExtractFileDir(PackageList[i].FileName));
for j := 0 to PackageList[i].ContainedFileList.Count - 1 do
containedFiles.Add(ExtractFileName(PackageList[i].ContainedFileList[j]));
end;
AdvBuildFileList(PathAppend(fCompilationData.BaseFolder,'*.pas'),
faAnyFile,
files,
amAny,
[flFullnames, flRecursive],
'', nil);
AdvBuildFileList(PathAppend(fCompilationData.BaseFolder,'*.inc'),
faAnyFile,
files,
amAny,
[flFullnames, flRecursive],
'', nil);
for I := 0 to files.count - 1 do
begin
fileExt := UpperCase(ExtractFileExt(files[i]));
if (containedFiles.IndexOf(ExtractFileName(files[i])) > 0) or (fileExt = '.INC') then
begin
SourceFilePaths.Add(ExtractFileDir(files[i]));
end
end;
end;
procedure TPackageCompiler.ResolveHelpFiles(const compilationData: TCompilationData);
var
files: TStringList;
filename: string;
begin
assert(assigned(fCompilationData));
files := TStringList.Create;
try
AdvBuildFileList(compilationData.BaseFolder +'\*.hlp',
faAnyFile,
files,
amAny,
[flFullnames, flRecursive],
'', nil);
for filename in files do
compilationData.HelpFiles.Add(filename);
finally
files.Free;
end;
end;
procedure TPackageCompiler.AddSourcePathsToIDE(const sourceFilePaths: TStrings; const installation: TJclBorRADToolInstallation);
var
path : string;
begin
Assert(assigned(sourceFilePaths));
Assert(assigned(installation));
for path in sourceFilePaths do
begin
installation.AddToLibrarySearchPath(path, bpWin32);
end;
end;
end.