mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 21:20:46 +02:00
Converter: Convert also units in project directory which are not part of the project. Issue #22677
git-svn-id: trunk@38903 -
This commit is contained in:
parent
b8f1a26235
commit
7d7d464100
@ -181,6 +181,7 @@ type
|
|||||||
function ExtractOptionsFromDOF(const DOFFilename: string): TModalResult;
|
function ExtractOptionsFromDOF(const DOFFilename: string): TModalResult;
|
||||||
function ExtractOptionsFromCFG(const CFGFilename: string): TModalResult;
|
function ExtractOptionsFromCFG(const CFGFilename: string): TModalResult;
|
||||||
function DoMissingUnits(AUsedUnitsTool: TUsedUnitsTool): integer; override;
|
function DoMissingUnits(AUsedUnitsTool: TUsedUnitsTool): integer; override;
|
||||||
|
function CheckPackageDependency(AUnitName: string): Boolean;
|
||||||
protected
|
protected
|
||||||
function CreateInstance: TModalResult; virtual; abstract;
|
function CreateInstance: TModalResult; virtual; abstract;
|
||||||
function CreateMainSourceFile: TModalResult; virtual;
|
function CreateMainSourceFile: TModalResult; virtual;
|
||||||
@ -202,7 +203,6 @@ type
|
|||||||
constructor Create(const AFilename, ADescription: string);
|
constructor Create(const AFilename, ADescription: string);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Convert: TModalResult;
|
function Convert: TModalResult;
|
||||||
function CheckPackageDependency(AUnitName: string): Boolean;
|
|
||||||
public
|
public
|
||||||
property CompOpts: TBaseCompilerOptions read GetCompOpts;
|
property CompOpts: TBaseCompilerOptions read GetCompOpts;
|
||||||
property CustomDefines: TDefineTemplate read GetCustomDefines;
|
property CustomDefines: TDefineTemplate read GetCustomDefines;
|
||||||
@ -218,6 +218,7 @@ type
|
|||||||
// Resource code
|
// Resource code
|
||||||
fMainUnitConverter: TDelphiUnit;
|
fMainUnitConverter: TDelphiUnit;
|
||||||
function AddUnit(AFileName: string; out OutUnitInfo: TUnitInfo): TModalResult;
|
function AddUnit(AFileName: string; out OutUnitInfo: TUnitInfo): TModalResult;
|
||||||
|
function CheckUnitForConversion(aFileName: string): Boolean;
|
||||||
function GetLazProject: TProject;
|
function GetLazProject: TProject;
|
||||||
procedure SetLazProject(const AValue: TProject);
|
procedure SetLazProject(const AValue: TProject);
|
||||||
protected
|
protected
|
||||||
@ -619,13 +620,16 @@ begin
|
|||||||
// Fix include file names.
|
// Fix include file names.
|
||||||
Result:=FixIncludeFiles;
|
Result:=FixIncludeFiles;
|
||||||
if Result<>mrOk then exit;
|
if Result<>mrOk then exit;
|
||||||
// Create a toold for missing units.
|
// Create a tool for missing units.
|
||||||
fUsedUnitsTool:=TUsedUnitsTool.Create(fCTLink, fOrigUnitFilename);
|
fUsedUnitsTool:=TUsedUnitsTool.Create(fCTLink, fOrigUnitFilename);
|
||||||
if fOwnerConverter is TConvertDelphiProjPack then
|
if fOwnerConverter is TConvertDelphiProjPack then
|
||||||
with fOwnerConverter as TConvertDelphiProjPack do begin
|
with TConvertDelphiProjPack(fOwnerConverter) do begin
|
||||||
fUsedUnitsTool.CheckPackDepEvent:=@CheckPackageDependency;
|
fUsedUnitsTool.OnCheckPackageDependency:=@CheckPackageDependency;
|
||||||
fUsedUnitsTool.IsConsoleApp:=fIsConsoleApp;
|
fUsedUnitsTool.IsConsoleApp:=fIsConsoleApp;
|
||||||
end;
|
end;
|
||||||
|
if fOwnerConverter is TConvertDelphiProject then
|
||||||
|
with TConvertDelphiProject(fOwnerConverter) do
|
||||||
|
fUsedUnitsTool.OnCheckUnitForConversion:=@CheckUnitForConversion;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDelphiUnit.FixLfmFilenameAndLoad(ADfmFilename: string): TModalResult;
|
function TDelphiUnit.FixLfmFilenameAndLoad(ADfmFilename: string): TModalResult;
|
||||||
@ -1213,30 +1217,6 @@ begin
|
|||||||
Options.SrcPath:=CleanProjectSearchPath(Options.SrcPath);
|
Options.SrcPath:=CleanProjectSearchPath(Options.SrcPath);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TConvertDelphiProjPack.CheckPackageDependency(AUnitName: string): Boolean;
|
|
||||||
var
|
|
||||||
Pack: TPkgFile;
|
|
||||||
Dep: TPkgDependency;
|
|
||||||
s: String;
|
|
||||||
begin
|
|
||||||
Result:=False;
|
|
||||||
Pack:=PackageGraph.FindUnitInAllPackages(AUnitName, True);
|
|
||||||
if Assigned(Pack) then begin
|
|
||||||
// Found from package: add package to project dependencies and open it.
|
|
||||||
s:=Pack.LazPackage.Name;
|
|
||||||
if s='LCLBase' then
|
|
||||||
s:='LCL';
|
|
||||||
AddPackageDependency(s);
|
|
||||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiAddedPackageRequirement, [s]), '', -1);
|
|
||||||
Dep:=FindDependencyByName(s);
|
|
||||||
if Assigned(Dep) then
|
|
||||||
PackageGraph.OpenDependency(Dep,false);
|
|
||||||
Result:=True;
|
|
||||||
end else begin;
|
|
||||||
// ToDo: Install the required package automatically from a repository...
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TConvertDelphiProjPack.DoMissingUnits(AUsedUnitsTool: TUsedUnitsTool): integer;
|
function TConvertDelphiProjPack.DoMissingUnits(AUsedUnitsTool: TUsedUnitsTool): integer;
|
||||||
// Locate unit names from earlier cached list or from packages.
|
// Locate unit names from earlier cached list or from packages.
|
||||||
// Return the number of units still missing.
|
// Return the number of units still missing.
|
||||||
@ -1275,6 +1255,30 @@ begin
|
|||||||
Result:=AUsedUnitsTool.MissingUnitCount;
|
Result:=AUsedUnitsTool.MissingUnitCount;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TConvertDelphiProjPack.CheckPackageDependency(AUnitName: string): Boolean;
|
||||||
|
var
|
||||||
|
Pack: TPkgFile;
|
||||||
|
Dep: TPkgDependency;
|
||||||
|
s: String;
|
||||||
|
begin
|
||||||
|
Result:=False;
|
||||||
|
Pack:=PackageGraph.FindUnitInAllPackages(AUnitName, True);
|
||||||
|
if Assigned(Pack) then begin
|
||||||
|
// Found from package: add package to project dependencies and open it.
|
||||||
|
s:=Pack.LazPackage.Name;
|
||||||
|
if s='LCLBase' then
|
||||||
|
s:='LCL';
|
||||||
|
AddPackageDependency(s);
|
||||||
|
IDEMessagesWindow.AddMsg(Format(lisConvDelphiAddedPackageRequirement, [s]), '', -1);
|
||||||
|
Dep:=FindDependencyByName(s);
|
||||||
|
if Assigned(Dep) then
|
||||||
|
PackageGraph.OpenDependency(Dep,false);
|
||||||
|
Result:=True;
|
||||||
|
end else begin;
|
||||||
|
// ToDo: Install the required package automatically from a repository...
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TConvertDelphiProjPack.CreateMainSourceFile: TModalResult;
|
function TConvertDelphiProjPack.CreateMainSourceFile: TModalResult;
|
||||||
begin
|
begin
|
||||||
Result:=mrOK; // Do nothing. Overridden in project.
|
Result:=mrOK; // Do nothing. Overridden in project.
|
||||||
@ -1444,6 +1448,21 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TConvertDelphiProject.CheckUnitForConversion(aFileName: string): Boolean;
|
||||||
|
var
|
||||||
|
UnitInfo: TUnitInfo;
|
||||||
|
Path: string;
|
||||||
|
begin
|
||||||
|
// Units in project directory but not part of the project are not reported
|
||||||
|
// as missing and would not be converted. Now add them to the project.
|
||||||
|
if ExtractFilePath(aFileName)=LazProject.ProjectDirectory then begin
|
||||||
|
UnitInfo:=LazProject.UnitInfoWithFilename(aFileName);
|
||||||
|
Result:=Assigned(UnitInfo);
|
||||||
|
if not Result then
|
||||||
|
fUnitsToAddToProject.Add(aFileName); // Will be added later to project.
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TConvertDelphiProject.FindAllUnits: TModalResult;
|
function TConvertDelphiProject.FindAllUnits: TModalResult;
|
||||||
var
|
var
|
||||||
FoundUnits, MisUnits, NormalUnits: TStrings;
|
FoundUnits, MisUnits, NormalUnits: TStrings;
|
||||||
@ -1523,7 +1542,7 @@ var
|
|||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
ConvUnits:=TObjectList.create;
|
ConvUnits:=TObjectList.Create;
|
||||||
try
|
try
|
||||||
// convert all units and fix .lfm files
|
// convert all units and fix .lfm files
|
||||||
IDEMessagesWindow.AddMsg(lisConvDelphiConvertingUnitFiles, '', -1);
|
IDEMessagesWindow.AddMsg(lisConvDelphiConvertingUnitFiles, '', -1);
|
||||||
|
@ -117,7 +117,8 @@ type
|
|||||||
fIsConsoleApp: Boolean;
|
fIsConsoleApp: Boolean;
|
||||||
fMainUsedUnits: TUsedUnits;
|
fMainUsedUnits: TUsedUnits;
|
||||||
fImplUsedUnits: TUsedUnits;
|
fImplUsedUnits: TUsedUnits;
|
||||||
fCheckPackageDependencyEvent: TCheckUnitEvent;
|
fOnCheckPackageDependency: TCheckUnitEvent;
|
||||||
|
fOnCheckUnitForConversion: TCheckUnitEvent;
|
||||||
function GetMissingUnitCount: integer;
|
function GetMissingUnitCount: integer;
|
||||||
public
|
public
|
||||||
constructor Create(ACTLink: TCodeToolLink; AFilename: string);
|
constructor Create(ACTLink: TCodeToolLink; AFilename: string);
|
||||||
@ -134,8 +135,10 @@ type
|
|||||||
property MainUsedUnits: TUsedUnits read fMainUsedUnits;
|
property MainUsedUnits: TUsedUnits read fMainUsedUnits;
|
||||||
property ImplUsedUnits: TUsedUnits read fImplUsedUnits;
|
property ImplUsedUnits: TUsedUnits read fImplUsedUnits;
|
||||||
property MissingUnitCount: integer read GetMissingUnitCount;
|
property MissingUnitCount: integer read GetMissingUnitCount;
|
||||||
property CheckPackDepEvent: TCheckUnitEvent read fCheckPackageDependencyEvent
|
property OnCheckPackageDependency: TCheckUnitEvent
|
||||||
write fCheckPackageDependencyEvent;
|
read fOnCheckPackageDependency write fOnCheckPackageDependency;
|
||||||
|
property OnCheckUnitForConversion: TCheckUnitEvent
|
||||||
|
read fOnCheckUnitForConversion write fOnCheckUnitForConversion;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -233,8 +236,8 @@ begin
|
|||||||
if AFilename<>'' then begin // unit found
|
if AFilename<>'' then begin // unit found
|
||||||
if (NewUnitName<>OldUnitName) and not Settings.OmitProjUnits.Find(NewUnitName,x)
|
if (NewUnitName<>OldUnitName) and not Settings.OmitProjUnits.Find(NewUnitName,x)
|
||||||
then begin
|
then begin
|
||||||
// Character case differs and it will not be replaced.
|
// Character case differs, fix it.
|
||||||
fUnitsToFixCase[OldUnitName]:=NewUnitName; // fix case
|
fUnitsToFixCase[OldUnitName]:=NewUnitName;
|
||||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiFixedUnitCase,
|
IDEMessagesWindow.AddMsg(Format(lisConvDelphiFixedUnitCase,
|
||||||
[OldUnitName, NewUnitName]), '', -1);
|
[OldUnitName, NewUnitName]), '', -1);
|
||||||
end;
|
end;
|
||||||
@ -242,6 +245,9 @@ begin
|
|||||||
// Needed if work-platform is Windows (kind of a hack).
|
// Needed if work-platform is Windows (kind of a hack).
|
||||||
if Settings.MultiPlatform and IsWinSpecificUnit(LowNU) then
|
if Settings.MultiPlatform and IsWinSpecificUnit(LowNU) then
|
||||||
fMissingUnits.Add(s);
|
fMissingUnits.Add(s);
|
||||||
|
// Check if the unit is not part of project and needs conversion, too.
|
||||||
|
if Assigned(fOwnerTool.OnCheckUnitForConversion) then
|
||||||
|
fOwnerTool.OnCheckUnitForConversion(AFilename);
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
// If the unit is not found, add it to fMissingUnits, but don't add
|
// If the unit is not found, add it to fMissingUnits, but don't add
|
||||||
@ -277,8 +283,8 @@ begin
|
|||||||
// If the unit is not found, open the package containing it.
|
// If the unit is not found, open the package containing it.
|
||||||
UnitInFileName:='';
|
UnitInFileName:='';
|
||||||
if fCTLink.CodeTool.FindUnitCaseInsensitive(ANewName,UnitInFileName) = '' then
|
if fCTLink.CodeTool.FindUnitCaseInsensitive(ANewName,UnitInFileName) = '' then
|
||||||
if Assigned(fOwnerTool.CheckPackDepEvent) then
|
if Assigned(fOwnerTool.OnCheckPackageDependency) then
|
||||||
if not fOwnerTool.CheckPackDepEvent(ANewName) then
|
if not fOwnerTool.OnCheckPackageDependency(ANewName) then
|
||||||
;
|
;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
@ -686,8 +692,8 @@ begin
|
|||||||
// If the unit is not found, open the package containing it.
|
// If the unit is not found, open the package containing it.
|
||||||
UnitInFileName:='';
|
UnitInFileName:='';
|
||||||
if fCTLink.CodeTool.FindUnitCaseInsensitive(AUnitName,UnitInFileName) = '' then
|
if fCTLink.CodeTool.FindUnitCaseInsensitive(AUnitName,UnitInFileName) = '' then
|
||||||
if Assigned(fCheckPackageDependencyEvent) then
|
if Assigned(fOnCheckPackageDependency) then
|
||||||
if not fCheckPackageDependencyEvent(AUnitName) then
|
if not fOnCheckPackageDependency(AUnitName) then
|
||||||
;
|
;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user