fullfpcinstallationtests.pas 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. unit FullFPCInstallationTests;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes,
  6. SysUtils,
  7. fpcunit,
  8. IniFiles,
  9. testdecorator,
  10. testregistry,
  11. CustApp,
  12. process,
  13. fpmkunit,
  14. pkgFppkg,
  15. fprepos;
  16. type
  17. { TFullFPCInstallationTests }
  18. TFullFPCInstallationTests = class(TTestCase)
  19. protected
  20. procedure SetUp; override;
  21. procedure TearDown; override;
  22. published
  23. procedure TestListPackages;
  24. procedure IntTestListPackages;
  25. procedure IntTestMergeGlobalOptions;
  26. procedure TestPackageA;
  27. procedure TestLooseFPMFile;
  28. procedure TestMissingSource;
  29. procedure TestBuildWithInstalledDependency;
  30. procedure TestFakePackageDir;
  31. procedure TestSourceDependency;
  32. procedure TestTransmitOptions;
  33. procedure TestPackageVariantPackage;
  34. procedure TestFPMakeCommandLikePackageVariants;
  35. procedure TestFpmakePluginDependencies;
  36. procedure TestCleanupOfTemporaryBuildpath;
  37. procedure TestDefaultInstallLocation;
  38. procedure TestSourceRepositoryInstallLocation;
  39. procedure TestConfiguredInstallLocation;
  40. end;
  41. { TFullFPCInstallationSetup }
  42. TFullFPCInstallationSetup = class(TTestSetup)
  43. private
  44. class var
  45. FFPCSourcePath: string;
  46. FTestPath: string;
  47. FPackagesPath: string;
  48. FStartCompiler: string;
  49. FTargetCPU: string;
  50. FTargetOS: string;
  51. FCompilerVersion: string;
  52. protected
  53. procedure OneTimeSetup; override;
  54. procedure OneTimeTearDown; override;
  55. public
  56. class function GetCurrentTestPath: string;
  57. class function GetTemplatePath: string;
  58. class function GetTestPath: string;
  59. class function GetBasePackagesPath: string;
  60. class function GetSpecificPackagesPath: string;
  61. class function GetCurrentTestBasePackagesPath: string;
  62. class function GetTestBinPath: string;
  63. class function GetTargetString: string;
  64. class function GetCompilerVersion: string;
  65. class function SyncPackageIntoCurrentTest(APackageName: string; SpecificPackageDir: string = ''): string;
  66. end;
  67. implementation
  68. function RunTestCommandIndir(const Curdir:string; const Exename:string; const Commands:array of string; TaskDescription: string; ExpectedExitStatus: Integer = 0):string;
  69. var
  70. CommandOutput: string;
  71. i: integer;
  72. CommandLine: string;
  73. ExitStatus: Integer;
  74. begin
  75. if RunCommandInDir(Curdir, Exename, Commands, CommandOutput, ExitStatus, [poStderrToOutPut]) <> 0 then
  76. raise Exception.CreateFmt('Failed to run ''%s''', [exename]);
  77. if ExitStatus<>ExpectedExitStatus then
  78. begin
  79. for i := 0 to length(Commands) -1 do
  80. begin
  81. CommandLine := CommandLine + ' ' + Commands[i];
  82. end;
  83. raise Exception.CreateFmt('Failed to %s.' +sLineBreak+ 'Current directory: ' +Curdir+ sLineBreak + 'command line: ' + Exename + CommandLine + sLineBreak + ' Output: ' + sLineBreak + CommandOutput, [TaskDescription]);
  84. end;
  85. result := CommandOutput;
  86. end;
  87. function RunFppkgIndir(const Curdir:string; Commands: array of string; TaskDescription: string; ExpectedExitStatus: Integer = 0):string;
  88. var
  89. i: Integer;
  90. StrArr: array of string;
  91. begin
  92. i := length(Commands);
  93. SetLength(StrArr, i + 2);
  94. StrArr[i] := '-C';
  95. StrArr[i+1] := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'etc','fppkg.cfg']);
  96. for i := 0 to length(Commands) -1 do
  97. StrArr[i] := Commands[i];
  98. Result := RunTestCommandIndir(Curdir, TFullFPCInstallationSetup.GetTestBinPath+'fppkg', StrArr, TaskDescription, ExpectedExitStatus);
  99. end;
  100. function RunFPMakeIndir(const Curdir:string; Commands: array of string; TaskDescription: string; ExpectedExitStatus: Integer = 0):string;
  101. var
  102. i: Integer;
  103. StrArr: array of string;
  104. CompilerStr, FpcSearchpath, PackageSearchPath: string;
  105. begin
  106. // Compile the package in the ProcVersion=VersionB variant
  107. CompilerStr := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'bin', 'fpc']);
  108. FpcSearchpath := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion]);
  109. PackageSearchpath := TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath;
  110. i := length(Commands);
  111. SetLength(StrArr, i + 6);
  112. StrArr[i] := '--nofpccfg';
  113. StrArr[i+1] := '--compiler='+CompilerStr;
  114. StrArr[i+2] := '--searchpath='+FpcSearchpath;
  115. StrArr[i+3] := '--searchpath='+PackageSearchpath;
  116. StrArr[i+4] := '--prefix='+TFullFPCInstallationSetup.GetCurrentTestPath + 'user';
  117. StrArr[i+5] := '--baseinstalldir=' + ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion]);
  118. for i := 0 to length(Commands) -1 do
  119. StrArr[i] := Commands[i];
  120. Result := RunTestCommandIndir(Curdir, ConcatPaths([Curdir, 'fpmake']), StrArr, TaskDescription, ExpectedExitStatus);
  121. end;
  122. function DeleteDirectory(const DirectoryName: string; OnlyChildren: boolean): boolean;
  123. const
  124. //Don't follow symlinks on *nix, just delete them
  125. DeleteMask = faAnyFile {$ifdef unix} or faSymLink{%H-} {$endif unix};
  126. var
  127. FileInfo: TSearchRec;
  128. CurSrcDir: String;
  129. CurFilename: String;
  130. begin
  131. Result:=false;
  132. CurSrcDir:=IncludeTrailingPathDelimiter(DirectoryName);
  133. if FindFirst(CurSrcDir+AllFilesMask,DeleteMask,FileInfo)=0 then begin
  134. repeat
  135. // check if special file
  136. if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
  137. continue;
  138. CurFilename:=CurSrcDir+FileInfo.Name;
  139. if ((FileInfo.Attr and faDirectory)>0)
  140. {$ifdef unix} and ((FileInfo.Attr and faSymLink{%H-})=0) {$endif unix} then begin
  141. if not DeleteDirectory(CurFilename,false) then exit;
  142. end else begin
  143. if not DeleteFile(CurFilename) then exit;
  144. end;
  145. until FindNext(FileInfo)<>0;
  146. end;
  147. FindClose(FileInfo);
  148. if (not OnlyChildren) and (not RemoveDir(CurSrcDir)) then exit;
  149. Result:=true;
  150. end;
  151. { TFullFPCInstallationSetup }
  152. procedure TFullFPCInstallationSetup.OneTimeSetup;
  153. var
  154. TemplatePath: string;
  155. LocalBasePath: string;
  156. MakeParams: array of string;
  157. begin
  158. FFPCSourcePath := CustomApplication.GetOptionValue('f','fpcsrcpath');
  159. if FFPCSourcePath<>'' then
  160. FFPCSourcePath := ExpandFileName(FFPCSourcePath);
  161. FStartCompiler := CustomApplication.GetOptionValue('s','startcompiler');
  162. FTestPath := CustomApplication.GetOptionValue('t','testpath');
  163. if FTestPath='' then
  164. FTestPath := IncludeTrailingPathDelimiter(ConcatPaths([ExtractFilePath(ParamStr(0)),'testroot']))
  165. else
  166. FTestPath := ExpandFileName(FTestPath);
  167. FPackagesPath := CustomApplication.GetOptionValue('p','packagespath');
  168. if FPackagesPath='' then
  169. FPackagesPath := IncludeTrailingPathDelimiter(ConcatPaths([ExtractFilePath(ParamStr(0)),'packages']))
  170. else
  171. FPackagesPath := ExpandFileName(FPackagesPath);
  172. if not CustomApplication.HasOption('T', 'skipbuildtemplate') then
  173. begin
  174. TemplatePath := GetTemplatePath;
  175. if DirectoryExists(GetTestPath) and not DeleteDirectory(GetTestPath, False) then
  176. raise Exception.CreateFmt('Failed to remove source-path ''%s''', [GetTestPath]);
  177. ForceDirectories(GetTemplatePath);
  178. SetLength(MakeParams, 2);
  179. MakeParams[0] := 'clean';
  180. MakeParams[1] := 'all';
  181. if FStartCompiler<>'' then
  182. begin
  183. SetLength(MakeParams, length(MakeParams)+1);
  184. MakeParams[High(MakeParams)] := 'PP='+FStartCompiler;
  185. end;
  186. RunTestCommandIndir(FFPCSourcePath, 'make', MakeParams, 'compile FPC');
  187. MakeParams[0] := 'install';
  188. MakeParams[1] := 'PREFIX='+GetTemplatePath;
  189. RunTestCommandIndir(FFPCSourcePath, 'make', MakeParams, 'install FPC');
  190. LocalBasePath := IncludeTrailingPathDelimiter(ConcatPaths([GetTemplatePath, 'user','lib','fpc']));
  191. FCompilerVersion := Trim(RunTestCommandIndir(GetTemplatePath, GetTemplatePath+'bin'+PathDelim+'fpc', ['-iV'], 'get compiler-version'));
  192. ForceDirectories(LocalBasePath+FCompilerVersion);
  193. SetLength(MakeParams, 8);
  194. MakeParams[0] := '-o';
  195. MakeParams[1] := GetTemplatePath+PathDelim+'fpc.cfg';
  196. MakeParams[2] := '-d';
  197. MakeParams[3] := 'basepath='+ConcatPaths([GetCurrentTestPath, 'lib','fpc','$fpcversion']);
  198. MakeParams[4] := '-d';
  199. MakeParams[5] := 'sharepath='+ConcatPaths([GetCurrentTestPath, 'share','fpc','$fpcversion']);
  200. MakeParams[6] := '-d';
  201. MakeParams[7] := 'localbasepath='+LocalBasePath+'$fpcversion';
  202. RunTestCommandIndir(ConcatPaths([GetTemplatePath,'bin']), 'fpcmkcfg', MakeParams, 'create fpc.cfg');
  203. SetLength(MakeParams, 12);
  204. MakeParams[1] := ConcatPaths([GetTemplatePath, 'etc', 'fppkg.cfg']);
  205. MakeParams[8] := '-3';
  206. MakeParams[9] := '-p';
  207. MakeParams[3] := 'GlobalPath='+ConcatPaths([GetCurrentTestPath, 'lib', 'fpc']);
  208. MakeParams[5] := 'GlobalPrefix='+GetCurrentTestPath;
  209. MakeParams[10] := '-d';
  210. MakeParams[11] := 'LocalRepository='+ConcatPaths([GetCurrentTestPath, 'user'])+PathDelim;
  211. RunTestCommandIndir(ConcatPaths([GetTemplatePath,'bin']), 'fpcmkcfg', MakeParams, 'create fppkg.cfg');
  212. SetLength(MakeParams, 12);
  213. MakeParams[1] := ConcatPaths([TemplatePath, 'user', 'config', 'default']);
  214. MakeParams[8] := '-4';
  215. MakeParams[9] := '-p';
  216. MakeParams[3] := 'GlobalPath='+ConcatPaths([GetCurrentTestPath, 'lib','fpc']);
  217. MakeParams[5] := 'fpcbin='+ConcatPaths([GetCurrentTestPath, 'bin','fpc']);
  218. MakeParams[10] := '-d';
  219. MakeParams[11] := 'LocalRepository='+ConcatPaths([GetCurrentTestPath, 'user'])+PathDelim;
  220. RunTestCommandIndir(ConcatPaths([TemplatePath,'bin']), 'fpcmkcfg', MakeParams, 'create default fppkg compiler file');
  221. ForceDirectories(ConcatPaths([TemplatePath, 'user','config','conf.d']));
  222. end
  223. else
  224. begin
  225. FCompilerVersion := Trim(RunTestCommandIndir(GetTemplatePath, GetTemplatePath+'bin'+PathDelim+'fpc', ['-iV'], 'get compiler-version'));
  226. end;
  227. FTargetOS := Trim(RunTestCommandIndir(GetTemplatePath, GetTemplatePath+'bin'+PathDelim+'fpc', ['-iTO'], 'get target-OS'));
  228. FTargetCPU := Trim(RunTestCommandIndir(GetTemplatePath, GetTemplatePath+'bin'+PathDelim+'fpc', ['-iTP'], 'get target-CPU'));
  229. end;
  230. procedure TFullFPCInstallationSetup.OneTimeTearDown;
  231. begin
  232. end;
  233. class function TFullFPCInstallationSetup.GetCurrentTestPath: string;
  234. begin
  235. Result := IncludeTrailingPathDelimiter(ConcatPaths([FTestPath,'currenttest']));
  236. end;
  237. class function TFullFPCInstallationSetup.GetTemplatePath: string;
  238. begin
  239. Result := IncludeTrailingPathDelimiter(ConcatPaths([FTestPath,'templates','fullfpc']));
  240. end;
  241. class function TFullFPCInstallationSetup.GetTestPath: string;
  242. begin
  243. Result := FTestPath;
  244. end;
  245. class function TFullFPCInstallationSetup.GetBasePackagesPath: string;
  246. begin
  247. Result := IncludeTrailingPathDelimiter(ConcatPaths([FPackagesPath, 'base']));
  248. end;
  249. class function TFullFPCInstallationSetup.GetSpecificPackagesPath: string;
  250. begin
  251. Result := IncludeTrailingPathDelimiter(ConcatPaths([FPackagesPath, 'specific']));
  252. end;
  253. class function TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath: string;
  254. begin
  255. Result := IncludeTrailingPathDelimiter(ConcatPaths([GetCurrentTestPath, 'packages']));
  256. end;
  257. class function TFullFPCInstallationSetup.GetTestBinPath: string;
  258. begin
  259. Result := IncludeTrailingPathDelimiter(ConcatPaths([GetCurrentTestPath,'bin']));
  260. end;
  261. class function TFullFPCInstallationSetup.GetTargetString: string;
  262. begin
  263. Result := FTargetCPU + '-' + FTargetOS;
  264. end;
  265. class function TFullFPCInstallationSetup.GetCompilerVersion: string;
  266. begin
  267. Result := FCompilerVersion;
  268. end;
  269. class function TFullFPCInstallationSetup.SyncPackageIntoCurrentTest(APackageName: string; SpecificPackageDir: string): string;
  270. var
  271. PackagePath: string;
  272. begin
  273. ForceDirectories(ConcatPaths([TFullFPCInstallationSetup.GetTestPath, 'currenttest', 'packages']));
  274. if SpecificPackageDir='' then
  275. PackagePath := TFullFPCInstallationSetup.GetBasePackagesPath+APackageName+PathDelim
  276. else
  277. PackagePath := ConcatPaths([TFullFPCInstallationSetup.GetSpecificPackagesPath, SpecificPackageDir, APackageName])+PathDelim;
  278. RunTestCommandIndir(TFullFPCInstallationSetup.GetTestPath, 'rsync', ['-rtvu', '--delete', PackagePath, TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath+APackageName], 'sync template');
  279. end;
  280. procedure TFullFPCInstallationTests.SetUp;
  281. begin
  282. RunTestCommandIndir(TFullFPCInstallationSetup.GetTestPath, 'rsync', ['-rtv', '--delete', 'templates/fullfpc/', 'currenttest/'], 'sync template');
  283. end;
  284. procedure TFullFPCInstallationTests.TearDown;
  285. begin
  286. end;
  287. procedure TFullFPCInstallationTests.TestFpmakePluginDependencies;
  288. begin
  289. // A fpmake-plugin could have it's own dependencies. These dependencies have
  290. // to be installed, and it's path must be used to compile the fpmake-executable.
  291. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packageusingplugin', 'plugindependencies');
  292. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('plugindependency', 'plugindependencies');
  293. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('pluginpackage', 'plugindependencies');
  294. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'plugindependency', ['install'], 'Install dependency');
  295. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'pluginpackage', ['install'], 'Install plugin');
  296. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageusingplugin', ['install'], 'Install package that depends on plugin');
  297. end;
  298. procedure TFullFPCInstallationTests.TestCleanupOfTemporaryBuildpath;
  299. var
  300. SR: TSearchRec;
  301. begin
  302. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('brokenpackage');
  303. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'brokenpackage', ['build'], 'Attempt to build brokenpackage', 1);
  304. if FindFirst(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'brokenpackage'+PathDelim+AllFilesMask, faAnyFile, sr) = 0 then
  305. begin
  306. repeat
  307. Check(not ((SR.Name<>'.') and (SR.Name<>'..') and (SR.Name<>'fpmake.pp') and (SR.Name<>'src')), 'Check for garbage-files after build ('+SR.Name+')');
  308. until FindNext(SR) <> 0;
  309. end;
  310. end;
  311. procedure TFullFPCInstallationTests.TestDefaultInstallLocation;
  312. var
  313. FPPKGFilename: String;
  314. ConfigFile: TIniFile;
  315. begin
  316. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagea');
  317. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packageb');
  318. // Remove the installrepository setting from fppkg.cfg
  319. FPPKGFilename := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'etc', 'fppkg.cfg']);
  320. ConfigFile := TIniFile.Create(FPPKGFilename);
  321. try
  322. ConfigFile.DeleteKey('Defaults', 'InstallRepository');
  323. ConfigFile.UpdateFile;
  324. finally
  325. ConfigFile.Free;
  326. end;
  327. // Should install into user
  328. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['install'], 'Install package A');
  329. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.ppu'])), 'PackageAUnitA.ppu not found');
  330. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.o'])), 'PackageAUnitA.o not found');
  331. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'fpmkinst',TFullFPCInstallationSetup.GetTargetString,'packagea.fpm'])), 'packagea.fpm not found');
  332. // Command-line should override default, so install in fpc
  333. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageb', ['install', '-i', 'fpc'], 'Install package B');
  334. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'PackageB','PackageBUnitB.ppu'])), 'PackageBUnitB.ppu not found');
  335. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'PackageB','PackageBUnitB.o'])), 'PackageBUnitB.o not found');
  336. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'fpmkinst',TFullFPCInstallationSetup.GetTargetString,'PackageB.fpm'])), 'PackageB.fpm not found');
  337. end;
  338. procedure TFullFPCInstallationTests.TestSourceRepositoryInstallLocation;
  339. var
  340. LocalPackagesRepoCfgFilename: String;
  341. ConfigFile: TIniFile;
  342. begin
  343. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagea');
  344. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packageb');
  345. // Remove the installrepository setting from fppkg.cfg
  346. LocalPackagesRepoCfgFilename := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'config', 'conf.d', 'lazaruspackagesrepo.conf']);
  347. ConfigFile := TIniFile.Create(LocalPackagesRepoCfgFilename);
  348. try
  349. ConfigFile.WriteString('UninstalledSourceRepository', 'Name', 'localpackages');
  350. ConfigFile.WriteString('UninstalledSourceRepository', 'Description', 'Local packages');
  351. ConfigFile.WriteString('UninstalledSourceRepository', 'Path', ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'packages']));
  352. ConfigFile.WriteString('UninstalledSourceRepository', 'InstallRepository', 'fpc');
  353. ConfigFile.UpdateFile;
  354. finally
  355. ConfigFile.Free;
  356. end;
  357. // Should install into fpc, as it is installed from the localpackages repository
  358. // which has fpc as install-repository
  359. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestPath, ['install', 'packagea'], 'Install package A from source repository');
  360. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.ppu'])), 'PackageAUnitA.ppu not found');
  361. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.o'])), 'PackageAUnitA.o not found');
  362. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'fpmkinst',TFullFPCInstallationSetup.GetTargetString,'packagea.fpm'])), 'packagea.fpm not found');
  363. // Command-line should override default, so install in user
  364. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestPath, ['install', '-i', 'user', 'packageb'], 'Install package B from user repository');
  365. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'PackageB','PackageBUnitB.ppu'])), 'PackageBUnitB.ppu not found');
  366. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'PackageB','PackageBUnitB.o'])), 'PackageBUnitB.o not found');
  367. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'fpmkinst',TFullFPCInstallationSetup.GetTargetString,'PackageB.fpm'])), 'PackageB.fpm not found');
  368. end;
  369. procedure TFullFPCInstallationTests.TestConfiguredInstallLocation;
  370. var
  371. FPPKGFilename: String;
  372. ConfigFile: TIniFile;
  373. begin
  374. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagea');
  375. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packageb');
  376. // Remove the installrepository setting from fppkg.cfg
  377. FPPKGFilename := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'etc', 'fppkg.cfg']);
  378. ConfigFile := TIniFile.Create(FPPKGFilename);
  379. try
  380. ConfigFile.WriteString('Defaults', 'InstallRepository', 'fpc');
  381. ConfigFile.UpdateFile;
  382. finally
  383. ConfigFile.Free;
  384. end;
  385. // Should install into fpc
  386. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['install'], 'Install package A');
  387. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.ppu'])), 'PackageAUnitA.ppu not found');
  388. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.o'])), 'PackageAUnitA.o not found');
  389. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'fpmkinst',TFullFPCInstallationSetup.GetTargetString,'packagea.fpm'])), 'packagea.fpm not found');
  390. // Command-line should override default, so install in user
  391. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageb', ['install', '-i', 'user'], 'Install package B');
  392. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'PackageB','PackageBUnitB.ppu'])), 'PackageBUnitB.ppu not found');
  393. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'PackageB','PackageBUnitB.o'])), 'PackageBUnitB.o not found');
  394. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'fpmkinst',TFullFPCInstallationSetup.GetTargetString,'PackageB.fpm'])), 'PackageB.fpm not found');
  395. end;
  396. procedure TFullFPCInstallationTests.TestListPackages;
  397. var
  398. s: String;
  399. begin
  400. s := RunFppkgIndir(TFullFPCInstallationSetup.GetTestPath, ['list'], 'fppkg list');
  401. Check(pos('rtl',s) > 0, 'Package rtl not found in fppkg-package list');
  402. end;
  403. procedure TFullFPCInstallationTests.IntTestListPackages;
  404. var
  405. FPpkg: TpkgFPpkg;
  406. RTLPackage: TFPPackage;
  407. begin
  408. FPpkg := TpkgFPpkg.Create(nil);
  409. try
  410. FPpkg.InitializeGlobalOptions(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'etc','fppkg.cfg']));
  411. FPpkg.Options.GlobalSection.Downloader := 'FPC';
  412. FPpkg.InitializeCompilerOptions;
  413. FPpkg.CompilerOptions.InitCompilerDefaults;
  414. FPpkg.FpmakeCompilerOptions.InitCompilerDefaults;
  415. FPpkg.CompilerOptions.CheckCompilerValues;
  416. FPpkg.FpmakeCompilerOptions.CheckCompilerValues;
  417. FPpkg.LoadLocalAvailableMirrors;
  418. FPpkg.ScanAvailablePackages;
  419. FPpkg.ScanPackages;
  420. RTLPackage := FPpkg.RepositoryByName('fpc').FindPackage('rtl');
  421. CheckNotNull(RTLPackage, 'RTL package not found');
  422. CheckEquals('3.1.1', RTLPackage.Version.AsString, 'RTL has not the same version as the compiler');
  423. finally
  424. FPpkg.Free;
  425. end;
  426. end;
  427. procedure TFullFPCInstallationTests.IntTestMergeGlobalOptions;
  428. var
  429. FPpkg: TpkgFPpkg;
  430. ExtraConfFile: Text;
  431. s: string;
  432. begin
  433. // When there are multiple global-sections, it's values should be merged.
  434. s := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'config', 'conf.d', 'extrasettings.conf']);
  435. AssignFile(ExtraConfFile, ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'config', 'conf.d', 'extrasettings.conf']));
  436. Rewrite(ExtraConfFile);
  437. WriteLn(ExtraConfFile, '[global]');
  438. WriteLn(ExtraConfFile, 'FPMakeOptions="-T 4"');
  439. CloseFile(ExtraConfFile);
  440. FPpkg := TpkgFPpkg.Create(nil);
  441. try
  442. FPpkg.InitializeGlobalOptions(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'etc','fppkg.cfg']));
  443. FPpkg.Options.GlobalSection.Downloader := 'FPC';
  444. FPpkg.InitializeCompilerOptions;
  445. FPpkg.CompilerOptions.InitCompilerDefaults;
  446. FPpkg.FpmakeCompilerOptions.InitCompilerDefaults;
  447. FPpkg.CompilerOptions.CheckCompilerValues;
  448. FPpkg.FpmakeCompilerOptions.CheckCompilerValues;
  449. FPpkg.LoadLocalAvailableMirrors;
  450. CheckEquals('user', FPpkg.Options.GlobalSection.InstallRepository, 'The InstallRepository does not match the value in the original configuration file');
  451. CheckEquals('"-T 4"', FPpkg.Options.GlobalSection.CustomFPMakeOptions, 'The custom FPMakeOptions do not match the value in the extra configuration file');
  452. finally
  453. FPpkg.Free;
  454. end;
  455. end;
  456. procedure TFullFPCInstallationTests.TestPackageA;
  457. var
  458. s: String;
  459. begin
  460. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagea');
  461. // Build and install package
  462. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['build'], 'build PackageA');
  463. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['install'], 'install PackageA');
  464. // Test installation
  465. s := RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestPath, ['list'], 'list packages');
  466. Check(pos('packagea', s) > 0, 'Just installed PackageA is not in package-list');
  467. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'user','lib','fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.ppu'])), 'PackageAUnitA.ppu not found');
  468. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'user','lib','fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.o'])), 'PackageAUnitA.o not found');
  469. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'user','lib','fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'fpmkinst',TFullFPCInstallationSetup.GetTargetString,'packagea.fpm'])), 'PackageAUnitA.fpm not found');
  470. // uninstall package
  471. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['uninstall'], 'install PackageA');
  472. // check uninstallation
  473. s := RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestPath, ['list'], 'list packages');
  474. Check(pos('packagea', s) = 0, 'Just de-installed PackageA is still in package-list');
  475. CheckFalse(DirectoryExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'user','lib','fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea'])), 'PackageAUnitA-directory found after uninstall');
  476. CheckFalse(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'user','lib','fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'fpmkinst',TFullFPCInstallationSetup.GetTargetString,'packagea.fpm'])), 'PackageAUnitA.fpm found after uninstall');
  477. end;
  478. procedure TFullFPCInstallationTests.TestLooseFPMFile;
  479. var
  480. F: Text;
  481. s: string;
  482. begin
  483. System.Assign(F, ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'fpmkinst', TFullFPCInstallationSetup.GetTargetString,'empty.fpm']));
  484. System.Rewrite(F);
  485. System.Close(F);
  486. s := RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestPath, ['list'], 'list packages');
  487. Check(pos('Failed to load package "empty"', s) > 0, 'Missing warning that the invalid package is skipped')
  488. end;
  489. procedure TFullFPCInstallationTests.TestMissingSource;
  490. var
  491. s: String;
  492. begin
  493. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagea');
  494. // Build and install package
  495. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['build'], 'build PackageA');
  496. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['install'], 'install PackageA');
  497. // Destroy the installation
  498. DeleteFile(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'user','lib','fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.ppu']));
  499. // Re-install
  500. RunFppkgIndir(TFullFPCInstallationSetup.GetTestPath, ['install', 'packagea'], 're-install PackageA');
  501. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'user','lib','fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.ppu'])), 'PackageAUnitA.ppu not found after re-install');
  502. // Remove the original sources
  503. DeleteDirectory(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', False);
  504. s := RunFppkgIndir(TFullFPCInstallationSetup.GetTestPath, ['install', 'packagea'], 'Re-install PackageA without source', 1);
  505. Check(pos('Source of package packagea is not available', s) > 0, 'Missing warning that the package-source is unavailable. Fppkg-output: ' + s)
  506. end;
  507. procedure TFullFPCInstallationTests.TestBuildWithInstalledDependency;
  508. var
  509. s: String;
  510. begin
  511. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagea');
  512. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packageb');
  513. // Build and install package
  514. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['install'], 'install PackageA');
  515. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageb', ['install'], 'install PackageB using the installed dependency PackageA');
  516. // Test installation
  517. s := RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestPath, ['list'], 'list packages');
  518. Check(pos('packagea', s) > 0, 'Just installed PackageA is not in package-list');
  519. Check(pos('PackageB', s) > 0, 'Just installed PackageB is not in package-list');
  520. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'user','lib','fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.ppu'])), 'PackageAUnitA.ppu not found');
  521. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'user','lib','fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'PackageB','PackageBUnitB.ppu'])), 'PackageBUnitB.ppu not found');
  522. end;
  523. procedure TFullFPCInstallationTests.TestFakePackageDir;
  524. var
  525. s: String;
  526. begin
  527. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagea');
  528. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packageb');
  529. // Build and install package
  530. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['install', '-i', 'fpc'], 'install PackageA');
  531. ForceDirectories(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units', TFullFPCInstallationSetup.GetTargetString, 'PackageA']));
  532. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageb', ['install'], 'install PackageB using the installed dependency PackageA');
  533. // Test installation
  534. s := RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestPath, ['list'], 'list packages');
  535. Check(pos('packagea', s) > 0, 'Just installed PackageA is not in package-list');
  536. Check(pos('PackageB', s) > 0, 'Just installed PackageB is not in package-list');
  537. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'lib','fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'packagea','PackageAUnitA.ppu'])), 'PackageAUnitA.ppu not found');
  538. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'user','lib','fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units',TFullFPCInstallationSetup.GetTargetString,'PackageB','PackageBUnitB.ppu'])), 'PackageBUnitB.ppu not found');
  539. end;
  540. procedure TFullFPCInstallationTests.TestSourceDependency;
  541. var
  542. s: String;
  543. begin
  544. // This is to test if fpmkunit works correctly when a dependency is available
  545. // not as an installed but as a (compiled) source-package. This happens for
  546. // example if you try to compile _one_ fpmake-packages in fpcsrc/packages,
  547. // using 'make clean all' and it needs one of the other packages in
  548. // fpcsrc/packages.
  549. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagea');
  550. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packageb');
  551. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['build'], 'build PackageA');
  552. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageb', ['build'], 'create fpmake-executable', 1);
  553. RunFPMakeIndir(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath,'packageb']), ['build'], 'build packageb');
  554. // When there is no .fpm file, fpmake should complain that the package is not
  555. // compiled. (Another possibility is that another packages is mistakenly being
  556. // used, for example when the package-name does not match the directory-name)
  557. // This has to be enforced because without the .fpm, the dependencies are
  558. // not handled.
  559. s := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath,'packagea','packagea-'+TFullFPCInstallationSetup.GetTargetString+'.fpm']);
  560. DeleteFile(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath,'packagea','packagea-'+TFullFPCInstallationSetup.GetTargetString+'.fpm']));
  561. s := RunFPMakeIndir(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath,'packageb']), ['build', '-d'], 'build packageb without fpm', 1);
  562. Check(pos('the package is not compiled', s) > 0, 'Missing .fpm-file detection did not trigger');
  563. Check(pos('Could not find unit directory for dependency package', s) > 0, 'Incorrect error message');
  564. end;
  565. procedure TFullFPCInstallationTests.TestTransmitOptions;
  566. begin
  567. // Test the TransmitOptions settings. PackageA contain some TransmitOptions,
  568. // without which the other packages won't compile.
  569. // PackageC depends on both PackageB's, but should only add the TransmitOptions
  570. // from PackageA once.
  571. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagea', 'transmitoptions');
  572. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packageb1', 'transmitoptions');
  573. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packageb2', 'transmitoptions');
  574. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagec', 'transmitoptions');
  575. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['install'], 'build PackageA');
  576. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageb1', ['install'], 'build PackageB1');
  577. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageb2', ['install'], 'build PackageB2');
  578. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagec', ['install'], 'build PackageC');
  579. end;
  580. procedure TFullFPCInstallationTests.TestPackageVariantPackage;
  581. var
  582. s: String;
  583. begin
  584. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagevarianta');
  585. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagevariantp');
  586. // Compile the packages with their default variant
  587. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagevarianta', ['install'], 'install PackageVariantA');
  588. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagevariantp', ['install'], 'install PackageVariantP');
  589. // Check the usage of the versiona-subdirectory
  590. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units', TFullFPCInstallationSetup.GetTargetString, 'packagevarianta', 'versiona', 'packagevariantbaseunit.ppu'])), 'packagevariantbaseunit.ppu not found');
  591. // Check the output of the generated executable
  592. s := RunTestCommandIndir(TFullFPCInstallationSetup.GetCurrentTestPath, ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'bin', 'packagevariantp']), [], 'Run PackageVariantP');
  593. Check(pos('Hello version A', s) > 0, 'Package is not compiled with Version-A unit');
  594. RunFPMakeIndir(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath,'packagevarianta']), ['build', '+ProcVersion=versionb'], 'build PackageVariantA in the VersionB variant');
  595. RunFPMakeIndir(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath,'packagevariantp']), ['build', '+ProcVersion=versionb'], 'build PackageVariantP in the VersionB variant');
  596. // Check the usage of the versiona- & versionb-subdirectory
  597. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath, 'packagevarianta', 'units', TFullFPCInstallationSetup.GetTargetString, 'versiona', 'packagevariantbaseunit.ppu'])), 'packagevariantbaseunit.ppu versiona not found');
  598. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath, 'packagevarianta', 'units', TFullFPCInstallationSetup.GetTargetString, 'versionb', 'packagevariantbaseunit.ppu'])), 'packagevariantbaseunit.ppu versionb not found');
  599. // Check the output of the generated executable
  600. s := RunTestCommandIndir(TFullFPCInstallationSetup.GetCurrentTestPath, ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath, 'packagevariantp', 'bin', TFullFPCInstallationSetup.GetTargetString, 'packagevariantp']), [], 'Run PackageVariantP');
  601. Check(pos('Bye version B', s) > 0, 'Package is not compiled with Version-B unit');
  602. Check(pos('Now with extra unit!', s) > 0, 'Package is not compiled with extra Version-B unit');
  603. // Compile PackageVariantP again, but now with VersionA
  604. RunFPMakeIndir(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath,'packagevariantp']), ['build', '+ProcVersion=versiona'], 'build PackageVariantP in the VersionA variant');
  605. // Check the output of the generated executable
  606. s := RunTestCommandIndir(TFullFPCInstallationSetup.GetCurrentTestPath, ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath, 'packagevariantp', 'bin', TFullFPCInstallationSetup.GetTargetString, 'packagevariantp']), [], 'Run PackageVariantP');
  607. Check(pos('Hello version A', s) > 0, 'Package is not compiled with Version-A unit');
  608. end;
  609. procedure TFullFPCInstallationTests.TestFPMakeCommandLikePackageVariants;
  610. var
  611. s: String;
  612. begin
  613. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagea');
  614. TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packageb');
  615. // Build packagea so that fpmake is compiled
  616. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['build'], 'build PackageA with fppkg');
  617. // Test some invalid command-line arguments
  618. s := RunFPMakeIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath+ 'packagea', ['build', '+buildvariant'], 'Test with invalid +buildvariant command line option', 1);
  619. Check(pos('needs an argument', s) > 0, 'FPMake did not check for the argument');
  620. s := RunFPMakeIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath+ 'packagea', ['build', '+buildvariant+'], 'Test with invalid +buildvariant+ command line option', 1);
  621. Check(pos('needs an argument', s) > 0, 'FPMake did not check for the argument +');
  622. s := RunFPMakeIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath+ 'packagea', ['build', '+buildvariant+='], 'Test with empty +buildvariant+ value', 1);
  623. Check(pos('should have at least one item', s) > 0, 'FPMake did not check for an empty argument');
  624. // Build PackageA with BuildVariants
  625. RunFPMakeIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath+ 'packagea', ['build', '+buildvariant+=debug,release', '--options_buildvariant_debug=-gl', '--options_buildvariant_release="-g- -CX -XX -O2"'], 'Build debug variant');
  626. // Build the release-variant
  627. RunFPMakeIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath+ 'packagea', ['build', '+buildvariant+=debug,release', '--options_buildvariant_debug=-gl', '--options_buildvariant_release="-g- -CX -XX -O2"', '+buildvariant=release'], 'Build release variant');
  628. // Check the usage of the debug- & release-subdirectory
  629. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath, 'packagea', 'units', TFullFPCInstallationSetup.GetTargetString, 'debug', 'PackageAUnitA.ppu'])), 'PackageAUnitA.ppu debug-version not found');
  630. Check(FileExists(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath, 'packagea', 'units', TFullFPCInstallationSetup.GetTargetString, 'release', 'PackageAUnitA.ppu'])), 'PackageAUnitA.ppu release-version not found');
  631. // Install PackageA with BuildVariants
  632. RunFPMakeIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath+ 'packagea', ['install', '+buildvariant+=debug,release', '--options_buildvariant_debug=-gl', '--options_buildvariant_release="-g- -CX -XX -O2"'], 'Build debug variant');
  633. // Install the release-variant
  634. RunFPMakeIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath+ 'packagea', ['install', '+buildvariant+=debug,release', '--options_buildvariant_debug=-gl', '--options_buildvariant_release="-g- -CX -XX -O2"', '+buildvariant=release'], 'Build release variant');
  635. // Check the usage of the debug-subdirectory
  636. s := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units', TFullFPCInstallationSetup.GetTargetString, 'packagea', 'debug', 'PackageAUnitA.ppu']);
  637. Check(FileExists(s), 'installed PackageAUnitA.ppu debug-version not found');
  638. // Check that the debug-version has debug-information
  639. s := RunTestCommandIndir(TFullFPCInstallationSetup.GetCurrentTestPath, TFullFPCInstallationSetup.GetCurrentTestPath+'bin'+PathDelim+'ppudump', s, 'Dump the ppu-information of the debug unit');
  640. Check(pos('has_debug_info', s) > 0, 'The debug-unit does not have debug-info');
  641. // Check the usage of the release-subdirectory
  642. s := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'units', TFullFPCInstallationSetup.GetTargetString, 'packagea', 'release', 'PackageAUnitA.ppu']);
  643. Check(FileExists(s), 'installed PackageAUnitA.ppu release-version not found');
  644. // Check that the debug-version has debug-information
  645. s := RunTestCommandIndir(TFullFPCInstallationSetup.GetCurrentTestPath, TFullFPCInstallationSetup.GetCurrentTestPath+'bin'+PathDelim+'ppudump', s, 'Dump the ppu-information of the release unit');
  646. Check(pos('has_debug_info', s) = 0, 'The release-unit has debug-info');
  647. // Build packageb, use the default variant (debug)
  648. RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageb', ['build'], 'build PackageB with fppkg');
  649. end;
  650. Initialization
  651. RegisterTestDecorator(TFullFPCInstallationSetup, TFullFPCInstallationTests);
  652. end.