mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 15:19:19 +02:00
IDE: Update unit path for all build modes also when creating a new unit. Issue #34413.
git-svn-id: trunk@59374 -
This commit is contained in:
parent
ebb0d843ec
commit
1313ae2b9b
@ -123,14 +123,14 @@ procedure SwitchBuildMode(aBuildModeID: string);
|
|||||||
procedure UpdateBuildModeCombo(aCombo: TComboBox);
|
procedure UpdateBuildModeCombo(aCombo: TComboBox);
|
||||||
|
|
||||||
// Functions dealing with many BuildModes. They depend on TBuildModesCheckList.
|
// Functions dealing with many BuildModes. They depend on TBuildModesCheckList.
|
||||||
function AddPathToBuildModes(aPath, CurDirectory: string; IsIncludeFile: Boolean): Boolean;
|
function AddPathToBuildModes(aDir: string; IsIncludeFile: Boolean): Boolean;
|
||||||
procedure RemovePathFromBuildModes(ObsoletePaths: String; pcos: TParsedCompilerOptString);
|
procedure RemovePathFromBuildModes(ObsoletePaths: String; pcos: TParsedCompilerOptString);
|
||||||
function BuildManyModes: Boolean;
|
function BuildManyModes: Boolean;
|
||||||
|
|
||||||
// Check if UnitDirectory is part of the Unit Search Paths.
|
// Check if UnitDirectory is part of the Unit Search Paths.
|
||||||
// If not, ask user if he wants to extend dependencies or the Unit Search Paths.
|
// If not, ask user if he wants to extend dependencies or the Unit Search Paths.
|
||||||
// Not strictly for many BuildModes but it adds a path to them all.
|
// Not strictly for many BuildModes but it adds a path to them all.
|
||||||
function CheckDirIsInSearchPath(UnitInfo: TUnitInfo; AllowAddingDependencies, IsIncludeFile: Boolean): Boolean;
|
function CheckDirIsInSearchPath(UnitInfo: TUnitInfo; IsIncludeFile: Boolean): Boolean;
|
||||||
|
|
||||||
var
|
var
|
||||||
OnLoadIDEOptionsHook: TOnLoadIDEOptions;
|
OnLoadIDEOptionsHook: TOnLoadIDEOptions;
|
||||||
@ -208,7 +208,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function AddPathToBuildModes(aPath, CurDirectory: string; IsIncludeFile: Boolean): Boolean;
|
function AddPathToBuildModes(aDir: string; IsIncludeFile: Boolean): Boolean;
|
||||||
var
|
var
|
||||||
DlgCapt, DlgMsg: String;
|
DlgCapt, DlgMsg: String;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
@ -229,17 +229,20 @@ begin
|
|||||||
if Project1.BuildModes.Count > 1 then
|
if Project1.BuildModes.Count > 1 then
|
||||||
Ok:=BMList.Show
|
Ok:=BMList.Show
|
||||||
else begin
|
else begin
|
||||||
Ok:=IDEMessageDialog(DlgCapt, Format(DlgMsg,[LineEnding,CurDirectory]),
|
Ok:=IDEMessageDialog(DlgCapt, Format(DlgMsg,[LineEnding,aDir]),
|
||||||
mtConfirmation,[mbYes,mbNo]) = mrYes;
|
mtConfirmation,[mbYes,mbNo]) = mrYes;
|
||||||
BMList.SelectFirst; // The only (Default) build mode must be selected.
|
BMList.SelectFirst; // The only (Default) build mode must be selected.
|
||||||
end;
|
end;
|
||||||
if not Ok then Exit(False);
|
if not Ok then Exit(False);
|
||||||
|
if not Project1.IsVirtual then
|
||||||
|
aDir:=CreateRelativePath(aDir, Project1.Directory);
|
||||||
for i:=0 to Project1.BuildModes.Count-1 do
|
for i:=0 to Project1.BuildModes.Count-1 do
|
||||||
if BMList.IsSelected(i) then
|
if BMList.IsSelected(i) then
|
||||||
if IsIncludeFile then
|
with Project1.BuildModes[i].CompilerOptions do
|
||||||
Project1.BuildModes[i].CompilerOptions.MergeToIncludePaths(aPath)
|
if IsIncludeFile then
|
||||||
else
|
MergeToIncludePaths(aDir)
|
||||||
Project1.BuildModes[i].CompilerOptions.MergeToUnitPaths(aPath);
|
else
|
||||||
|
MergeToUnitPaths(aDir);
|
||||||
finally
|
finally
|
||||||
BMList.Free;
|
BMList.Free;
|
||||||
end;
|
end;
|
||||||
@ -374,15 +377,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CheckDirIsInSearchPath(UnitInfo: TUnitInfo;
|
function CheckDirIsInSearchPath(UnitInfo: TUnitInfo; IsIncludeFile: Boolean): Boolean;
|
||||||
AllowAddingDependencies, IsIncludeFile: Boolean): Boolean;
|
|
||||||
// Check if the given unit's path is on Unit- or Include-search path.
|
// Check if the given unit's path is on Unit- or Include-search path.
|
||||||
// Returns true if it is OK to add the unit to current project.
|
// Returns true if it is OK to add the unit to current project.
|
||||||
var
|
var
|
||||||
CurDirectory, CurPath, ShortDir: String;
|
UnitDir, CurPath: String;
|
||||||
Owners: TFPList;
|
|
||||||
APackage: TLazPackage;
|
|
||||||
i: Integer;
|
|
||||||
begin
|
begin
|
||||||
Result:=True;
|
Result:=True;
|
||||||
if UnitInfo.IsVirtual then exit;
|
if UnitInfo.IsVirtual then exit;
|
||||||
@ -390,36 +389,10 @@ begin
|
|||||||
CurPath:=Project1.CompilerOptions.GetIncludePath(false)
|
CurPath:=Project1.CompilerOptions.GetIncludePath(false)
|
||||||
else
|
else
|
||||||
CurPath:=Project1.CompilerOptions.GetUnitPath(false);
|
CurPath:=Project1.CompilerOptions.GetUnitPath(false);
|
||||||
CurDirectory:=AppendPathDelim(UnitInfo.GetDirectory);
|
UnitDir:=AppendPathDelim(UnitInfo.GetDirectory);
|
||||||
if SearchDirectoryInSearchPath(CurPath,CurDirectory)<1 then
|
if SearchDirectoryInSearchPath(CurPath,UnitDir)<1 then
|
||||||
begin
|
// unit is not in search path => extend it
|
||||||
if AllowAddingDependencies then begin
|
Result:=AddPathToBuildModes(UnitDir,IsIncludeFile);
|
||||||
Owners:=PkgBoss.GetPossibleOwnersOfUnit(UnitInfo.Filename,[]);
|
|
||||||
try
|
|
||||||
if (Owners<>nil) then begin
|
|
||||||
for i:=0 to Owners.Count-1 do begin
|
|
||||||
if TObject(Owners[i]) is TLazPackage then begin
|
|
||||||
APackage:=TLazPackage(Owners[i]);
|
|
||||||
if IDEMessageDialog(lisAddPackageRequirement,
|
|
||||||
Format(lisAddPackageToProject, [APackage.IDAsString]),
|
|
||||||
mtConfirmation,[mbYes,mbCancel],'')<>mrYes
|
|
||||||
then
|
|
||||||
Exit(True);
|
|
||||||
PkgBoss.AddProjectDependency(Project1,APackage);
|
|
||||||
Exit(False);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
Owners.Free;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
// unit is not in a package => extend unit path
|
|
||||||
ShortDir:=CurDirectory;
|
|
||||||
if (not Project1.IsVirtual) then
|
|
||||||
ShortDir:=CreateRelativePath(ShortDir,Project1.Directory);
|
|
||||||
Result:=AddPathToBuildModes(ShortDir,CurDirectory,IsIncludeFile);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TBuildModesForm }
|
{ TBuildModesForm }
|
||||||
|
@ -12352,7 +12352,7 @@ begin
|
|||||||
BeginCodeTool(ActiveSourceEditor,ActiveUnitInfo,[]);
|
BeginCodeTool(ActiveSourceEditor,ActiveUnitInfo,[]);
|
||||||
OkToAdd:=True;
|
OkToAdd:=True;
|
||||||
if FilenameIsPascalUnit(AnUnitInfo.Filename) then begin
|
if FilenameIsPascalUnit(AnUnitInfo.Filename) then begin
|
||||||
OkToAdd:=CheckDirIsInSearchPath(AnUnitInfo,False,False);
|
OkToAdd:=CheckDirIsInSearchPath(AnUnitInfo,False);
|
||||||
if (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags) then begin
|
if (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags) then begin
|
||||||
AnUnitInfo.ReadUnitNameFromSource(false);
|
AnUnitInfo.ReadUnitNameFromSource(false);
|
||||||
ShortUnitName:=AnUnitInfo.Unit_Name;
|
ShortUnitName:=AnUnitInfo.Unit_Name;
|
||||||
@ -12369,7 +12369,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else if CompareFileExt(AnUnitInfo.Filename,'inc',false)=0 then
|
else if CompareFileExt(AnUnitInfo.Filename,'inc',false)=0 then
|
||||||
OkToAdd:=CheckDirIsInSearchPath(AnUnitInfo,False,True);
|
OkToAdd:=CheckDirIsInSearchPath(AnUnitInfo,True);
|
||||||
if OkToAdd then
|
if OkToAdd then
|
||||||
;
|
;
|
||||||
Project1.Modified:=true;
|
Project1.Modified:=true;
|
||||||
|
@ -1850,9 +1850,9 @@ begin
|
|||||||
then begin
|
then begin
|
||||||
OkToAdd:=True;
|
OkToAdd:=True;
|
||||||
if FilenameIsPascalUnit(ActiveUnitInfo.Filename) then
|
if FilenameIsPascalUnit(ActiveUnitInfo.Filename) then
|
||||||
OkToAdd:=CheckDirIsInSearchPath(ActiveUnitInfo,False,False)
|
OkToAdd:=CheckDirIsInSearchPath(ActiveUnitInfo,False)
|
||||||
else if CompareFileExt(ActiveUnitInfo.Filename,'inc',false)=0 then
|
else if CompareFileExt(ActiveUnitInfo.Filename,'inc',false)=0 then
|
||||||
OkToAdd:=CheckDirIsInSearchPath(ActiveUnitInfo,False,True);
|
OkToAdd:=CheckDirIsInSearchPath(ActiveUnitInfo,True);
|
||||||
if OkToAdd then begin
|
if OkToAdd then begin
|
||||||
ActiveUnitInfo.IsPartOfProject:=true;
|
ActiveUnitInfo.IsPartOfProject:=true;
|
||||||
Project1.Modified:=true;
|
Project1.Modified:=true;
|
||||||
@ -5308,22 +5308,11 @@ begin
|
|||||||
|
|
||||||
// add new path to unit path
|
// add new path to unit path
|
||||||
if AnUnitInfo.IsPartOfProject
|
if AnUnitInfo.IsPartOfProject
|
||||||
and (not Project1.IsVirtual)
|
|
||||||
and (FilenameIsPascalUnit(NewFilename))
|
and (FilenameIsPascalUnit(NewFilename))
|
||||||
and (CompareFilenames(NewFilePath,Project1.Directory)<>0) then begin
|
and (CompareFilenames(NewFilePath,Project1.Directory)<>0) then begin
|
||||||
OldUnitPath:=Project1.CompilerOptions.GetUnitPath(false);
|
OldUnitPath:=Project1.CompilerOptions.GetUnitPath(false);
|
||||||
|
if SearchDirectoryInSearchPath(OldUnitPath,NewFilePath,1)<1 then
|
||||||
if SearchDirectoryInSearchPath(OldUnitPath,NewFilePath,1)<1 then begin
|
AddPathToBuildModes(NewFilePath, False);
|
||||||
//DebugLn('RenameUnit NewFilePath="',NewFilePath,'" OldUnitPath="',OldUnitPath,'"');
|
|
||||||
if IDEMessageDialog(lisExtendUnitPath,
|
|
||||||
Format(lisTheDirectoryIsNotYetInTheUnitPathAddIt,[NewFilePath,LineEnding]),
|
|
||||||
mtConfirmation,[mbYes,mbNo])=mrYes then
|
|
||||||
begin
|
|
||||||
Project1.CompilerOptions.OtherUnitFiles:=
|
|
||||||
Project1.CompilerOptions.OtherUnitFiles+';'
|
|
||||||
+CreateRelativePath(NewFilePath,Project1.Directory);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// rename lfm file
|
// rename lfm file
|
||||||
@ -5382,8 +5371,7 @@ begin
|
|||||||
Result:=ForceDirectoryInteractive(ExtractFilePath(NewLRSFilename),[mbRetry,mbIgnore]);
|
Result:=ForceDirectoryInteractive(ExtractFilePath(NewLRSFilename),[mbRetry,mbIgnore]);
|
||||||
if Result=mrCancel then exit;
|
if Result=mrCancel then exit;
|
||||||
if Result=mrOk then begin
|
if Result=mrOk then begin
|
||||||
if not CodeToolBoss.SaveBufferAs(LRSCode,NewLRSFilename,LRSCode)
|
if not CodeToolBoss.SaveBufferAs(LRSCode,NewLRSFilename,LRSCode) then
|
||||||
then
|
|
||||||
DebugLn(['RenameUnit CodeToolBoss.SaveBufferAs failed: NewResFilename="',NewLRSFilename,'"']);
|
DebugLn(['RenameUnit CodeToolBoss.SaveBufferAs failed: NewResFilename="',NewLRSFilename,'"']);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user