source: trunk/UInstance.pas

Last change on this file was 13, checked in by chronos, 6 years ago
  • Fixed: Build under Lazarus 1.8.0.
File size: 7.3 KB
Line 
1unit UInstance;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, USource, Contnrs, Process, Forms, Controls,
9 FileUtil, Dialogs;
10
11type
12 { TInstance }
13
14 TInstance = class
15 private
16 function GetCompiled: Boolean;
17 function GetDownloaded: Boolean;
18 public
19 Id: Integer;
20 Name: string;
21 IDESource: TSource;
22 IDERevision: string;
23 IDEDate: TDateTime;
24 FPCSource: TSource;
25 FPCRevision: string;
26 FPCDate: TDateTime;
27 procedure Build;
28 procedure Start;
29 procedure UpdateLazarusConfig;
30 procedure UpdateFPCConfig;
31 function GetPath: string;
32 function GetBinPath: string;
33 property Downloaded: Boolean read GetDownloaded;
34 property Compiled: Boolean read GetCompiled;
35 end;
36
37 { TInstanceList }
38
39 TInstanceList = class(TObjectList)
40 function GetNewId: Integer;
41 end;
42
43implementation
44
45uses
46 UOperationProgress, UMainForm;
47
48{ TInstanceList }
49
50function TInstanceList.GetNewId: Integer;
51var
52 I: Integer;
53begin
54 Result := 1;
55 for I := 0 to Count - 1 do
56 if TInstance(Items[I]).Id >= Result then
57 Result := TInstance(Items[I]).Id + 1;
58end;
59
60{ TInstance }
61
62function TInstance.GetCompiled: Boolean;
63begin
64 Result := FileExists(GetBinPath + DirectorySeparator + FPCSource.GetExecutableFile);
65 if Assigned(IDESource) then Result := Result and
66 FileExists(GetPath + DirectorySeparator + IDESource.ProjectShortName +
67 DirectorySeparator + IDESource.GetExecutableFile);
68end;
69
70function TInstance.GetDownloaded: Boolean;
71begin
72 Result := DirectoryExists(GetPath + DirectorySeparator + FPCSource.ProjectShortName);
73 if Assigned(IDESource) then Result := Result and
74 DirectoryExists(GetPath + DirectorySeparator + IDESource.ProjectShortName);
75end;
76
77procedure TInstance.Build;
78begin
79 {$IFDEF Windows}
80 OperationProgressForm.Environment := 'PATH=' + MainForm.GetBinUtilsDir;
81 {$ENDIF}
82 OperationProgressForm.Path := GetPath + DirectorySeparator + FPCSource.ProjectShortName;
83 OperationProgressForm.CommandLine := 'make clean all PP=' +
84 MainForm.GetCompilerPath + '';
85 OperationProgressForm.ShowModal;
86
87 {$IFDEF Windows}
88 OperationProgressForm.Environment := 'PATH=' + MainForm.GetBinUtilsDir;
89 {$ENDIF}
90 OperationProgressForm.Path := GetPath + DirectorySeparator + FPCSource.ProjectShortName;
91 OperationProgressForm.CommandLine := 'make install PREFIX=' +
92 GetPath + DirectorySeparator + FPCSource.ProjectShortName + '' +
93 ' PP=' + MainForm.GetCompilerPath + '';
94 OperationProgressForm.ShowModal;
95
96 if Assigned(IDESource) then begin
97 {$IFDEF Windows}
98 OperationProgressForm.Environment := 'PATH=' + MainForm.GetBinUtilsDir;
99 {$ENDIF}
100 OperationProgressForm.Path := GetPath + DirectorySeparator + IDESource.ProjectShortName;
101 OperationProgressForm.CommandLine :=
102 'make OPT="-Xg"';
103 OperationProgressForm.ShowModal;
104 end;
105end;
106
107procedure TInstance.Start;
108var
109 Process: TProcess;
110 I: Integer;
111begin
112 if Assigned(IDESource) then
113 try
114 UpdateFPCConfig;
115 UpdateLazarusConfig;
116
117 Process := TProcess.Create(nil);
118
119 {$IFDEF Linux}
120 for I := 0 to GetEnvironmentVariableCount - 1 do
121 Process.Environment.Add(GetEnvironmentString(I));
122
123 Process.Environment.Values['PATH'] := GetPath + DirectorySeparator + FPCSource.ProjectShortName +
124 '/lib/fpc/' + FPCSource.VersionNumber + ':' + Process.Environment.Values['PATH'];
125 Process.Environment.Values['PPC_CONFIG_PATH'] := GetBinPath;
126 //ShowMessage(Process.Environment.Text);
127 {$ENDIF}
128 {$IFDEF Windows}
129 OperationProgressForm.Environment := 'PATH=' + MainForm.GetBinUtilsDir;
130 {$ENDIF}
131 Process.CurrentDirectory := GetPath + DirectorySeparator + IDESource.ProjectShortName;
132 Process.CommandLine := GetPath + DirectorySeparator + IDESource.ProjectShortName +
133 DirectorySeparator + IDESource.GetExecutableFile + ' --primary-config-path=' +
134 GetPath + DirectorySeparator + IDESource.ProjectShortName +
135 DirectorySeparator + 'config';
136 Process.Execute;
137 finally
138 Process.Free;
139 end;
140end;
141
142procedure TInstance.UpdateLazarusConfig;
143var
144 Config: TStringList;
145 ConfigFileName: string;
146 ConfigPath: string;
147begin
148 ConfigPath := GetPath + DirectorySeparator + IDESource.ProjectShortName +
149 DirectorySeparator + 'config';
150 ForceDirectories(ConfigPath);
151 ConfigFileName := ConfigPath + DirectorySeparator + 'environmentoptions.xml';
152 if not FileExists(ConfigFileName) then
153 try
154 Config := TStringList.Create;
155 Config.LoadFromFile(MainForm.GetBaseDir + DirectorySeparator +
156 MainForm.TemplateDir + DirectorySeparator + 'environmentoptions.xml');
157 Config.Text := StringReplace(Config.Text, '%FPCDir%', GetPath + DirectorySeparator + FPCSource.ProjectShortName, [rfReplaceAll]);
158 Config.Text := StringReplace(Config.Text, '%BaseDir%', MainForm.GetBaseDir, [rfReplaceAll]);
159 Config.Text := StringReplace(Config.Text, '%LazarusDir%', GetPath + DirectorySeparator + IDESource.ProjectShortName, [rfReplaceAll]);
160 {$IFDEF Windows}
161 Config.Text := StringReplace(Config.Text, '%Make%', MainForm.GetBinUtilsDir + DirectorySeparator + 'make.exe', [rfReplaceAll]);
162 Config.Text := StringReplace(Config.Text, '%FPCCompiler%', GetBinPath + DirectorySeparator + FPCSource.ExecutableFile + '.exe', [rfReplaceAll]);
163 Config.Text := StringReplace(Config.Text, '%Temp%', GetEnvironmentVariable('TEMP'), [rfReplaceAll]);
164 Config.Text := StringReplace(Config.Text, '%GDB%', MainForm.GetBinUtilsDir + DirectorySeparator + 'mingw\gdb.exe', [rfReplaceAll]);
165 {$ENDIF}
166 {$IFDEF Linux}
167 Config.Text := StringReplace(Config.Text, '%Make%', MainForm.GetBinUtilsDir + DirectorySeparator + 'make', [rfReplaceAll]);
168 Config.Text := StringReplace(Config.Text, '%FPCCompiler%', GetBinPath + DirectorySeparator + FPCSource.ExecutableFile, [rfReplaceAll]);
169 Config.Text := StringReplace(Config.Text, '%Temp%', '/tmp', [rfReplaceAll]);
170 Config.Text := StringReplace(Config.Text, '%GDB%', '/usr/bin/gdb', [rfReplaceAll]);
171 {$ENDIF}
172 Config.SaveToFile(ConfigFileName);
173 finally
174 Config.Free;
175 end;
176end;
177
178procedure TInstance.UpdateFPCConfig;
179var
180 Config: TStringList;
181begin
182 try
183 Config := TStringList.Create;
184 Config.LoadFromFile(MainForm.GetBaseDir + DirectorySeparator +
185 MainForm.TemplateDir + DirectorySeparator + 'fpc.cfg');
186 {$IFDEF Windows}
187 Config.Text := StringReplace(Config.Text, '$(FPCDir)', GetPath +
188 DirectorySeparator + FPCSource.ProjectShortName, [rfReplaceAll]);
189 {$ENDIF}
190 {$IFDEF Linux}
191 Config.Text := StringReplace(Config.Text, '$(FPCDir)', GetPath +
192 DirectorySeparator + FPCSource.ProjectShortName +
193 '/lib/fpc/' + FPCSource.VersionNumber, [rfReplaceAll]);
194 {$ENDIF}
195 Config.SaveToFile(GetBinPath + DirectorySeparator + 'fpc.cfg');
196 finally
197 Config.Free;
198 end;
199end;
200
201function TInstance.GetPath: string;
202begin
203 Result := ExtractFileDir(Application.ExeName) + DirectorySeparator +
204 MainForm.InstanceDir + DirectorySeparator + IntToStr(Id);
205end;
206
207function TInstance.GetBinPath: string;
208begin
209 Result := GetPath + DirectorySeparator + FPCSource.ProjectShortName +
210 DirectorySeparator + 'bin';
211 {$IFDEF Windows}
212 Result := Result + DirectorySeparator + MainForm.Platform;
213 {$ENDIF}
214end;
215
216end.
217
Note: See TracBrowser for help on using the repository browser.