pkgoptions.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. {
  2. This file is part of the Free Pascal Utilities
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {$mode objfpc}
  11. {$h+}
  12. unit pkgoptions;
  13. interface
  14. uses Classes, Sysutils, Inifiles, fprepos, fpTemplate;
  15. Const
  16. UnitConfigFileName = 'fpunits.conf';
  17. ManifestFileName = 'manifest.xml';
  18. MirrorsFileName = 'mirrors.xml';
  19. PackagesFileName = 'packages.xml';
  20. VersionsFileName = 'versions-%s.dat';
  21. CurrentConfigVersion = 4;
  22. Type
  23. { TGlobalOptions }
  24. TGlobalOptions = Class(TPersistent)
  25. private
  26. FDirty : Boolean;
  27. FConfigVersion : Integer;
  28. FRemoteMirrorsURL,
  29. FRemoteRepository,
  30. FLocalRepository,
  31. FCompilerConfigDir,
  32. FArchivesDir,
  33. FBuildDir,
  34. FDownloader,
  35. FDefaultCompilerConfig,
  36. FFPMakeCompilerConfig : String;
  37. // Parameter options
  38. FCompilerConfig : String;
  39. FAllowBroken,
  40. FInstallGlobal,
  41. FRecoveryMode : Boolean;
  42. FOptionParser: TTemplateParser;
  43. FShowLocation: Boolean;
  44. function GetOptString(Index: integer): String;
  45. procedure SetOptString(Index: integer; const AValue: String);
  46. procedure UpdateLocalRepositoryOption;
  47. Public
  48. Constructor Create;
  49. destructor Destroy; override;
  50. Procedure InitGlobalDefaults;
  51. Procedure LoadGlobalFromFile(const AFileName : String);
  52. Procedure SaveGlobalToFile(const AFileName : String);
  53. procedure LogValues;
  54. Property Dirty : Boolean Read FDirty;
  55. Property ConfigVersion : Integer read FConfigVersion;
  56. function LocalPackagesFile:string;
  57. function LocalMirrorsFile:string;
  58. function LocalVersionsFile(const ACompilerConfig:String):string;
  59. Published
  60. Property RemoteMirrorsURL : String Index 0 Read GetOptString Write SetOptString;
  61. // 1 is unused
  62. Property RemoteRepository : String Index 2 Read GetOptString Write SetOptString;
  63. Property LocalRepository : String Index 3 Read GetOptString Write SetOptString;
  64. Property BuildDir : String Index 4 Read GetOptString Write SetOptString;
  65. Property ArchivesDir : String Index 5 Read GetOptString Write SetOptString;
  66. Property CompilerConfigDir : String Index 6 Read GetOptString Write SetOptString;
  67. Property DefaultCompilerConfig : String Index 8 Read GetOptString Write SetOptString;
  68. Property FPMakeCompilerConfig : String Index 9 Read GetOptString Write SetOptString;
  69. Property Downloader: String Index 10 Read GetOptString Write SetOptString;
  70. // Parameters
  71. Property CompilerConfig : String Read FCompilerConfig Write FCompilerConfig;
  72. Property InstallGlobal : Boolean Read FInstallGlobal Write FInstallGlobal;
  73. Property RecoveryMode : Boolean Read FRecoveryMode Write FRecoveryMode;
  74. Property AllowBroken : Boolean Read FAllowBroken Write FAllowBroken;
  75. Property ShowLocation : Boolean Read FShowLocation Write FShowLocation;
  76. end;
  77. { TCompilerOptions }
  78. TCompilerOptions = Class(TPersistent)
  79. private
  80. FDirty: Boolean;
  81. FConfigVersion : Integer;
  82. FCompiler,
  83. FCompilerVersion,
  84. FLocalInstallDir,
  85. FGlobalInstallDir : String;
  86. FCompilerCPU: TCPU;
  87. FCompilerOS: TOS;
  88. FOptionParser: TTemplateParser;
  89. function GetOptString(Index: integer): String;
  90. procedure SetOptString(Index: integer; const AValue: String);
  91. procedure SetCompilerCPU(const AValue: TCPU);
  92. procedure SetCompilerOS(const AValue: TOS);
  93. Public
  94. Constructor Create;
  95. Destructor Destroy; override;
  96. Procedure InitCompilerDefaults;
  97. Procedure LoadCompilerFromFile(const AFileName : String);
  98. Procedure SaveCompilerToFile(const AFileName : String);
  99. procedure LogValues(const ACfgName:string);
  100. procedure UpdateLocalRepositoryOption;
  101. Function LocalUnitDir:string;
  102. Function GlobalUnitDir:string;
  103. Property Dirty : Boolean Read FDirty;
  104. Property ConfigVersion : Integer read FConfigVersion;
  105. Published
  106. Property Compiler : String Index 1 Read GetOptString Write SetOptString;
  107. Property CompilerTarget : String Index 2 Read GetOptString Write SetOptString;
  108. Property CompilerVersion : String Index 3 Read GetOptString Write SetOptString;
  109. Property GlobalInstallDir : String Index 4 Read GetOptString Write SetOptString;
  110. Property LocalInstallDir : String Index 5 Read GetOptString Write SetOptString;
  111. Property CompilerOS : TOS Read FCompilerOS Write SetCompilerOS;
  112. Property CompilerCPU : TCPU Read FCompilerCPU Write SetCompilerCPU;
  113. end;
  114. var
  115. GlobalOptions : TGlobalOptions;
  116. CompilerOptions : TCompilerOptions;
  117. FPMakeCompilerOptions : TCompilerOptions;
  118. Implementation
  119. uses
  120. pkgglobals,
  121. pkgmessages;
  122. Const
  123. DefaultMirrorsURL = 'http://www.freepascal.org/repository/'+MirrorsFileName;
  124. {$ifdef localrepository}
  125. DefaultRemoteRepository = 'file://'+{$I %HOME%}+'/repository/';
  126. {$else}
  127. DefaultRemoteRepository = 'auto';
  128. {$endif}
  129. // ini file keys
  130. SDefaults = 'Defaults';
  131. // All configs
  132. KeyConfigVersion = 'ConfigVersion';
  133. // Global config
  134. KeyRemoteMirrorsURL = 'RemoteMirrors';
  135. KeyRemoteRepository = 'RemoteRepository';
  136. KeyLocalRepository = 'LocalRepository';
  137. KeyArchivesDir = 'ArchivesDir';
  138. KeyBuildDir = 'BuildDir';
  139. KeyCompilerConfigDir = 'CompilerConfigDir';
  140. KeyCompilerConfig = 'CompilerConfig';
  141. KeyFPMakeCompilerConfig = 'FPMakeCompilerConfig';
  142. KeyDownloader = 'Downloader';
  143. // Compiler dependent config
  144. KeyGlobalInstallDir = 'GlobalInstallDir';
  145. KeyLocalInstallDir = 'LocalInstallDir';
  146. KeyCompiler = 'Compiler' ;
  147. KeyCompilerOS = 'OS';
  148. KeyCompilerCPU = 'CPU';
  149. KeyCompilerVersion = 'Version';
  150. {*****************************************************************************
  151. TGlobalOptions
  152. *****************************************************************************}
  153. constructor TGlobalOptions.Create;
  154. begin
  155. FOptionParser := TTemplateParser.Create;
  156. FOptionParser.Values['AppConfigDir'] := GetAppConfigDir(false);
  157. FOptionParser.Values['UserDir'] := GetUserDir;
  158. InitGlobalDefaults;
  159. end;
  160. destructor TGlobalOptions.Destroy;
  161. begin
  162. FOptionParser.Free;
  163. inherited Destroy;
  164. end;
  165. function TGlobalOptions.GetOptString(Index: integer): String;
  166. begin
  167. Case Index of
  168. 0 : Result:=FRemoteMirrorsURL;
  169. 2 : Result:=FRemoteRepository;
  170. 3 : Result:=FOptionParser.ParseString(FLocalRepository);
  171. 4 : Result:=FOptionParser.ParseString(FBuildDir);
  172. 5 : Result:=FOptionParser.ParseString(FArchivesDir);
  173. 6 : Result:=FOptionParser.ParseString(FCompilerConfigDir);
  174. 8 : Result:=FDefaultCompilerConfig;
  175. 9 : Result:=FFPMakeCompilerConfig;
  176. 10 : Result:=FDownloader;
  177. else
  178. Error('Unknown option');
  179. end;
  180. end;
  181. procedure TGlobalOptions.SetOptString(Index: integer; const AValue: String);
  182. begin
  183. If AValue=GetOptString(Index) then
  184. Exit;
  185. Case Index of
  186. 1 : FRemoteMirrorsURL:=AValue;
  187. 2 : FRemoteRepository:=AValue;
  188. 3 : begin
  189. FLocalRepository:=AValue;
  190. UpdateLocalRepositoryOption;
  191. end;
  192. 4 : FBuildDir:=FixPath(AValue);
  193. 5 : FArchivesDir:=FixPath(AValue);
  194. 6 : FCompilerConfigDir:=FixPath(AValue);
  195. 8 : FDefaultCompilerConfig:=AValue;
  196. 9 : FFPMakeCompilerConfig:=AValue;
  197. 10 : FDownloader:=AValue;
  198. else
  199. Error('Unknown option');
  200. end;
  201. FDirty:=True;
  202. end;
  203. procedure TGlobalOptions.UpdateLocalRepositoryOption;
  204. begin
  205. FOptionParser.Values['LocalRepository'] := LocalRepository;
  206. end;
  207. function TGlobalOptions.LocalPackagesFile:string;
  208. begin
  209. Result:=LocalRepository+PackagesFileName;
  210. end;
  211. function TGlobalOptions.LocalMirrorsFile:string;
  212. begin
  213. Result:=LocalRepository+MirrorsFileName;
  214. end;
  215. function TGlobalOptions.LocalVersionsFile(const ACompilerConfig:String):string;
  216. begin
  217. Result:=LocalRepository+Format(VersionsFileName,[ACompilerConfig]);
  218. end;
  219. Procedure TGlobalOptions.InitGlobalDefaults;
  220. begin
  221. FConfigVersion:=CurrentConfigVersion;
  222. // Retrieve Local fppkg directory
  223. {$ifdef unix}
  224. if IsSuperUser then
  225. begin
  226. if DirectoryExists('/usr/local/lib/fpc') then
  227. FLocalRepository:='/usr/local/lib/fpc/fppkg/'
  228. else
  229. FLocalRepository:='/usr/lib/fpc/fppkg/';
  230. end
  231. else
  232. FLocalRepository:='{UserDir}.fppkg/';
  233. {$else}
  234. FLocalRepository:=IncludeTrailingPathDelimiter(GetAppConfigDir(IsSuperUser));
  235. {$endif}
  236. UpdateLocalRepositoryOption;
  237. // Directories
  238. FBuildDir:='{LocalRepository}build'+PathDelim;
  239. FArchivesDir:='{LocalRepository}archives'+PathDelim;
  240. FCompilerConfigDir:='{LocalRepository}config'+PathDelim;
  241. // Remote
  242. FRemoteMirrorsURL:=DefaultMirrorsURL;
  243. FRemoteRepository:=DefaultRemoteRepository;
  244. // Other config
  245. FDefaultCompilerConfig:='default';
  246. FFPMakeCompilerConfig:='default';
  247. // Downloader
  248. {$if defined(unix) or defined(windows)}
  249. FDownloader:='lnet';
  250. {$else}
  251. FDownloader:='base';
  252. {$endif}
  253. // Parameter defaults
  254. FCompilerConfig:=FDefaultCompilerConfig;
  255. FInstallGlobal:=False;
  256. FRecoveryMode:=False;
  257. FAllowBroken:=False;
  258. end;
  259. procedure TGlobalOptions.LoadGlobalFromFile(const AFileName: String);
  260. Var
  261. Ini : TMemIniFile;
  262. begin
  263. try
  264. Ini:=TMemIniFile.Create(AFileName);
  265. With Ini do
  266. begin
  267. FConfigVersion:=ReadInteger(SDefaults,KeyConfigVersion,0);
  268. if (FConfigVersion<>CurrentConfigVersion) then
  269. begin
  270. Log(vlDebug,SLogUpgradingConfig,[AFileName]);
  271. FDirty:=true;
  272. if FConfigVersion<1 then
  273. begin
  274. FRemoteRepository:='auto';
  275. end;
  276. if FConfigVersion<3 then
  277. begin
  278. // Directories
  279. FBuildDir:=FLocalRepository+'build'+PathDelim;
  280. FArchivesDir:=FLocalRepository+'archives'+PathDelim;
  281. FCompilerConfigDir:=FLocalRepository+'config'+PathDelim;
  282. end;
  283. if (FConfigVersion>CurrentConfigVersion) then
  284. Error(SErrUnsupportedConfigVersion,[AFileName]);
  285. end;
  286. FRemoteMirrorsURL:=ReadString(SDefaults,KeyRemoteMirrorsURL,FRemoteMirrorsURL);
  287. FRemoteRepository:=ReadString(SDefaults,KeyRemoteRepository,FRemoteRepository);
  288. FLocalRepository:=ReadString(SDefaults,KeyLocalRepository,FLocalRepository);
  289. UpdateLocalRepositoryOption;
  290. FBuildDir:=FixPath(ReadString(SDefaults,KeyBuildDir,FBuildDir));
  291. FArchivesDir:=FixPath(ReadString(SDefaults,KeyArchivesDir,FArchivesDir));
  292. FCompilerConfigDir:=FixPath(ReadString(SDefaults,KeyCompilerConfigDir,FCompilerConfigDir));
  293. FDefaultCompilerConfig:=ReadString(SDefaults,KeyCompilerConfig,FDefaultCompilerConfig);
  294. FFPMakeCompilerConfig:=ReadString(SDefaults,KeyFPMakeCompilerConfig,FFPMakeCompilerConfig);
  295. FDownloader:=ReadString(SDefaults,KeyDownloader,FDownloader);
  296. end;
  297. finally
  298. Ini.Free;
  299. end;
  300. end;
  301. procedure TGlobalOptions.SaveGlobalToFile(const AFileName: String);
  302. Var
  303. Ini : TIniFile;
  304. begin
  305. if FileExists(AFileName) then
  306. BackupFile(AFileName);
  307. try
  308. Ini:=TIniFile.Create(AFileName);
  309. With Ini do
  310. begin
  311. WriteInteger(SDefaults,KeyConfigVersion,CurrentConfigVersion);
  312. WriteString(SDefaults,KeyLocalRepository,FLocalRepository);
  313. WriteString(SDefaults,KeyBuildDir,FBuildDir);
  314. WriteString(SDefaults,KeyArchivesDir,FArchivesDir);
  315. WriteString(SDefaults,KeyCompilerConfigDir,FCompilerConfigDir);
  316. WriteString(SDefaults,KeyRemoteMirrorsURL,FRemoteMirrorsURL);
  317. WriteString(SDefaults,KeyRemoteRepository,FRemoteRepository);
  318. WriteString(SDefaults,KeyCompilerConfig,FDefaultCompilerConfig);
  319. WriteString(SDefaults,KeyFPMakeCompilerConfig,FFPMakeCompilerConfig);
  320. WriteString(SDefaults,KeyDownloader,FDownloader);
  321. FDirty:=False;
  322. end;
  323. Ini.UpdateFile;
  324. finally
  325. Ini.Free;
  326. end;
  327. end;
  328. procedure TGlobalOptions.LogValues;
  329. begin
  330. Log(vlDebug,SLogGlobalCfgHeader);
  331. Log(vlDebug,SLogGlobalCfgRemoteMirrorsURL,[FRemoteMirrorsURL]);
  332. Log(vlDebug,SLogGlobalCfgRemoteRepository,[FRemoteRepository]);
  333. Log(vlDebug,SLogGlobalCfgLocalRepository,[LocalRepository]);
  334. Log(vlDebug,SLogGlobalCfgBuildDir,[BuildDir]);
  335. Log(vlDebug,SLogGlobalCfgArchivesDir,[ArchivesDir]);
  336. Log(vlDebug,SLogGlobalCfgCompilerConfigDir,[CompilerConfigDir]);
  337. Log(vlDebug,SLogGlobalCfgDefaultCompilerConfig,[FDefaultCompilerConfig]);
  338. Log(vlDebug,SLogGlobalCfgFPMakeCompilerConfig,[FFPMakeCompilerConfig]);
  339. Log(vlDebug,SLogGlobalCfgDownloader,[FDownloader]);
  340. end;
  341. {*****************************************************************************
  342. TCompilerOptions
  343. *****************************************************************************}
  344. constructor TCompilerOptions.Create;
  345. begin
  346. FOptionParser := TTemplateParser.Create;
  347. FOptionParser.Values['AppConfigDir'] := GetAppConfigDir(false);
  348. FOptionParser.Values['UserDir'] := GetUserDir;
  349. end;
  350. destructor TCompilerOptions.Destroy;
  351. begin
  352. FOptionParser.Free;
  353. inherited Destroy;
  354. end;
  355. function TCompilerOptions.GetOptString(Index: integer): String;
  356. begin
  357. Case Index of
  358. 1 : Result:=FCompiler;
  359. 2 : Result:=MakeTargetString(CompilerCPU,CompilerOS);
  360. 3 : Result:=FCompilerVersion;
  361. 4 : Result:=FOptionParser.ParseString(FGlobalInstallDir);
  362. 5 : Result:=FOptionParser.ParseString(FLocalInstallDir);
  363. else
  364. Error('Unknown option');
  365. end;
  366. end;
  367. procedure TCompilerOptions.SetOptString(Index: integer; const AValue: String);
  368. begin
  369. If AValue=GetOptString(Index) then
  370. Exit;
  371. Case Index of
  372. 1 : FCompiler:=AValue;
  373. 2 : StringToCPUOS(AValue,FCompilerCPU,FCompilerOS);
  374. 3 : FCompilerVersion:=AValue;
  375. 4 : FGlobalInstallDir:=FixPath(AValue);
  376. 5 : FLocalInstallDir:=FixPath(AValue);
  377. else
  378. Error('Unknown option');
  379. end;
  380. FDirty:=True;
  381. end;
  382. procedure TCompilerOptions.SetCompilerCPU(const AValue: TCPU);
  383. begin
  384. if FCompilerCPU=AValue then
  385. exit;
  386. FCompilerCPU:=AValue;
  387. FDirty:=True;
  388. end;
  389. procedure TCompilerOptions.UpdateLocalRepositoryOption;
  390. begin
  391. FOptionParser.Values['LocalRepository'] := GlobalOptions.LocalRepository;
  392. end;
  393. procedure TCompilerOptions.SetCompilerOS(const AValue: TOS);
  394. begin
  395. if FCompilerOS=AValue then
  396. exit;
  397. FCompilerOS:=AValue;
  398. FDirty:=True;
  399. end;
  400. function TCompilerOptions.LocalUnitDir:string;
  401. begin
  402. if LocalInstallDir<>'' then
  403. result:=LocalInstallDir+'units'+PathDelim+CompilerTarget+PathDelim
  404. else
  405. result:='';
  406. end;
  407. function TCompilerOptions.GlobalUnitDir:string;
  408. begin
  409. if GlobalInstallDir<>'' then
  410. result:=GlobalInstallDir+'units'+PathDelim+CompilerTarget+PathDelim
  411. else
  412. result:='';
  413. end;
  414. procedure TCompilerOptions.InitCompilerDefaults;
  415. var
  416. infoSL : TStringList;
  417. begin
  418. FConfigVersion:=CurrentConfigVersion;
  419. FCompiler:=ExeSearch('fpc'+ExeExt,GetEnvironmentVariable('PATH'));
  420. if FCompiler='' then
  421. Raise EPackagerError.Create(SErrMissingFPC);
  422. // Detect compiler version/target from -i option
  423. infosl:=TStringList.Create;
  424. infosl.Delimiter:=' ';
  425. infosl.DelimitedText:=GetCompilerInfo(FCompiler,'-iVTPTO');
  426. if infosl.Count<>3 then
  427. Raise EPackagerError.Create(SErrInvalidFPCInfo);
  428. FCompilerVersion:=infosl[0];
  429. FCompilerCPU:=StringToCPU(infosl[1]);
  430. FCompilerOS:=StringToOS(infosl[2]);
  431. // Temporary hack to workaround bug in fpc.exe that doesn't support spaces
  432. // We retrieve the real binary
  433. if FCompilerVersion='2.2.0' then
  434. FCompiler:=GetCompilerInfo(FCompiler,'-PB');
  435. Log(vlDebug,SLogDetectedCompiler,[FCompiler,FCompilerVersion,MakeTargetString(FCompilerCPU,FCompilerOS)]);
  436. // Use the same algorithm as the compiler, see options.pas
  437. {$ifdef Unix}
  438. FGlobalInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
  439. if FGlobalInstallDir='' then
  440. begin
  441. FGlobalInstallDir:='/usr/local/lib/fpc/'+FCompilerVersion+'/';
  442. if not DirectoryExists(FGlobalInstallDir) and
  443. DirectoryExists('/usr/lib/fpc/'+FCompilerVersion) then
  444. FGlobalInstallDir:='/usr/lib/fpc/'+FCompilerVersion+'/';
  445. end;
  446. {$else unix}
  447. FGlobalInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
  448. if FGlobalInstallDir='' then
  449. begin
  450. FGlobalInstallDir:=ExtractFilePath(FCompiler)+'../';
  451. if not(DirectoryExists(FGlobalInstallDir+'/units')) and
  452. not(DirectoryExists(FGlobalInstallDir+'/rtl')) then
  453. FGlobalInstallDir:=FGlobalInstallDir+'../';
  454. end;
  455. FGlobalInstallDir:=ExpandFileName(FGlobalInstallDir);
  456. {$endif unix}
  457. Log(vlDebug,SLogDetectedFPCDIR,['global',FGlobalInstallDir]);
  458. // User writable install directory
  459. if not IsSuperUser then
  460. begin
  461. FLocalInstallDir:= '{LocalRepository}lib'+ PathDelim + FCompilerVersion+PathDelim;
  462. Log(vlDebug,SLogDetectedFPCDIR,['local',FLocalInstallDir]);
  463. end;
  464. end;
  465. procedure TCompilerOptions.LoadCompilerFromFile(const AFileName: String);
  466. Var
  467. Ini : TMemIniFile;
  468. begin
  469. try
  470. Ini:=TMemIniFile.Create(AFileName);
  471. With Ini do
  472. begin
  473. FConfigVersion:=ReadInteger(SDefaults,KeyConfigVersion,0);
  474. if (FConfigVersion<>CurrentConfigVersion) then
  475. begin
  476. Log(vlDebug,SLogUpgradingConfig,[AFileName]);
  477. FDirty:=true;
  478. if (FConfigVersion>CurrentConfigVersion) then
  479. Error(SErrUnsupportedConfigVersion,[AFileName]);
  480. end;
  481. FGlobalInstallDir:=FixPath(ReadString(SDefaults,KeyGlobalInstallDir,FGlobalInstallDir));
  482. FLocalInstallDir:=FixPath(ReadString(SDefaults,KeyLocalInstallDir,FLocalInstallDir));
  483. FCompiler:=ReadString(SDefaults,KeyCompiler,FCompiler);
  484. FCompilerOS:=StringToOS(ReadString(SDefaults,KeyCompilerOS,OSToString(CompilerOS)));
  485. FCompilerCPU:=StringToCPU(ReadString(SDefaults,KeyCompilerCPU,CPUtoString(CompilerCPU)));
  486. FCompilerVersion:=ReadString(SDefaults,KeyCompilerVersion,FCompilerVersion);
  487. end;
  488. finally
  489. Ini.Free;
  490. end;
  491. end;
  492. procedure TCompilerOptions.SaveCompilerToFile(const AFileName: String);
  493. Var
  494. Ini : TIniFile;
  495. begin
  496. if FileExists(AFileName) then
  497. BackupFile(AFileName);
  498. try
  499. Ini:=TIniFile.Create(AFileName);
  500. With Ini do
  501. begin
  502. WriteInteger(SDefaults,KeyConfigVersion,CurrentConfigVersion);
  503. WriteString(SDefaults,KeyGlobalInstallDir,FGlobalInstallDir);
  504. WriteString(SDefaults,KeyLocalInstallDir,FLocalInstallDir);
  505. WriteString(SDefaults,KeyCompiler,FCompiler);
  506. WriteString(SDefaults,KeyCompilerOS,OSToString(CompilerOS));
  507. WriteString(SDefaults,KeyCompilerCPU,CPUtoString(CompilerCPU));
  508. WriteString(SDefaults,KeyCompilerVersion,FCompilerVersion);
  509. FDirty:=False;
  510. end;
  511. Ini.UpdateFile;
  512. finally
  513. Ini.Free;
  514. end;
  515. end;
  516. procedure TCompilerOptions.LogValues(const ACfgName:string);
  517. begin
  518. Log(vlDebug,SLogCompilerCfgHeader,[ACfgName]);
  519. Log(vlDebug,SLogCompilerCfgCompiler,[FCompiler]);
  520. Log(vlDebug,SLogCompilerCfgTarget,[MakeTargetString(CompilerCPU,CompilerOS)]);
  521. Log(vlDebug,SLogCompilerCfgVersion,[FCompilerVersion]);
  522. Log(vlDebug,SLogCompilerCfgGlobalInstallDir,[GlobalInstallDir]);
  523. Log(vlDebug,SLogCompilerCfgLocalInstallDir,[LocalInstallDir]);
  524. end;
  525. initialization
  526. GlobalOptions:=TGlobalOptions.Create;
  527. CompilerOptions:=TCompilerOptions.Create;
  528. FPMakeCompilerOptions:=TCompilerOptions.Create;
  529. finalization
  530. FreeAndNil(GlobalOptions);
  531. FreeAndNil(CompilerOptions);
  532. FreeAndNil(FPMakeCompilerOptions);
  533. end.