mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-27 21:20:30 +02:00
IDE: compiler options: warn if SrcPath contains paths in UnitPath
git-svn-id: trunk@28188 -
This commit is contained in:
parent
82ab7cfc02
commit
ffe59abaf7
@ -47,6 +47,9 @@ type
|
|||||||
chkUseAsDefault: TCheckBox;
|
chkUseAsDefault: TCheckBox;
|
||||||
function CheckSearchPath(const Context, ExpandedPath: string;
|
function CheckSearchPath(const Context, ExpandedPath: string;
|
||||||
Level: TCheckCompileOptionsMsgLvl): boolean;
|
Level: TCheckCompileOptionsMsgLvl): boolean;
|
||||||
|
function CheckSrcPathInUnitPath(OldParsedSrcPath, NewParsedSrcPath,
|
||||||
|
OldParsedUnitPath, NewParsedUnitPath: string;
|
||||||
|
out SrcPathChanged: boolean): boolean;
|
||||||
procedure FileBrowseBtnClick(Sender: TObject);
|
procedure FileBrowseBtnClick(Sender: TObject);
|
||||||
procedure PathEditBtnClick(Sender: TObject);
|
procedure PathEditBtnClick(Sender: TObject);
|
||||||
procedure PathEditBtnExecuted(Sender: TObject);
|
procedure PathEditBtnExecuted(Sender: TObject);
|
||||||
@ -98,34 +101,62 @@ var
|
|||||||
OldUnparsedUnitPath: String;
|
OldUnparsedUnitPath: String;
|
||||||
OldUnparsedSrcPath: String;
|
OldUnparsedSrcPath: String;
|
||||||
OldUnparsedDebugPath: String;
|
OldUnparsedDebugPath: String;
|
||||||
|
NewParsedIncludePath: String;
|
||||||
|
NewParsedLibraries: String;
|
||||||
|
NewParsedUnitPath: String;
|
||||||
|
NewParsedSrcPath: String;
|
||||||
|
NewParsedDebugPath: String;
|
||||||
|
PathsChanged: boolean;
|
||||||
|
|
||||||
|
procedure GetParsedPaths;
|
||||||
begin
|
begin
|
||||||
OldParsedIncludePath := FCompilerOpts.GetIncludePath(False);
|
NewParsedIncludePath:=FCompilerOpts.GetIncludePath(False,coptParsed,false);
|
||||||
|
NewParsedLibraries:=FCompilerOpts.GetLibraryPath(False,coptParsed,false);
|
||||||
|
NewParsedUnitPath:=FCompilerOpts.GetUnitPath(False,coptParsed,false);
|
||||||
|
NewParsedSrcPath:=FCompilerOpts.GetSrcPath(False,coptParsed,false);
|
||||||
|
NewParsedDebugPath:=FCompilerOpts.GetDebugPath(False,coptParsed,false);
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
GetParsedPaths;
|
||||||
|
OldParsedIncludePath := NewParsedIncludePath;
|
||||||
OldUnparsedIncludePath := FCompilerOpts.IncludePath;
|
OldUnparsedIncludePath := FCompilerOpts.IncludePath;
|
||||||
OldParsedLibraryPath := FCompilerOpts.GetLibraryPath(False);
|
OldParsedLibraryPath := NewParsedLibraries;
|
||||||
OldUnparsedLibraryPath := FCompilerOpts.Libraries;
|
OldUnparsedLibraryPath := FCompilerOpts.Libraries;
|
||||||
OldParsedUnitPath := FCompilerOpts.GetUnitPath(False);
|
OldParsedUnitPath := NewParsedUnitPath;
|
||||||
OldUnparsedUnitPath := FCompilerOpts.OtherUnitFiles;
|
OldUnparsedUnitPath := FCompilerOpts.OtherUnitFiles;
|
||||||
OldParsedSrcPath := FCompilerOpts.GetSrcPath(False);
|
OldParsedSrcPath := NewParsedSrcPath;
|
||||||
OldUnparsedSrcPath := FCompilerOpts.SrcPath;
|
OldUnparsedSrcPath := FCompilerOpts.SrcPath;
|
||||||
OldParsedDebugPath := FCompilerOpts.GetDebugPath(False);
|
OldParsedDebugPath := NewParsedDebugPath;
|
||||||
OldUnparsedDebugPath := FCompilerOpts.DebugPath;
|
OldUnparsedDebugPath := FCompilerOpts.DebugPath;
|
||||||
|
|
||||||
|
Result:=false;
|
||||||
try
|
try
|
||||||
FCompilerOpts.IncludePath := IncludeFilesEdit.Text;
|
FCompilerOpts.IncludePath := IncludeFilesEdit.Text;
|
||||||
FCompilerOpts.Libraries := LibrariesEdit.Text;
|
FCompilerOpts.Libraries := LibrariesEdit.Text;
|
||||||
FCompilerOpts.OtherUnitFiles := OtherUnitsEdit.Text;
|
FCompilerOpts.OtherUnitFiles := OtherUnitsEdit.Text;
|
||||||
FCompilerOpts.SrcPath := OtherSourcesEdit.Text;
|
FCompilerOpts.SrcPath := OtherSourcesEdit.Text;
|
||||||
FCompilerOpts.DebugPath := DebugPathEdit.Text;
|
FCompilerOpts.DebugPath := DebugPathEdit.Text;
|
||||||
if not CheckPutSearchPath('include search path', OldParsedIncludePath, FCompilerOpts.GetIncludePath(False)) then
|
GetParsedPaths;
|
||||||
Exit(False);
|
|
||||||
if not CheckPutSearchPath('library search path', OldParsedLibraryPath, FCompilerOpts.GetLibraryPath(False)) then
|
if not CheckPutSearchPath('include search path', OldParsedIncludePath, NewParsedIncludePath) then
|
||||||
Exit(False);
|
Exit;
|
||||||
if not CheckPutSearchPath('unit search path', OldParsedUnitPath, FCompilerOpts.GetUnitPath(False)) then
|
if not CheckPutSearchPath('library search path', OldParsedLibraryPath, NewParsedLibraries) then
|
||||||
Exit(False);
|
Exit;
|
||||||
if not CheckPutSearchPath('source search path', OldParsedSrcPath, FCompilerOpts.GetSrcPath(False)) then
|
if not CheckPutSearchPath('unit search path', OldParsedUnitPath, NewParsedUnitPath) then
|
||||||
Exit(False);
|
Exit;
|
||||||
if not CheckPutSearchPath('debugger search path', OldParsedDebugPath, FCompilerOpts.GetDebugPath(False)) then
|
if not CheckPutSearchPath('source search path', OldParsedSrcPath, NewParsedSrcPath) then
|
||||||
Exit(False);
|
Exit;
|
||||||
|
if not CheckPutSearchPath('debugger search path', OldParsedDebugPath, NewParsedDebugPath) then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
if not CheckSrcPathInUnitPath(OldParsedSrcPath,NewParsedSrcPath,
|
||||||
|
OldParsedUnitPath,NewParsedUnitPath,PathsChanged)
|
||||||
|
then
|
||||||
|
Exit;
|
||||||
|
if PathsChanged then
|
||||||
|
GetParsedPaths;
|
||||||
|
|
||||||
finally
|
finally
|
||||||
FCompilerOpts.IncludePath := OldUnparsedIncludePath;
|
FCompilerOpts.IncludePath := OldUnparsedIncludePath;
|
||||||
FCompilerOpts.Libraries := OldUnparsedLibraryPath;
|
FCompilerOpts.Libraries := OldUnparsedLibraryPath;
|
||||||
@ -292,6 +323,85 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCompilerPathOptionsFrame.CheckSrcPathInUnitPath(OldParsedSrcPath,
|
||||||
|
NewParsedSrcPath, OldParsedUnitPath, NewParsedUnitPath: string; out
|
||||||
|
SrcPathChanged: boolean): boolean;
|
||||||
|
// checks if the SrcPath contains directories of the UnitPath
|
||||||
|
// the SrcPath should only contain directories for the IDE, not for the compiler
|
||||||
|
var
|
||||||
|
p: Integer;
|
||||||
|
CurPath: String;
|
||||||
|
Duplicates: TStringList;
|
||||||
|
i: PtrInt;
|
||||||
|
OldUnparsedSrcPath: String;
|
||||||
|
NewUnparsedSrcPath: String;
|
||||||
|
j: Integer;
|
||||||
|
BaseDir: String;
|
||||||
|
begin
|
||||||
|
Result:=true;
|
||||||
|
SrcPathChanged:=false;
|
||||||
|
if (OldParsedSrcPath=NewParsedSrcPath)
|
||||||
|
and (OldParsedUnitPath=NewParsedUnitPath) then exit;
|
||||||
|
|
||||||
|
Duplicates:=TStringList.Create;
|
||||||
|
try
|
||||||
|
p:=1;
|
||||||
|
i:=0;
|
||||||
|
BaseDir:=AppendPathDelim(FCompilerOpts.BaseDirectory);
|
||||||
|
repeat
|
||||||
|
CurPath:=GetNextDirectoryInSearchPath(NewParsedSrcPath, p);
|
||||||
|
if (CurPath<>'') and (not IDEMacros.StrHasMacros(CurPath)) and
|
||||||
|
(FilenameIsAbsolute(CurPath)) then
|
||||||
|
begin
|
||||||
|
if (SearchDirectoryInSearchPath(NewParsedUnitPath,CurPath)>0)
|
||||||
|
or (CompareFilenames(BaseDir,AppendPathDelim(CurPath))=0) then
|
||||||
|
Duplicates.AddObject(CurPath,TObject(Pointer(i)));
|
||||||
|
end;
|
||||||
|
inc(i);
|
||||||
|
until p>length(NewParsedSrcPath);
|
||||||
|
|
||||||
|
if Duplicates.Count>0 then
|
||||||
|
begin
|
||||||
|
debugln(['TCompilerPathOptionsFrame.CheckSrcPathInUnitPath OldParsedSrcPath="',OldParsedSrcPath,'" NewParsedSrcPath="',NewParsedSrcPath,'" OldParsedUnitPath="',OldParsedUnitPath,'" NewParsedUnitPath="',NewParsedUnitPath,'"']);
|
||||||
|
Result:=false;
|
||||||
|
Duplicates.Delimiter:=#13;
|
||||||
|
Duplicates.StrictDelimiter:=true;
|
||||||
|
if QuestionDlg(lisDuplicateSearchPath,
|
||||||
|
Format(lisTheOtherSourcesContainsADirectoryWhichIsAlreadyInT, [#13#13,
|
||||||
|
Duplicates.DelimitedText]),
|
||||||
|
mtError,
|
||||||
|
[mrCancel, mrYes, lisRemoveThePathsFromOtherSources, 'IsDefault'],
|
||||||
|
0)=mrYes
|
||||||
|
then begin
|
||||||
|
// remove paths from SrcPath
|
||||||
|
OldUnparsedSrcPath:=FCompilerOpts.SrcPath;
|
||||||
|
NewUnparsedSrcPath:='';
|
||||||
|
i:=0;
|
||||||
|
p:=1;
|
||||||
|
repeat
|
||||||
|
CurPath:=GetNextDirectoryInSearchPath(OldUnparsedSrcPath, p);
|
||||||
|
j:=Duplicates.Count-1;
|
||||||
|
while (j>=0) and (PtrUInt(Duplicates.Objects[j])<>i) do dec(j);
|
||||||
|
if j<0 then
|
||||||
|
begin
|
||||||
|
if NewUnparsedSrcPath<>'' then
|
||||||
|
NewUnparsedSrcPath:=NewUnparsedSrcPath+';';
|
||||||
|
NewUnparsedSrcPath:=NewUnparsedSrcPath+CurPath;
|
||||||
|
end;
|
||||||
|
inc(i);
|
||||||
|
until p>length(OldUnparsedSrcPath);
|
||||||
|
FCompilerOpts.SrcPath:=NewUnparsedSrcPath;
|
||||||
|
OtherSourcesEdit.Text:=FCompilerOpts.SrcPath;
|
||||||
|
|
||||||
|
SrcPathChanged:=true;
|
||||||
|
// do not set Result to true, let's user review the changes
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
Duplicates.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCompilerPathOptionsFrame.PathEditBtnClick(Sender: TObject);
|
procedure TCompilerPathOptionsFrame.PathEditBtnClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
AButton: TPathEditorButton;
|
AButton: TPathEditorButton;
|
||||||
|
@ -2025,6 +2025,11 @@ resourcestring
|
|||||||
dlgPOTargetFileName = 'Target file name:';
|
dlgPOTargetFileName = 'Target file name:';
|
||||||
lisTargetFileNameEmptyUseUnitOutputDirectory = 'Target file name: (-o, empty = '
|
lisTargetFileNameEmptyUseUnitOutputDirectory = 'Target file name: (-o, empty = '
|
||||||
+'use unit output directory)';
|
+'use unit output directory)';
|
||||||
|
lisDuplicateSearchPath = 'Duplicate search path';
|
||||||
|
lisTheOtherSourcesContainsADirectoryWhichIsAlreadyInT = 'The "Other '
|
||||||
|
+'sources" contains a directory which is already in the "Other unit '
|
||||||
|
+'files".%s%s';
|
||||||
|
lisRemoveThePathsFromOtherSources = 'Remove the paths from "Other sources"';
|
||||||
lisTargetFileNameO = 'Target file name (-o):';
|
lisTargetFileNameO = 'Target file name (-o):';
|
||||||
dlgPOUseAppBundle = 'Use Application Bundle for running and debugging (darwin only)';
|
dlgPOUseAppBundle = 'Use Application Bundle for running and debugging (darwin only)';
|
||||||
dlgPOCreateAppBundle = 'Create Application Bundle';
|
dlgPOCreateAppBundle = 'Create Application Bundle';
|
||||||
|
@ -311,11 +311,11 @@ type
|
|||||||
procedure RemoveOnChangedHandler(const Handler: TNotifyEvent);
|
procedure RemoveOnChangedHandler(const Handler: TNotifyEvent);
|
||||||
|
|
||||||
// search paths:
|
// search paths:
|
||||||
property IncludePath: String read GetIncludePaths write SetIncludePaths;
|
property IncludePath: String read GetIncludePaths write SetIncludePaths; // alias IncPath
|
||||||
property Libraries: String read GetLibraryPaths write SetLibraryPaths;
|
property Libraries: String read GetLibraryPaths write SetLibraryPaths; // alias LibraryPath
|
||||||
property OtherUnitFiles: String read GetUnitPaths write SetUnitPaths;
|
property OtherUnitFiles: String read GetUnitPaths write SetUnitPaths; // alias UnitPath
|
||||||
property ObjectPath: string read GetObjectPath write SetObjectPath;
|
property ObjectPath: string read GetObjectPath write SetObjectPath;
|
||||||
property SrcPath: string read GetSrcPath write SetSrcPath;
|
property SrcPath: string read GetSrcPath write SetSrcPath; // alias SrcPath
|
||||||
property DebugPath: string read GetDebugPath write SetDebugPath;
|
property DebugPath: string read GetDebugPath write SetDebugPath;
|
||||||
property UnitOutputDirectory: string read GetUnitOutputDir write SetUnitOutputDir;
|
property UnitOutputDirectory: string read GetUnitOutputDir write SetUnitOutputDir;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user