| 1 | unit UInstance;
|
|---|
| 2 |
|
|---|
| 3 | {$mode objfpc}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, USource, Contnrs, Process, Forms, Controls,
|
|---|
| 9 | FileUtil, Dialogs;
|
|---|
| 10 |
|
|---|
| 11 | type
|
|---|
| 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 |
|
|---|
| 43 | implementation
|
|---|
| 44 |
|
|---|
| 45 | uses
|
|---|
| 46 | UOperationProgress, UMainForm;
|
|---|
| 47 |
|
|---|
| 48 | { TInstanceList }
|
|---|
| 49 |
|
|---|
| 50 | function TInstanceList.GetNewId: Integer;
|
|---|
| 51 | var
|
|---|
| 52 | I: Integer;
|
|---|
| 53 | begin
|
|---|
| 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;
|
|---|
| 58 | end;
|
|---|
| 59 |
|
|---|
| 60 | { TInstance }
|
|---|
| 61 |
|
|---|
| 62 | function TInstance.GetCompiled: Boolean;
|
|---|
| 63 | begin
|
|---|
| 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);
|
|---|
| 68 | end;
|
|---|
| 69 |
|
|---|
| 70 | function TInstance.GetDownloaded: Boolean;
|
|---|
| 71 | begin
|
|---|
| 72 | Result := DirectoryExists(GetPath + DirectorySeparator + FPCSource.ProjectShortName);
|
|---|
| 73 | if Assigned(IDESource) then Result := Result and
|
|---|
| 74 | DirectoryExists(GetPath + DirectorySeparator + IDESource.ProjectShortName);
|
|---|
| 75 | end;
|
|---|
| 76 |
|
|---|
| 77 | procedure TInstance.Build;
|
|---|
| 78 | begin
|
|---|
| 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;
|
|---|
| 105 | end;
|
|---|
| 106 |
|
|---|
| 107 | procedure TInstance.Start;
|
|---|
| 108 | var
|
|---|
| 109 | Process: TProcess;
|
|---|
| 110 | I: Integer;
|
|---|
| 111 | begin
|
|---|
| 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;
|
|---|
| 140 | end;
|
|---|
| 141 |
|
|---|
| 142 | procedure TInstance.UpdateLazarusConfig;
|
|---|
| 143 | var
|
|---|
| 144 | Config: TStringList;
|
|---|
| 145 | ConfigFileName: string;
|
|---|
| 146 | ConfigPath: string;
|
|---|
| 147 | begin
|
|---|
| 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;
|
|---|
| 176 | end;
|
|---|
| 177 |
|
|---|
| 178 | procedure TInstance.UpdateFPCConfig;
|
|---|
| 179 | var
|
|---|
| 180 | Config: TStringList;
|
|---|
| 181 | begin
|
|---|
| 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;
|
|---|
| 199 | end;
|
|---|
| 200 |
|
|---|
| 201 | function TInstance.GetPath: string;
|
|---|
| 202 | begin
|
|---|
| 203 | Result := ExtractFileDir(Application.ExeName) + DirectorySeparator +
|
|---|
| 204 | MainForm.InstanceDir + DirectorySeparator + IntToStr(Id);
|
|---|
| 205 | end;
|
|---|
| 206 |
|
|---|
| 207 | function TInstance.GetBinPath: string;
|
|---|
| 208 | begin
|
|---|
| 209 | Result := GetPath + DirectorySeparator + FPCSource.ProjectShortName +
|
|---|
| 210 | DirectorySeparator + 'bin';
|
|---|
| 211 | {$IFDEF Windows}
|
|---|
| 212 | Result := Result + DirectorySeparator + MainForm.Platform;
|
|---|
| 213 | {$ENDIF}
|
|---|
| 214 | end;
|
|---|
| 215 |
|
|---|
| 216 | end.
|
|---|
| 217 |
|
|---|