Browse Source

* When there are multiple global-option sections, merge them (+test)

git-svn-id: trunk@35930 -
joost 8 years ago
parent
commit
34f547d0d4
2 changed files with 49 additions and 12 deletions
  1. 15 12
      packages/fppkg/src/pkgoptions.pp
  2. 34 0
      packages/fppkg/tests/fullfpcinstallationtests.pas

+ 15 - 12
packages/fppkg/src/pkgoptions.pp

@@ -792,19 +792,22 @@ begin
             if not Assigned(CurrentSection) or CurrentSection.AllowDuplicate then
               begin
                 if SameText(s, KeyGlobalSection) or SameText(s, KeyDeprGlobalSection) then
-                  CurrentSection := TFppkgGlobalOptionSection.Create(FOptionParser)
-                else if SameText(s, KeyRepositorySection) then
-                  CurrentSection := TFppkgRepositoryOptionSection.Create(FOptionParser)
-                else if SameText(s, KeySrcRepositorySection) then
-                  CurrentSection := TFppkgUninstalledSourceRepositoryOptionSection.Create(FOptionParser)
-                else if SameText(s, KeyIncludeFilesSection) then
-                  CurrentSection := TFppkgIncludeFilesOptionSection.Create(FOptionParser, Self, ExtractFileDir(AFileName))
-                else if SameText(s, KeyUninstalledRepository) then
-                  CurrentSection := TFppkgUninstalledRepositoryOptionSection.Create(FOptionParser)
+                  CurrentSection := GetGlobalSection
                 else
-                  CurrentSection := TFppkgCustomOptionSection.Create(FOptionParser);
-                FSectionList.Add(CurrentSection);
-                CurrentSection.Name := s;
+                  begin
+                    if SameText(s, KeyRepositorySection) then
+                      CurrentSection := TFppkgRepositoryOptionSection.Create(FOptionParser)
+                    else if SameText(s, KeySrcRepositorySection) then
+                      CurrentSection := TFppkgUninstalledSourceRepositoryOptionSection.Create(FOptionParser)
+                    else if SameText(s, KeyIncludeFilesSection) then
+                      CurrentSection := TFppkgIncludeFilesOptionSection.Create(FOptionParser, Self, ExtractFileDir(AFileName))
+                    else if SameText(s, KeyUninstalledRepository) then
+                      CurrentSection := TFppkgUninstalledRepositoryOptionSection.Create(FOptionParser)
+                    else
+                      CurrentSection := TFppkgCustomOptionSection.Create(FOptionParser);
+                    FSectionList.Add(CurrentSection);
+                    CurrentSection.Name := s;
+                  end;
               end
           end
         else if copy(s,1,1)<>';' then // comment

+ 34 - 0
packages/fppkg/tests/fullfpcinstallationtests.pas

@@ -27,6 +27,7 @@ type
   published
     procedure TestListPackages;
     procedure IntTestListPackages;
+    procedure IntTestMergeGlobalOptions;
     procedure TestPackageA;
     procedure TestLooseFPMFile;
     procedure TestMissingSource;
@@ -359,6 +360,39 @@ begin
    end;
 end;
 
+procedure TFullFPCInstallationTests.IntTestMergeGlobalOptions;
+var
+  FPpkg: TpkgFPpkg;
+  ExtraConfFile: Text;
+  s: string;
+begin
+  // When there are multiple global-sections, it's values should be merged.
+  s := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'config', 'conf.d', 'extrasettings.conf']);
+  AssignFile(ExtraConfFile, ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'config', 'conf.d', 'extrasettings.conf']));
+  Rewrite(ExtraConfFile);
+  WriteLn(ExtraConfFile, '[global]');
+  WriteLn(ExtraConfFile, 'FPMakeOptions="-T 4"');
+  CloseFile(ExtraConfFile);
+
+  FPpkg := TpkgFPpkg.Create(nil);
+  try
+    FPpkg.InitializeGlobalOptions(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'etc','fppkg.cfg']));
+    FPpkg.Options.GlobalSection.Downloader := 'FPC';
+    FPpkg.InitializeCompilerOptions;
+
+    FPpkg.CompilerOptions.InitCompilerDefaults;
+    FPpkg.FpmakeCompilerOptions.InitCompilerDefaults;
+    FPpkg.CompilerOptions.CheckCompilerValues;
+    FPpkg.FpmakeCompilerOptions.CheckCompilerValues;
+    FPpkg.LoadLocalAvailableMirrors;
+
+    CheckEquals('user', FPpkg.Options.GlobalSection.InstallRepository, 'The InstallRepository does not match the value in the original configuration file');
+    CheckEquals('"-T 4"', FPpkg.Options.GlobalSection.CustomFPMakeOptions, 'The custom FPMakeOptions do not match the value in the extra configuration file');
+  finally
+    FPpkg.Free;
+  end;
+end;
+
 procedure TFullFPCInstallationTests.TestPackageA;
 var
   s: String;