IDE: Add methods for merging paths to CompilerOptions and replace common code patterns with them.

git-svn-id: trunk@52693 -
This commit is contained in:
juha 2016-07-15 17:47:18 +00:00
parent 800f13923b
commit 297e19a349
7 changed files with 81 additions and 68 deletions

View File

@ -1186,13 +1186,11 @@ var
procedure AddSearchPath(const SearchPath: string);
begin
with fProjPack.BaseCompilerOptions do begin
IncludePath:=MergeSearchPaths(IncludePath,SearchPath);
Libraries:=MergeSearchPaths(Libraries,SearchPath);
OtherUnitFiles:=MergeSearchPaths(OtherUnitFiles,SearchPath);
ObjectPath:=MergeSearchPaths(ObjectPath,SearchPath);
DebugPath:=MergeSearchPaths(DebugPath,SearchPath);
end;
fProjPack.BaseCompilerOptions.MergeToIncludePaths(SearchPath);
fProjPack.BaseCompilerOptions.MergeToLibraryPaths(SearchPath);
fProjPack.BaseCompilerOptions.MergeToUnitPaths(SearchPath);
fProjPack.BaseCompilerOptions.MergeToObjectPath(SearchPath);
fProjPack.BaseCompilerOptions.MergeToDebugPath(SearchPath);
end;
var
@ -1218,8 +1216,7 @@ begin
// debug source dirs
DebugSourceDirs:=ReadSearchPath('Directories','DebugSourceDirs');
if DebugSourceDirs<>'' then
with fProjPack.BaseCompilerOptions do
DebugPath:=MergeSearchPaths(DebugPath,DebugSourceDirs);
fProjPack.BaseCompilerOptions.MergeToDebugPath(DebugSourceDirs);
// packages
ReadDelphiPackages;
@ -1259,11 +1256,10 @@ begin
if (c='U') or (c='I') then begin
s:=ExpandDelphiSearchPath(copy(Line,4,length(Line)-4), Self);
if s<>'' then
with fProjPack.BaseCompilerOptions do
case c of
'U': OtherUnitFiles:=MergeSearchPaths(OtherUnitFiles,s);
'I': IncludePath:=MergeSearchPaths(IncludePath,s);
end;
case c of
'U': fProjPack.BaseCompilerOptions.MergeToUnitPaths(s);
'I': fProjPack.BaseCompilerOptions.MergeToIncludePaths(s);
end;
end
end;
finally
@ -1333,11 +1329,8 @@ function TConvertDelphiProjPack.DoMissingUnits(AUsedUnitsTool: TUsedUnitsTool):
mUnit:=AUsedUnits.MissingUnits[i];
sUnitPath:=GetCachedUnitPath(mUnit);
if sUnitPath<>'' then begin
// Found from cached paths: add unit path to project's settings.
with fProjPack.BaseCompilerOptions do begin
OtherUnitFiles:=MergeSearchPaths(OtherUnitFiles,sUnitPath);
IncludePath:=MergeSearchPaths(IncludePath,sUnitPath);
end;
fProjPack.BaseCompilerOptions.MergeToUnitPaths(sUnitPath);
fProjPack.BaseCompilerOptions.MergeToIncludePaths(sUnitPath);
// Rename a unit with different casing if needed.
RealFileName:=fCachedRealFileNames[UpperCase(mUnit)];
RealUnitName:=ExtractFileNameOnly(RealFileName);
@ -1633,11 +1626,8 @@ begin
end;
finally
AllPath:=fUnitSearchPaths.DelimitedText;
// Set unit and include paths for project
with LazProject.CompilerOptions do begin
OtherUnitFiles:=MergeSearchPaths(OtherUnitFiles,AllPath);
IncludePath:=MergeSearchPaths(IncludePath,AllPath);
end;
LazProject.CompilerOptions.MergeToUnitPaths(AllPath);
LazProject.CompilerOptions.MergeToIncludePaths(AllPath);
// Clear caches
LazProject.DefineTemplates.SourceDirectoriesChanged;
end;

View File

@ -549,9 +549,18 @@ type
function GetCustomOptions(Parsed: TCompilerOptionsParseType): string;
function TrimCustomOptions(o: string): string; override;
function GetOptionsForCTDefines: string;
// rename macro in paths and options, not in BuildMacros, not in dependencies
procedure RenameMacro(const OldName, NewName: string;
ChangeConditionals: boolean); virtual; // rename macro in paths and options, not in BuildMacros, not in dependencies
ChangeConditionals: boolean); virtual;
procedure MergeToIncludePaths(const AddSearchPath: string);
procedure MergeToLibraryPaths(const AddSearchPath: string);
procedure MergeToUnitPaths(const AddSearchPath: string);
procedure MergeToObjectPath(const AddSearchPath: string);
procedure MergeToSrcPath(const AddSearchPath: string);
procedure MergeToDebugPath(const AddSearchPath: string);
procedure RemoveFromUnitPaths(const RemSearchPath: string);
// compiler message types by id
function IDEMessageFlags: TCompilerMsgIDFlags; inline;
public
// not stored properties
property ParsedOpts: TParsedCompilerOptions read FParsedOpts;
@ -569,9 +578,6 @@ type
property ExecuteAfter: TCompilationToolOptions read fExecuteAfter;
property CreateMakefileOnBuild: boolean read FCreateMakefileOnBuild
write SetCreateMakefileOnBuild;
// compiler message types by id
function IDEMessageFlags: TCompilerMsgIDFlags; inline;
end;
TBaseCompilerOptionsClass = class of TBaseCompilerOptions;
@ -2448,6 +2454,41 @@ begin
end;
end;
procedure TBaseCompilerOptions.MergeToIncludePaths(const AddSearchPath: string);
begin
SetIncludePaths(MergeSearchPaths(GetIncludePaths,AddSearchPath));
end;
procedure TBaseCompilerOptions.MergeToLibraryPaths(const AddSearchPath: string);
begin
SetLibraryPaths(MergeSearchPaths(GetLibraryPaths,AddSearchPath));
end;
procedure TBaseCompilerOptions.MergeToUnitPaths(const AddSearchPath: string);
begin
SetUnitPaths(MergeSearchPaths(GetUnitPaths,AddSearchPath));
end;
procedure TBaseCompilerOptions.MergeToObjectPath(const AddSearchPath: string);
begin
SetObjectPath(MergeSearchPaths(GetObjectPath,AddSearchPath));
end;
procedure TBaseCompilerOptions.MergeToSrcPath(const AddSearchPath: string);
begin
SetSrcPath(MergeSearchPaths(GetSrcPath,AddSearchPath));
end;
procedure TBaseCompilerOptions.MergeToDebugPath(const AddSearchPath: string);
begin
SetDebugPath(MergeSearchPaths(GetDebugPath,AddSearchPath));
end;
procedure TBaseCompilerOptions.RemoveFromUnitPaths(const RemSearchPath: string);
begin
SetUnitPaths(RemoveSearchPaths(GetUnitPaths,RemSearchPath));
end;
function TBaseCompilerOptions.ShortenPath(const SearchPath: string;
MakeAlwaysRelative: boolean): string;
begin

View File

@ -366,8 +366,7 @@ begin
Format(lisExtendUnitSearchPathOfProjectWith, [#13, NewUnitPaths]),
mtConfirmation, [mbYes, mbNo, mbCancel]);
case r of
mrYes: AProject.CompilerOptions.OtherUnitFiles:=
MergeSearchPaths(AProject.CompilerOptions.OtherUnitFiles,NewUnitPaths);
mrYes: AProject.CompilerOptions.MergeToUnitPaths(NewUnitPaths);
mrNo: ;
else exit(false);
end;
@ -389,8 +388,7 @@ begin
Format(lisExtendIncludeFilesSearchPathOfProjectWith, [#13, NewIncPaths]),
mtConfirmation, [mbYes, mbNo, mbCancel]);
case r of
mrYes: AProject.CompilerOptions.IncludePath:=
MergeSearchPaths(AProject.CompilerOptions.IncludePath,NewIncPaths);
mrYes: AProject.CompilerOptions.MergeToIncludePaths(NewIncPaths);
mrNo: ;
else exit(false);
end;

View File

@ -4835,8 +4835,7 @@ end;
procedure TProject.AddSrcPath(const SrcPathAddition: string);
begin
CompilerOptions.SrcPath:=MergeSearchPaths(CompilerOptions.SrcPath,
GetForcedPathDelims(SrcPathAddition));
CompilerOptions.MergeToSrcPath( GetForcedPathDelims(SrcPathAddition) );
end;
function TProject.GetSourceDirs(WithProjectDir, WithoutOutputDir: boolean): string;
@ -4875,15 +4874,12 @@ begin
end;
procedure TProject.AutoAddOutputDirToIncPath;
var
IncPath: String;
begin
if pfLRSFilesInOutputDirectory in Flags then begin
// the .lrs files are auto created in the output directory
// => make sure the project output directory is in the include path
IncPath:=CompilerOptions.IncludePath;
if SearchDirectoryInSearchPath(IncPath,'$(ProjOutDir)')<1 then
CompilerOptions.IncludePath:=MergeSearchPaths(IncPath,';$(ProjOutDir)');
if SearchDirectoryInSearchPath(CompilerOptions.IncludePath,'$(ProjOutDir)')<1 then
CompilerOptions.MergeToIncludePaths(';$(ProjOutDir)');
end;
end;

View File

@ -4240,11 +4240,10 @@ begin
if not Ok then Exit(False);
for i:=0 to Project1.BuildModes.Count-1 do
if (FListForm=Nil) or FListForm.CheckListBox1.Checked[i] then
with Project1.BuildModes[i].CompilerOptions do
if IsIncludeFile then
IncludePath:=MergeSearchPaths(IncludePath,aPath)
else
OtherUnitFiles:=MergeSearchPaths(OtherUnitFiles,aPath);
if IsIncludeFile then
Project1.BuildModes[i].CompilerOptions.MergeToIncludePaths(aPath)
else
Project1.BuildModes[i].CompilerOptions.MergeToUnitPaths(aPath);
finally
FListForm.Free;
end;
@ -5578,20 +5577,15 @@ begin
//DebugLn('TLazSourceFileManager.RenameUnit OldFilePath="',OldFilePath,'" SourceDirs="',Project1.SourceDirectories.CreateSearchPathFromAllFiles,'"');
if (SearchDirectoryInSearchPath(
Project1.SourceDirectories.CreateSearchPathFromAllFiles,OldFilePath,1)<1)
then begin
then
//DebugLn('TLazSourceFileManager.RenameUnit OldFilePath="',OldFilePath,'" UnitPath="',Project1.CompilerOptions.GetUnitPath(false),'"');
if (SearchDirectoryInSearchPath(
Project1.CompilerOptions.GetUnitPath(false),OldFilePath,1)<1)
then begin
if (SearchDirectoryInSearchPath(Project1.CompilerOptions.GetUnitPath(false),OldFilePath,1)<1)
then
if IDEMessageDialog(lisCleanUpUnitPath,
Format(lisTheDirectoryIsNoLongerNeededInTheUnitPathRemoveIt,[OldFilePath,LineEnding]),
mtConfirmation,[mbYes,mbNo])=mrYes then
begin
Project1.CompilerOptions.OtherUnitFiles:=
RemoveSearchPaths(Project1.CompilerOptions.OtherUnitFiles, OldUnitPath);
end;
end;
end;
mtConfirmation,[mbYes,mbNo])=mrYes
then
Project1.CompilerOptions.RemoveFromUnitPaths(OldUnitPath);
end;
// delete old pas, .pp, .ppu

View File

@ -3185,8 +3185,7 @@ begin
Format(lisExtendUnitSearchPathOfPackageWith, [Name, #13, NewUnitPaths]),
mtConfirmation, [mbYes, mbNo, mbCancel]);
case r of
mrYes: CompilerOptions.OtherUnitFiles:=
MergeSearchPaths(CompilerOptions.OtherUnitFiles,NewUnitPaths);
mrYes: CompilerOptions.MergeToUnitPaths(NewUnitPaths);
mrNo: ;
else exit(false);
end;
@ -3207,8 +3206,7 @@ begin
Format(lisExtendIncludeFileSearchPathOfPackageWith, [Name, #13, NewIncPaths]),
mtConfirmation, [mbYes, mbNo, mbCancel]);
case r of
mrYes: CompilerOptions.IncludePath:=
MergeSearchPaths(CompilerOptions.IncludePath,NewIncPaths);
mrYes: CompilerOptions.MergeToIncludePaths(NewIncPaths);
mrNo: ;
else exit(false);
end;

View File

@ -2977,15 +2977,12 @@ begin
exit;
end;
// add path
with LazPackage.CompilerOptions do
OtherUnitFiles:=MergeSearchPaths(OtherUnitFiles,ShortDirectory);
LazPackage.CompilerOptions.MergeToUnitPaths(ShortDirectory);
end;
if IncPathPos<1 then begin
if IncPathPos<1 then
// the unit is in unitpath, but the include file not in the incpath
// -> auto extend the include path
with LazPackage.CompilerOptions do
IncludePath:=MergeSearchPaths(IncludePath,ShortIncDirectory);
end;
LazPackage.CompilerOptions.MergeToIncludePaths(ShortIncDirectory);
end;
procedure TPackageEditorForm.ExtendIncPathForNewIncludeFile(
@ -3021,8 +3018,7 @@ begin
exit;
end;
// add path
with LazPackage.CompilerOptions do
IncludePath:=MergeSearchPaths(IncludePath,ShortDirectory);
LazPackage.CompilerOptions.MergeToIncludePaths(ShortDirectory);
end;
function TPackageEditorForm.ExtendUnitSearchPath(NewUnitPaths: string): boolean;