IDE: when package is renamed, rename its build macros

git-svn-id: trunk@27465 -
This commit is contained in:
mattias 2010-09-26 10:34:13 +00:00
parent e52d954696
commit 5e87400d8c
8 changed files with 280 additions and 103 deletions

View File

@ -238,6 +238,8 @@ type
procedure WriteDebugReportStack(Title: string); procedure WriteDebugReportStack(Title: string);
end; end;
procedure RenameCTCSVariable(var Src: string; const OldName, NewName: string);
function CompareCTCSVariables(Var1, Var2: Pointer): integer; function CompareCTCSVariables(Var1, Var2: Pointer): integer;
function ComparePCharWithCTCSVariableName(Name, aVar: Pointer): integer; function ComparePCharWithCTCSVariableName(Name, aVar: Pointer): integer;
function AreCTCSVariablesEqual(const V1, V2: PCTCfgScriptVariable): Boolean; function AreCTCSVariablesEqual(const V1, V2: PCTCfgScriptVariable): Boolean;
@ -272,6 +274,30 @@ function dbgs(const V: PCTCfgScriptVariable): string; overload;
implementation implementation
procedure RenameCTCSVariable(var Src: string; const OldName, NewName: string);
var
p: PChar;
AtomStart: PChar;
SrcPos: PtrUInt;
begin
if (Src='') or (OldName='') or (not IsValidIdent(OldName))
or (NewName='') then exit;
p:=PChar(Src);
//debugln(['RenameCTCSVariable START ',dbgstr(Src)]);
repeat
ReadRawNextPascalAtom(p,AtomStart);
if (p=AtomStart) then break;
if IsIdentStartChar[AtomStart^]
and (CompareIdentifierPtrs(PChar(OldName),AtomStart)=0)
then begin
SrcPos:=PtrUInt(AtomStart-PChar(Src))+1;
Src:=copy(Src,1,SrcPos-1)+NewName+copy(Src,SrcPos+length(OldName),length(Src));
p:=@Src[SrcPos]+length(NewName);
end;
until false;
//debugln(['RenameCTCSVariable END ',dbgstr(Src)]);
end;
function CompareCTCSVariables(Var1, Var2: Pointer): integer; function CompareCTCSVariables(Var1, Var2: Pointer): integer;
var var
v1: PCTCfgScriptVariable absolute Var1; v1: PCTCfgScriptVariable absolute Var1;

View File

@ -77,13 +77,19 @@
- show build macros in inherited compiler options - show build macros in inherited compiler options
- use syntax highlighter settings like the editor previews - use syntax highlighter settings like the editor previews
- show syntax errors of conditionals - show syntax errors of conditionals
- when package is renamed, rename macros too
ToDo: ToDo:
- code completion - warn for macro name conflicts
- when package is renamed, rename macros too - IDE macros like CompPath
- move the project target file to compiler options - move the project target file to compiler options
- discuss captions - discuss captions
- resourcestrings - resourcestrings
- make synedit a package
- make IDEIntf a package
- make LCL a package
- make FCL a package
- code completion
- a project can save the set of build macros and compiler options - a project can save the set of build macros and compiler options
- add changestamp, assign, equals to compiler options - add changestamp, assign, equals to compiler options
- refactor compiler options (default options, load, save to file) - refactor compiler options (default options, load, save to file)
@ -349,6 +355,8 @@ type
procedure Clear; procedure Clear;
procedure InvalidateAll; procedure InvalidateAll;
procedure InvalidateFiles; procedure InvalidateFiles;
procedure RenameMacro(const OldName, NewName: string;
out Changed: TParsedCompilerOptStrings); // rename macro in UnparsedValues
public public
property Owner: TObject read FOwner; property Owner: TObject read FOwner;
property OnLocalSubstitute: TLocalSubstitutionEvent read FOnLocalSubstitute property OnLocalSubstitute: TLocalSubstitutionEvent read FOnLocalSubstitute
@ -467,7 +475,6 @@ type
TBaseCompilerOptions = class(TLazCompilerOptions) TBaseCompilerOptions = class(TLazCompilerOptions)
private private
FBaseDirectory: string;
FDefaultMakeOptionsFlags: TCompilerCmdLineOptions; FDefaultMakeOptionsFlags: TCompilerCmdLineOptions;
fInheritedOptions: TInheritedCompOptsParseTypesStrings; fInheritedOptions: TInheritedCompOptsParseTypesStrings;
fInheritedOptParseStamps: integer; fInheritedOptParseStamps: integer;
@ -480,7 +487,6 @@ type
FXMLConfig: TXMLConfig; FXMLConfig: TXMLConfig;
// Compilation // Compilation
fCompilerPath: String;
fExecuteBefore: TCompilationToolOptions; fExecuteBefore: TCompilationToolOptions;
fExecuteAfter: TCompilationToolOptions; fExecuteAfter: TCompilationToolOptions;
FCreateMakefileOnBuild: boolean; FCreateMakefileOnBuild: boolean;
@ -489,10 +495,20 @@ type
fUseCustomMessages: Boolean; // use messages customization fUseCustomMessages: Boolean; // use messages customization
fUseMsgFile: Boolean; // use specified file for messages fUseMsgFile: Boolean; // use specified file for messages
fMsgFileName: String; // messages file name fMsgFileName: String; // messages file name
fCompilerMessages: TCompilerMessagesList; fCompilerMessages: TCompilerMessagesList;
protected protected
procedure SetBaseDirectory(const AValue: string); override; function GetCompilerPath: String;
function GetBaseDirectory: string;
function GetCustomOptions: string; override;
function GetDebugPath: string; override;
function GetIncludePaths: String; override;
function GetLibraryPaths: String; override;
function GetObjectPath: string; override;
function GetSrcPath: string; override;
function GetUnitOutputDir: string; override;
function GetUnitPaths: String; override;
procedure SetBaseDirectory(const AValue: string);
procedure SetCompilerPath(const AValue: String); override; procedure SetCompilerPath(const AValue: String); override;
procedure SetConditionals(const AValue: string); override; procedure SetConditionals(const AValue: string); override;
procedure SetCustomOptions(const AValue: string); override; procedure SetCustomOptions(const AValue: string); override;
@ -590,13 +606,16 @@ type
RelativeToBaseDir: boolean): string; RelativeToBaseDir: boolean): string;
function ShortenPath(const SearchPath: string; function ShortenPath(const SearchPath: string;
MakeAlwaysRelative: boolean): string; MakeAlwaysRelative: boolean): string;
function GetCustomOptions(Parsed: TCompilerOptionsParseType = coptParsed): string; function GetCustomOptions(Parsed: TCompilerOptionsParseType): string;
function GetOptionsForCTDefines: string; function GetOptionsForCTDefines: string;
function GetEffectiveLCLWidgetType: string; virtual; function GetEffectiveLCLWidgetType: string; virtual;
procedure RenameMacro(const OldName, NewName: string;
ChangeConditionals: boolean); virtual; // rename macro in paths and options, not in BuildMacros, not in dependencies
public public
// Properties // Properties
property ParsedOpts: TParsedCompilerOptions read FParsedOpts; property ParsedOpts: TParsedCompilerOptions read FParsedOpts;
property BaseDirectory: string read FBaseDirectory write SetBaseDirectory; property BaseDirectory: string read GetBaseDirectory write SetBaseDirectory;
property DefaultMakeOptionsFlags: TCompilerCmdLineOptions property DefaultMakeOptionsFlags: TCompilerCmdLineOptions
read FDefaultMakeOptionsFlags write SetDefaultMakeOptionsFlags; read FDefaultMakeOptionsFlags write SetDefaultMakeOptionsFlags;
@ -606,7 +625,7 @@ type
property StorePathDelim: TPathDelimSwitch read FStorePathDelim write FStorePathDelim; property StorePathDelim: TPathDelimSwitch read FStorePathDelim write FStorePathDelim;
// compilation // compilation
property CompilerPath: String read fCompilerPath write SetCompilerPath; property CompilerPath: String read GetCompilerPath write SetCompilerPath;
property ExecuteBefore: TCompilationToolOptions read fExecuteBefore; property ExecuteBefore: TCompilationToolOptions read fExecuteBefore;
property ExecuteAfter: TCompilationToolOptions read fExecuteAfter; property ExecuteAfter: TCompilationToolOptions read fExecuteAfter;
property CreateMakefileOnBuild: boolean read FCreateMakefileOnBuild property CreateMakefileOnBuild: boolean read FCreateMakefileOnBuild
@ -1129,17 +1148,14 @@ var
NewValue: String; NewValue: String;
begin begin
NewValue:=ShortenPath(AValue,false); NewValue:=ShortenPath(AValue,false);
if NewValue<>AValue then if IncludePath=NewValue then exit;
if fIncludePaths=NewValue then exit; ParsedOpts.SetUnparsedValue(pcosIncludePath,NewValue);
fIncludePaths:=NewValue;
ParsedOpts.SetUnparsedValue(pcosIncludePath,fIncludePaths);
end; end;
procedure TBaseCompilerOptions.SetCompilerPath(const AValue: String); procedure TBaseCompilerOptions.SetCompilerPath(const AValue: String);
begin begin
if fCompilerPath=AValue then exit; if CompilerPath=AValue then exit;
fCompilerPath:=AValue; ParsedOpts.SetUnparsedValue(pcosCompilerPath,AValue);
ParsedOpts.SetUnparsedValue(pcosCompilerPath,fCompilerPath);
end; end;
procedure TBaseCompilerOptions.SetConditionals(const AValue: string); procedure TBaseCompilerOptions.SetConditionals(const AValue: string);
@ -1161,9 +1177,8 @@ var
NewValue: String; NewValue: String;
begin begin
NewValue:=ShortenPath(AValue,false); NewValue:=ShortenPath(AValue,false);
if FSrcPath=NewValue then exit; if SrcPath=NewValue then exit;
FSrcPath:=NewValue; ParsedOpts.SetUnparsedValue(pcosSrcPath,NewValue);
ParsedOpts.SetUnparsedValue(pcosSrcPath,FSrcPath);
end; end;
procedure TBaseCompilerOptions.SetDebugPath(const AValue: string); procedure TBaseCompilerOptions.SetDebugPath(const AValue: string);
@ -1171,9 +1186,8 @@ var
NewValue: String; NewValue: String;
begin begin
NewValue:=ShortenPath(AValue,false); NewValue:=ShortenPath(AValue,false);
if fDebugPath=NewValue then exit; if DebugPath=NewValue then exit;
fDebugPath:=NewValue; ParsedOpts.SetUnparsedValue(pcosDebugPath,NewValue);
ParsedOpts.SetUnparsedValue(pcosDebugPath,fDebugPath);
end; end;
procedure TBaseCompilerOptions.SetTargetCPU(const AValue: string); procedure TBaseCompilerOptions.SetTargetCPU(const AValue: string);
@ -1204,18 +1218,66 @@ begin
Modified:=true; Modified:=true;
end; end;
function TBaseCompilerOptions.GetCompilerPath: String;
begin
Result:=ParsedOpts.UnparsedValues[pcosCompilerPath];
end;
function TBaseCompilerOptions.GetBaseDirectory: string;
begin
Result:=ParsedOpts.UnparsedValues[pcosBaseDir];
end;
function TBaseCompilerOptions.GetCustomOptions: string;
begin
Result:=ParsedOpts.UnparsedValues[pcosCustomOptions];
end;
function TBaseCompilerOptions.GetDebugPath: string;
begin
Result:=ParsedOpts.UnparsedValues[pcosDebugPath];
end;
function TBaseCompilerOptions.GetIncludePaths: String;
begin
Result:=ParsedOpts.UnparsedValues[pcosIncludePath];
end;
function TBaseCompilerOptions.GetLibraryPaths: String;
begin
Result:=ParsedOpts.UnparsedValues[pcosLibraryPath];
end;
function TBaseCompilerOptions.GetObjectPath: string;
begin
Result:=ParsedOpts.UnparsedValues[pcosObjectPath];
end;
function TBaseCompilerOptions.GetSrcPath: string;
begin
Result:=ParsedOpts.UnparsedValues[pcosSrcPath];
end;
function TBaseCompilerOptions.GetUnitOutputDir: string;
begin
Result:=ParsedOpts.UnparsedValues[pcosOutputDir];
end;
function TBaseCompilerOptions.GetUnitPaths: String;
begin
Result:=ParsedOpts.UnparsedValues[pcosUnitPath];
end;
procedure TBaseCompilerOptions.SetBaseDirectory(const AValue: string); procedure TBaseCompilerOptions.SetBaseDirectory(const AValue: string);
begin begin
if FBaseDirectory=AValue then exit; if BaseDirectory=AValue then exit;
FBaseDirectory:=AValue; ParsedOpts.SetUnparsedValue(pcosBaseDir,AValue);
ParsedOpts.SetUnparsedValue(pcosBaseDir,FBaseDirectory);
end; end;
procedure TBaseCompilerOptions.SetCustomOptions(const AValue: string); procedure TBaseCompilerOptions.SetCustomOptions(const AValue: string);
begin begin
if fCustomOptions=AValue then exit; if CustomOptions=AValue then exit;
fCustomOptions:=AValue; ParsedOpts.SetUnparsedValue(pcosCustomOptions,AValue);
ParsedOpts.SetUnparsedValue(pcosCustomOptions,fCustomOptions);
end; end;
procedure TBaseCompilerOptions.SetLibraryPaths(const AValue: String); procedure TBaseCompilerOptions.SetLibraryPaths(const AValue: String);
@ -1223,16 +1285,14 @@ var
NewValue: String; NewValue: String;
begin begin
NewValue:=ShortenPath(AValue,false); NewValue:=ShortenPath(AValue,false);
if fLibraryPaths=NewValue then exit; if Libraries=NewValue then exit;
fLibraryPaths:=NewValue; ParsedOpts.SetUnparsedValue(pcosLibraryPath,NewValue);
ParsedOpts.SetUnparsedValue(pcosLibraryPath,fLibraryPaths);
end; end;
procedure TBaseCompilerOptions.SetLinkerOptions(const AValue: String); procedure TBaseCompilerOptions.SetLinkerOptions(const AValue: String);
begin begin
if fLinkerOptions=AValue then exit; if LinkerOptions=AValue then exit;
fLinkerOptions:=AValue; ParsedOpts.SetUnparsedValue(pcosLinkerOptions,AValue);
ParsedOpts.SetUnparsedValue(pcosLinkerOptions,fLinkerOptions);
end; end;
procedure TBaseCompilerOptions.SetUnitPaths(const AValue: String); procedure TBaseCompilerOptions.SetUnitPaths(const AValue: String);
@ -1240,16 +1300,14 @@ var
NewValue: String; NewValue: String;
begin begin
NewValue:=ShortenPath(AValue,false); NewValue:=ShortenPath(AValue,false);
if fUnitPaths=NewValue then exit; if OtherUnitFiles=NewValue then exit;
fUnitPaths:=NewValue; ParsedOpts.SetUnparsedValue(pcosUnitPath,NewValue);
ParsedOpts.SetUnparsedValue(pcosUnitPath,fUnitPaths);
end; end;
procedure TBaseCompilerOptions.SetUnitOutputDir(const AValue: string); procedure TBaseCompilerOptions.SetUnitOutputDir(const AValue: string);
begin begin
if fUnitOutputDir=AValue then exit; if UnitOutputDirectory=AValue then exit;
fUnitOutputDir:=AValue; ParsedOpts.SetUnparsedValue(pcosOutputDir,AValue);
ParsedOpts.SetUnparsedValue(pcosOutputDir,fUnitOutputDir);
end; end;
procedure TBaseCompilerOptions.SetObjectPath(const AValue: string); procedure TBaseCompilerOptions.SetObjectPath(const AValue: string);
@ -1257,9 +1315,8 @@ var
NewValue: String; NewValue: String;
begin begin
NewValue:=ShortenPath(AValue,false); NewValue:=ShortenPath(AValue,false);
if FObjectPath=NewValue then exit; if ObjectPath=NewValue then exit;
FObjectPath:=NewValue; ParsedOpts.SetUnparsedValue(pcosObjectPath,NewValue);
ParsedOpts.SetUnparsedValue(pcosObjectPath,FObjectPath);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -2058,8 +2115,8 @@ begin
{$ENDIF} {$ENDIF}
end; end;
function TBaseCompilerOptions.GetCustomOptions(Parsed: TCompilerOptionsParseType function TBaseCompilerOptions.GetCustomOptions(
): string; Parsed: TCompilerOptionsParseType): string;
var var
CurCustomOptions: String; CurCustomOptions: String;
InhCustomOptions: String; InhCustomOptions: String;
@ -2107,6 +2164,24 @@ begin
Result:= LCLPlatformDirNames[GetDefaultLCLWidgetType]; Result:= LCLPlatformDirNames[GetDefaultLCLWidgetType];
end; end;
procedure TBaseCompilerOptions.RenameMacro(const OldName, NewName: string;
ChangeConditionals: boolean);
var
Changed: TParsedCompilerOptStrings;
s: String;
begin
ParsedOpts.RenameMacro(OldName,NewName,Changed);
if Changed<>[] then begin
end;
if ChangeConditionals then
begin
s:=Conditionals;
RenameCTCSVariable(s,OldName,NewName);
Conditionals:=s;
end;
end;
function TBaseCompilerOptions.ShortenPath(const SearchPath: string; function TBaseCompilerOptions.ShortenPath(const SearchPath: string;
MakeAlwaysRelative: boolean): string; MakeAlwaysRelative: boolean): string;
begin begin
@ -2749,7 +2824,7 @@ begin
end; end;
// custom options // custom options
CurCustomOptions:=GetCustomOptions; CurCustomOptions:=GetCustomOptions(coptParsed);
if CurCustomOptions<>'' then if CurCustomOptions<>'' then
switches := switches+' '+CurCustomOptions; switches := switches+' '+CurCustomOptions;
@ -2956,11 +3031,11 @@ begin
// Search Paths // Search Paths
StorePathDelim := CompOpts.StorePathDelim; StorePathDelim := CompOpts.StorePathDelim;
IncludePath := CompOpts.fIncludePaths; IncludePath := CompOpts.IncludePath;
Libraries := CompOpts.fLibraryPaths; Libraries := CompOpts.Libraries;
OtherUnitFiles := CompOpts.fUnitPaths; OtherUnitFiles := CompOpts.OtherUnitFiles;
UnitOutputDirectory := CompOpts.fUnitOutputDir; UnitOutputDirectory := CompOpts.UnitOutputDirectory;
ObjectPath := CompOpts.FObjectPath; ObjectPath := CompOpts.ObjectPath;
SrcPath := CompOpts.SrcPath; SrcPath := CompOpts.SrcPath;
DebugPath := CompOpts.DebugPath; DebugPath := CompOpts.DebugPath;
@ -3039,10 +3114,10 @@ begin
fDontUseConfigFile := CompOpts.fDontUseConfigFile; fDontUseConfigFile := CompOpts.fDontUseConfigFile;
fCustomConfigFile := CompOpts.fCustomConfigFile; fCustomConfigFile := CompOpts.fCustomConfigFile;
fConfigFilePath := CompOpts.fConfigFilePath; fConfigFilePath := CompOpts.fConfigFilePath;
CustomOptions := CompOpts.fCustomOptions; CustomOptions := CompOpts.CustomOptions;
// compilation // compilation
CompilerPath := CompOpts.fCompilerPath; CompilerPath := CompOpts.CompilerPath;
ExecuteBefore.Assign(CompOpts.ExecuteBefore); ExecuteBefore.Assign(CompOpts.ExecuteBefore);
ExecuteAfter.Assign(CompOpts.ExecuteAfter); ExecuteAfter.Assign(CompOpts.ExecuteAfter);
CreateMakefileOnBuild:=CompOpts.CreateMakefileOnBuild; CreateMakefileOnBuild:=CompOpts.CreateMakefileOnBuild;
@ -3088,13 +3163,13 @@ begin
// search paths // search paths
Tool.Path:='Paths'; Tool.Path:='Paths';
Tool.AddPathsDiff('IncludePaths',fIncludePaths,CompOpts.fIncludePaths); Tool.AddPathsDiff('IncludePaths',IncludePath,CompOpts.IncludePath);
Tool.AddPathsDiff('LibraryPaths',fLibraryPaths,CompOpts.fLibraryPaths); Tool.AddPathsDiff('LibraryPaths',Libraries,CompOpts.Libraries);
Tool.AddPathsDiff('UnitPaths',fUnitPaths,CompOpts.fUnitPaths); Tool.AddPathsDiff('UnitPaths',OtherUnitFiles,CompOpts.OtherUnitFiles);
Tool.AddPathsDiff('UnitOutputDir',fUnitOutputDir,CompOpts.fUnitOutputDir); Tool.AddPathsDiff('UnitOutputDir',UnitOutputDirectory,CompOpts.UnitOutputDirectory);
Tool.AddPathsDiff('ObjectPath',FObjectPath,CompOpts.FObjectPath); Tool.AddPathsDiff('ObjectPath',ObjectPath,CompOpts.ObjectPath);
Tool.AddPathsDiff('SrcPath',FSrcPath,CompOpts.FSrcPath); Tool.AddPathsDiff('SrcPath',SrcPath,CompOpts.SrcPath);
Tool.AddPathsDiff('DebugPath',fDebugPath,CompOpts.fDebugPath); Tool.AddPathsDiff('DebugPath',DebugPath,CompOpts.DebugPath);
// conditionals // conditionals
Tool.AddPathsDiff('Conditionals',FConditionals,CompOpts.FConditionals); Tool.AddPathsDiff('Conditionals',FConditionals,CompOpts.FConditionals);
@ -3186,11 +3261,11 @@ begin
Tool.AddDiff('CustomConfigFile',fCustomConfigFile,CompOpts.fCustomConfigFile); Tool.AddDiff('CustomConfigFile',fCustomConfigFile,CompOpts.fCustomConfigFile);
Tool.AddDiff('ConfigFilePath',fConfigFilePath,CompOpts.fConfigFilePath); Tool.AddDiff('ConfigFilePath',fConfigFilePath,CompOpts.fConfigFilePath);
Tool.AddDiff('StopAfterErrCount',fStopAfterErrCount,CompOpts.fStopAfterErrCount); Tool.AddDiff('StopAfterErrCount',fStopAfterErrCount,CompOpts.fStopAfterErrCount);
Tool.AddDiff('CustomOptions',fCustomOptions,CompOpts.fCustomOptions); Tool.AddDiff('CustomOptions',CustomOptions,CompOpts.CustomOptions);
// compilation // compilation
Tool.Path:='Compilation'; Tool.Path:='Compilation';
Tool.AddDiff('CompilerPath',fCompilerPath,CompOpts.fCompilerPath); Tool.AddDiff('CompilerPath',CompilerPath,CompOpts.CompilerPath);
ExecuteBefore.CreateDiff(CompOpts.ExecuteBefore,Tool); ExecuteBefore.CreateDiff(CompOpts.ExecuteBefore,Tool);
ExecuteAfter.CreateDiff(CompOpts.ExecuteAfter,Tool); ExecuteAfter.CreateDiff(CompOpts.ExecuteAfter,Tool);
Tool.AddDiff('CreateMakefileOnBuild',fCreateMakefileOnBuild,CompOpts.fCreateMakefileOnBuild); Tool.AddDiff('CreateMakefileOnBuild',fCreateMakefileOnBuild,CompOpts.fCreateMakefileOnBuild);
@ -3620,6 +3695,24 @@ begin
end; end;
end; end;
procedure TParsedCompilerOptions.RenameMacro(const OldName, NewName: string;
out Changed: TParsedCompilerOptStrings);
var
o: TParsedCompilerOptString;
s: String;
begin
Changed:=[];
for o:=Low(UnparsedValues) to High(UnparsedValues) do
begin
s:=UnparsedValues[o];
RenameIDEMacroInString(s,OldName,NewName);
if s<>UnparsedValues[o] then begin
SetUnparsedValue(o,s);
Include(Changed,o)
end;
end;
end;
{ TCompilationToolOptions } { TCompilationToolOptions }
procedure TCompilationToolOptions.Clear; procedure TCompilationToolOptions.Clear;

View File

@ -352,7 +352,8 @@ begin
// custom options ----------------------------------------------------------- // custom options -----------------------------------------------------------
CustomOpts:=CodeToolBoss.DefinePool.CreateFPCCommandLineDefines( CustomOpts:=CodeToolBoss.DefinePool.CreateFPCCommandLineDefines(
FPCCmdLineDefTemplName,CompOpts.GetCustomOptions,RecursiveDefines,nil); FPCCmdLineDefTemplName,CompOpts.GetCustomOptions(coptParsed),
RecursiveDefines,nil);
if CustomOpts<>nil then begin if CustomOpts<>nil then begin
ParentTemplate.ReplaceChild(CustomOpts); ParentTemplate.ReplaceChild(CustomOpts);
end else begin end else begin

View File

@ -46,6 +46,7 @@ var
// the global IDE values // the global IDE values
IDEMacros: TIDEMacros = nil; // set by the IDE IDEMacros: TIDEMacros = nil; // set by the IDE
procedure RenameIDEMacroInString(var s: string; const OldName, NewName: string);
implementation implementation
@ -54,6 +55,40 @@ const
MinStamp = -$7fffffff; MinStamp = -$7fffffff;
InvalidStamp = MinStamp-1; InvalidStamp = MinStamp-1;
procedure RenameIDEMacroInString(var s: string; const OldName, NewName: string);
var
p: Integer;
Macro1: String;
Macro2: String;
procedure Replace(const OldValue, NewValue: string);
begin
s:=copy(s,1,p-1)+NewValue+copy(s,p+length(OldValue),length(s));
inc(p,length(NewValue));
end;
begin
Macro1:='$('+OldName+')';
Macro2:='$'+OldName+'(';
p:=1;
while (p<length(s)) do
begin
if (s[p]<>'$') then
inc(p) // skip normal character
else if (s[p+1]='$') then
inc(p,2) // skip $$
else begin
// macro at p found
if SysUtils.CompareText(Macro1,copy(s,p,length(Macro1)))=0 then
Replace(Macro1,'$('+NewName+')')
else if SysUtils.CompareText(Macro2,copy(s,p,length(Macro1)))=0 then
Replace(Macro2,'$'+NewName+'(')
else
inc(p);
end;
end;
end;
{ TIDEMacros } { TIDEMacros }
procedure TIDEMacros.IncreaseBaseStamp; procedure TIDEMacros.IncreaseBaseStamp;

View File

@ -127,13 +127,6 @@ type
FModified: boolean; FModified: boolean;
// Paths: // Paths:
fIncludePaths: String;
fLibraryPaths: String;
fUnitPaths: String;
FObjectPath: string;
FSrcPath: string;
fUnitOutputDir: string;
fDebugPath: string;
// conditionals / build modes // conditionals / build modes
FConditionals: string; FConditionals: string;
@ -215,25 +208,31 @@ type
fDontUseConfigFile: Boolean; fDontUseConfigFile: Boolean;
fCustomConfigFile: Boolean; fCustomConfigFile: Boolean;
fConfigFilePath: String; fConfigFilePath: String;
fCustomOptions: string;
protected protected
procedure SetBaseDirectory(const AValue: string); virtual; abstract; function GetCustomOptions: string; virtual; abstract;
function GetDebugPath: string; virtual; abstract;
function GetIncludePaths: String; virtual; abstract;
function GetLibraryPaths: String; virtual; abstract;
function GetObjectPath: string; virtual; abstract;
function GetSrcPath: string; virtual; abstract;
function GetUnitOutputDir: string; virtual; abstract;
function GetUnitPaths: String; virtual; abstract;
procedure SetCompilerPath(const AValue: String); virtual; abstract; procedure SetCompilerPath(const AValue: String); virtual; abstract;
procedure SetConditionals(const AValue: string); virtual; abstract; procedure SetConditionals(const AValue: string); virtual; abstract;
procedure SetCustomOptions(const AValue: string); virtual; abstract; procedure SetCustomOptions(const AValue: string); virtual; abstract;
procedure SetDebugPath(const AValue: string); virtual; abstract;
procedure SetIncludePaths(const AValue: String); virtual; abstract; procedure SetIncludePaths(const AValue: String); virtual; abstract;
procedure SetLibraryPaths(const AValue: String); virtual; abstract; procedure SetLibraryPaths(const AValue: String); virtual; abstract;
procedure SetLinkerOptions(const AValue: String); virtual; abstract; procedure SetLinkerOptions(const AValue: String); virtual; abstract;
procedure SetUnitPaths(const AValue: String); virtual; abstract; procedure SetModified(const AValue: boolean); virtual; abstract;
procedure SetUnitOutputDir(const AValue: string); virtual; abstract;
procedure SetObjectPath(const AValue: string); virtual; abstract; procedure SetObjectPath(const AValue: string); virtual; abstract;
procedure SetSrcPath(const AValue: string); virtual; abstract; procedure SetSrcPath(const AValue: string); virtual; abstract;
procedure SetDebugPath(const AValue: string); virtual; abstract;
procedure SetTargetCPU(const AValue: string); virtual; abstract; procedure SetTargetCPU(const AValue: string); virtual; abstract;
procedure SetTargetProc(const AValue: string); virtual; abstract;
procedure SetTargetOS(const AValue: string); virtual; abstract;
procedure SetTargetFilename(const AValue: String); virtual; abstract; procedure SetTargetFilename(const AValue: String); virtual; abstract;
procedure SetModified(const AValue: boolean); virtual; abstract; procedure SetTargetOS(const AValue: string); virtual; abstract;
procedure SetTargetProc(const AValue: string); virtual; abstract;
procedure SetUnitOutputDir(const AValue: string); virtual; abstract;
procedure SetUnitPaths(const AValue: String); virtual; abstract;
public public
constructor Create(const TheOwner: TObject); virtual; constructor Create(const TheOwner: TObject); virtual;
public public
@ -242,13 +241,13 @@ type
property OnModified: TNotifyEvent read FOnModified write FOnModified; property OnModified: TNotifyEvent read FOnModified write FOnModified;
// search paths: // search paths:
property IncludePath: String read fIncludePaths write SetIncludePaths; property IncludePath: String read GetIncludePaths write SetIncludePaths;
property Libraries: String read fLibraryPaths write SetLibraryPaths; property Libraries: String read GetLibraryPaths write SetLibraryPaths;
property OtherUnitFiles: String read fUnitPaths write SetUnitPaths; property OtherUnitFiles: String read GetUnitPaths write SetUnitPaths;
property ObjectPath: string read FObjectPath write SetObjectPath; property ObjectPath: string read GetObjectPath write SetObjectPath;
property SrcPath: string read FSrcPath write SetSrcPath; property SrcPath: string read GetSrcPath write SetSrcPath;
property DebugPath: string read FDebugPath write SetDebugPath; property DebugPath: string read GetDebugPath write SetDebugPath;
property UnitOutputDirectory: string read fUnitOutputDir write SetUnitOutputDir; property UnitOutputDirectory: string read GetUnitOutputDir write SetUnitOutputDir;
// conditional / build modes // conditional / build modes
property Conditionals: string read FConditionals write SetConditionals; property Conditionals: string read FConditionals write SetConditionals;
@ -340,7 +339,7 @@ type
property CustomConfigFile: Boolean read fCustomConfigFile property CustomConfigFile: Boolean read fCustomConfigFile
write fCustomConfigFile; write fCustomConfigFile;
property ConfigFilePath: String read fConfigFilePath write fConfigFilePath; property ConfigFilePath: String read fConfigFilePath write fConfigFilePath;
property CustomOptions: string read fCustomOptions write SetCustomOptions; property CustomOptions: string read GetCustomOptions write SetCustomOptions;
end; end;

View File

@ -58,7 +58,8 @@ uses
// IDE // IDE
LazarusIDEStrConsts, EnvironmentOpts, IDEProcs, LazConf, TransferMacros, LazarusIDEStrConsts, EnvironmentOpts, IDEProcs, LazConf, TransferMacros,
DialogProcs, IDETranslations, CompilerOptions, PackageLinks, PackageDefs, DialogProcs, IDETranslations, CompilerOptions, PackageLinks, PackageDefs,
ComponentReg, RegisterFCL, RegisterLCL, RegisterSynEdit, RegisterIDEIntf; ComponentReg, ProjectIntf, RegisterFCL, RegisterLCL, RegisterSynEdit,
RegisterIDEIntf;
type type
TFindPackageFlag = ( TFindPackageFlag = (
@ -265,7 +266,7 @@ type
procedure CloseUnneededPackages; procedure CloseUnneededPackages;
procedure ChangePackageID(APackage: TLazPackage; procedure ChangePackageID(APackage: TLazPackage;
const NewName: string; NewVersion: TPkgVersion; const NewName: string; NewVersion: TPkgVersion;
RenameDependencies: boolean); RenameDependencies, RenameMacros: boolean);
function SavePackageCompiledState(APackage: TLazPackage; function SavePackageCompiledState(APackage: TLazPackage;
const CompilerFilename, CompilerParams: string; const CompilerFilename, CompilerParams: string;
Complete, ShowAbort: boolean): TModalResult; Complete, ShowAbort: boolean): TModalResult;
@ -2652,26 +2653,46 @@ begin
end; end;
procedure TLazPackageGraph.ChangePackageID(APackage: TLazPackage; procedure TLazPackageGraph.ChangePackageID(APackage: TLazPackage;
const NewName: string; NewVersion: TPkgVersion; RenameDependencies: boolean); const NewName: string; NewVersion: TPkgVersion; RenameDependencies,
RenameMacros: boolean);
var var
Dependency: TPkgDependency; Dependency: TPkgDependency;
NextDependency: TPkgDependency; NextDependency: TPkgDependency;
OldPkgName: String; OldPkgName: String;
i: Integer;
Macro: TLazBuildMacro;
RenamedMacros: TStringList;
OldMacroName: String;
BaseCompOpts: TBaseCompilerOptions;
begin begin
OldPkgName:=APackage.Name; OldPkgName:=APackage.Name;
if (SysUtils.CompareText(OldPkgName,NewName)=0) if (OldPkgName=NewName) and (APackage.Version.Compare(NewVersion)=0) then
and (APackage.Version.Compare(NewVersion)=0) then begin exit; // fit exactly
// ID does not change
// -> just rename
APackage.Name:=NewName;
fChanged:=true;
exit;
end;
// ID changed
BeginUpdate(true); BeginUpdate(true);
if RenameMacros then
begin
// rename macros
RenamedMacros:=TStringList.Create;
try
for i:=0 to APackage.CompilerOptions.BuildMacros.Count-1 do
begin
Macro:=APackage.CompilerOptions.BuildMacros[i];
if SysUtils.CompareText(OldPkgName,copy(Macro.Identifier,1,length(OldPkgName)))=0
then begin
OldMacroName:=Macro.Identifier;
RenamedMacros.Add(OldMacroName);
Macro.Identifier:=NewName+copy(OldMacroName,length(OldPkgName)+1,256);
BaseCompOpts:=TBaseCompilerOptions(APackage.CompilerOptions);
BaseCompOpts.RenameMacro(OldMacroName,Macro.Identifier,true);
end;
end;
finally
RenamedMacros.Free;
end;
end;
// cut or fix all dependencies, that became incompatible // cut or fix all dependencies, that became incompatible
Dependency:=APackage.FirstUsedByDependency; Dependency:=APackage.FirstUsedByDependency;
while Dependency<>nil do begin while Dependency<>nil do begin
@ -2687,7 +2708,7 @@ begin
end; end;
Dependency:=NextDependency; Dependency:=NextDependency;
end; end;
// change ID // change ID
FTree.Remove(APackage); FTree.Remove(APackage);
APackage.ChangeID(NewName,NewVersion); APackage.ChangeID(NewName,NewVersion);
@ -2698,6 +2719,8 @@ begin
if Assigned(OnChangePackageName) then if Assigned(OnChangePackageName) then
OnChangePackageName(APackage,OldPkgName); OnChangePackageName(APackage,OldPkgName);
// no try-finally needed, because above fails only for fatal reasons
EndUpdate; EndUpdate;
end; end;

View File

@ -1330,7 +1330,7 @@ begin
// rename package // rename package
PackageGraph.ChangePackageID(APackage,NewPkgName,APackage.Version, PackageGraph.ChangePackageID(APackage,NewPkgName,APackage.Version,
RenameDependencies); RenameDependencies,true);
SaveAutoInstallDependencies(false); SaveAutoInstallDependencies(false);
RenamePackageInProject; RenamePackageInProject;

View File

@ -329,7 +329,7 @@ begin
end; end;
PackageGraph.ChangePackageID(LazPackage,LazPackage.Name,NewVersion, PackageGraph.ChangePackageID(LazPackage,LazPackage.Name,NewVersion,
RenameDependencies); RenameDependencies,true);
finally finally
NewVersion.Free; NewVersion.Free;
end; end;