pkgoptions.pp 19 KB

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