diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index 6c405b05b6..0504d80528 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -1072,7 +1072,8 @@ function TStandardCodeTool.CommentUnitsInUsesSections(MissingUnits: TStrings; AtomIsIdentifier(true); CurUnitName:=GetAtom; i:=MissingUnits.Count-1; - while (i>=0) and (SysUtils.CompareText(MissingUnits[i],CurUnitName)<>0) do + while (i>=0) + and (CompareIdentifiers(PChar(MissingUnits[i]),PChar(CurUnitName))<>0) do dec(i); CommentCurUnit:=i>=0; //debugln('CommentUnitsInUsesSection CurUnitName="',CurUnitName,'" CommentCurUnit=',dbgs(CommentCurUnit)); diff --git a/converter/delphiproject2laz.pas b/converter/delphiproject2laz.pas index 947861d69f..221998607b 100644 --- a/converter/delphiproject2laz.pas +++ b/converter/delphiproject2laz.pas @@ -46,9 +46,9 @@ interface uses Classes, SysUtils, LCLProc, Forms, Controls, Dialogs, FileUtil, - ExprEval, CodeCache, CodeToolManager, + ExprEval, DefineTemplates, CodeCache, CodeToolManager, SrcEditorIntf, MsgIntf, MainIntf, LazIDEIntf, ProjectIntf, - DelphiUnit2Laz, Project, DialogProcs, CheckLFMDlg, + IDEProcs, DelphiUnit2Laz, Project, DialogProcs, CheckLFMDlg, EditorOptions, ProjectInspector, CompilerOptions, BasePkgManager, PkgManager; @@ -85,6 +85,9 @@ var DPRFilename: String; MainSourceFilename: String; RenameLowercase: Boolean; + NewUnitPath: String; + CurFilename: string; + p: LongInt; begin debugln('ConvertDelphiToLazarusProject ProjectFilename="',ProjectFilename,'"'); IDEMessagesWindow.Clear; @@ -162,24 +165,46 @@ begin +NotFoundUnits,mtWarning,[mrIgnore,mrAbort],0); if Result<>mrIgnore then exit; end; - + + // clean up project + Project1.RemoveNonExistingFiles(false); + // add all units to the project debugln('ConvertDelphiToLazarusProject adding all project units to project ...'); for i:=0 to FoundInUnits.Count-1 do begin CurUnitInfo:=TUnitInfo.Create(nil); - TUnitInfo(CurUnitInfo).Filename:=FoundInUnits[i]; + CurFilename:=FoundInUnits[i]; + p:=System.Pos(' in ',CurFilename); + if p>0 then + CurFilename:=copy(CurFilename,p+4,length(CurFilename)); + if CurFilename='' then continue; + if not FilenameIsAbsolute(CurFilename) then + CurFilename:=AppendPathDelim(Project1.ProjectDirectory)+CurFilename; + if not FileExists(CurFilename) then begin + DebugLn('ConvertDelphiToLazarusProject file not found: "',CurFilename,'"'); + continue; + end; + TUnitInfo(CurUnitInfo).Filename:=CurFilename; + CurUnitInfo.IsPartOfProject:=true; Project1.AddFile(CurUnitInfo,false); end; // set search paths to find all project units - Project1.CompilerOptions.OtherUnitFiles:= - Project1.SourceDirectories.CreateSearchPathFromAllFiles; + NewUnitPath:=MergeSearchPaths(Project1.CompilerOptions.OtherUnitFiles, + Project1.SourceDirectories.CreateSearchPathFromAllFiles); + NewUnitPath:=RemoveSearchPaths(NewUnitPath, + '.;'+VirtualDirectory+';'+VirtualTempDir + +';'+Project1.ProjectDirectory); + Project1.CompilerOptions.OtherUnitFiles:=NewUnitPath; DebugLn('ConvertDelphiToLazarusProject UnitPath="',Project1.CompilerOptions.OtherUnitFiles,'"'); // save project - debugln('ConvertDelphiToLazarusProject Saving new project ...'); + debugln('ConvertDelphiToLazarusProject Saving project ...'); Result:=LazarusIDE.DoSaveProject([]); - if Result<>mrOk then exit; - + if Result<>mrOk then begin + DebugLn('ConvertDelphiToLazarusProject failed saving project'); + exit; + end; + // convert all units i:=0; while imrYes then exit; // comment missing units - DebugLn('FixMissingUnits CommentUnitsInUsesSections'); + DebugLn('FixMissingUnits CommentUnitsInUsesSections ',MissingUnits.Text); CTResult:=CodeToolBoss.CommentUnitsInUsesSections(LazUnitCode,MissingUnits); if not CTResult then begin Result:=mrCancel; diff --git a/ide/ideprocs.pp b/ide/ideprocs.pp index e6e213846f..7c0323f8ce 100644 --- a/ide/ideprocs.pp +++ b/ide/ideprocs.pp @@ -131,7 +131,7 @@ function GetNextDirectoryInSearchPath(const SearchPath: string; function GetNextUsedDirectoryInSearchPath(const SearchPath, FilterDir: string; var NextStartPos: integer): string; function SearchDirectoryInSearchPath(const SearchPath, Directory: string; - DirStartPos: integer): integer; + DirStartPos: integer = 1): integer; // XMLConfig procedure LoadRecentList(XMLConfig: TXMLConfig; List: TStrings; @@ -412,6 +412,7 @@ begin EndPos:=StartPos; while (EndPos<=OldPathLen) and (SearchPath[EndPos]<>';') do inc(EndPos); + //DebugLn('RemoveSearchPaths Dir="',copy(SearchPath,StartPos,EndPos-StartPos),'" RemoveSearchPath="',RemoveSearchPath,'"'); if SearchDirectoryInSearchPath(RemoveSearchPath,SearchPath,StartPos)>0 then begin // remove path -> skip @@ -591,6 +592,7 @@ begin if DirEndPos=DirStartPos then DirEndPos:=DirStartPos+1; end; CurDirLen:=DirEndPos-DirStartPos; + //DebugLn('SearchDirectoryInSearchPath Dir="',copy(Directory,DirStartPos,CurDirLen),'"'); PathLen:=length(SearchPath); EndPos:=1; while EndPos<=PathLen do begin @@ -611,6 +613,7 @@ begin // check if it is the root path '/' if CurDirEndPos=StartPos then CurDirEndPos:=StartPos+1; end; + //DebugLn('SearchDirectoryInSearchPath CurDir="',copy(SearchPath,StartPos,CurDirEndPos-StartPos),'"'); if CurDirEndPos-StartPos=CurDirLen then begin // directories have same length -> compare chars if FileUtil.CompareFilenames(@SearchPath[StartPos],CurDirLen, diff --git a/ide/project.pp b/ide/project.pp index 305eb89c8a..9cb8a5d765 100644 --- a/ide/project.pp +++ b/ide/project.pp @@ -557,7 +557,9 @@ type function NewUniqueFilename(const Filename: string): string; procedure AddFile(ProjectFile: TLazProjectFile; AddToProjectUsesClause: boolean); override; - procedure RemoveUnit(Index: integer); override; + procedure RemoveUnit(Index: integer; + RemoveFromUsesSection: boolean = true); override; + procedure RemoveNonExistingFiles(RemoveFromUsesSection: boolean = true); function CreateProjectFile(const Filename: string): TLazProjectFile; override; // search @@ -2063,7 +2065,7 @@ end; {------------------------------------------------------------------------------ TProject RemoveUnit ------------------------------------------------------------------------------} -procedure TProject.RemoveUnit(Index: integer); +procedure TProject.RemoveUnit(Index: integer; RemoveFromUsesSection: boolean); var OldUnitInfo: TUnitInfo; begin @@ -2081,13 +2083,15 @@ begin if (MainUnitID>=0) then begin // remove unit from uses section and from createforms in program file if (OldUnitInfo.IsPartOfProject) then begin - if (OldUnitInfo.UnitName<>'') then begin - CodeToolBoss.RemoveUnitFromAllUsesSections(MainUnitInfo.Source, - OldUnitInfo.UnitName); - end; - if (OldUnitInfo.ComponentName<>'') then begin - CodeToolBoss.RemoveCreateFormStatement(MainUnitInfo.Source, - OldUnitInfo.ComponentName); + if RemoveFromUsesSection then begin + if (OldUnitInfo.UnitName<>'') then begin + CodeToolBoss.RemoveUnitFromAllUsesSections(MainUnitInfo.Source, + OldUnitInfo.UnitName); + end; + if (OldUnitInfo.ComponentName<>'') then begin + CodeToolBoss.RemoveCreateFormStatement(MainUnitInfo.Source, + OldUnitInfo.ComponentName); + end; end; end; end; @@ -2117,6 +2121,24 @@ begin Result:=AnUnitInfo; end; +procedure TProject.RemoveNonExistingFiles(RemoveFromUsesSection: boolean); +var + i: Integer; + AnUnitInfo: TUnitInfo; +begin + i:=UnitCount-1; + while (i>=0) do begin + if iMainUnitID) then begin + if not FileExists(AnUnitInfo.Filename) then + RemoveUnit(i,RemoveFromUsesSection); + end; + end; + dec(i); + end; +end; + {------------------------------------------------------------------------------ TProject Clear ------------------------------------------------------------------------------} diff --git a/ideintf/projectintf.pas b/ideintf/projectintf.pas index c71eeae0ca..8df239d2ff 100644 --- a/ideintf/projectintf.pas +++ b/ideintf/projectintf.pas @@ -529,7 +529,7 @@ type ): TLazProjectFile; virtual; abstract; procedure AddFile(ProjectFile: TLazProjectFile; AddToProjectUsesClause: boolean); virtual; abstract; - procedure RemoveUnit(Index: integer); virtual; abstract; + procedure RemoveUnit(Index: integer; RemoveFromUsesSection: boolean = true); virtual; abstract; function GetFileCount: integer; virtual; abstract; procedure AddSrcPath(const SrcPathAddition: string); virtual; abstract; procedure AddPackageDependency(const PackageName: string); virtual; abstract; diff --git a/lcl/include/fileutil.inc b/lcl/include/fileutil.inc index 0ee08f4405..5255fce026 100644 --- a/lcl/include/fileutil.inc +++ b/lcl/include/fileutil.inc @@ -86,8 +86,8 @@ begin Result:=CompareFilenames(File1,File2); end else begin Result:=0; - i:=1; - while (Result=0) and ((i<=Len1) and (i<=Len2)) do begin + i:=0; + while (Result=0) and ((i