implemented telling custom options of packages to codetools

git-svn-id: trunk@4545 -
This commit is contained in:
mattias 2003-08-28 15:22:38 +00:00
parent 223a02d7e2
commit 5932d8825a
3 changed files with 93 additions and 4 deletions

View File

@ -2111,8 +2111,11 @@ var
end; end;
da_IfDef: da_IfDef:
// test if variable is defined // test if variable is defined
if DirDef.Values.IsDefined(DefTempl.Variable) then begin
CalculateIfChilds; //writeln('CalculateTemplate A ',DefTempl.Name,' ',DefTempl.Variable,' ',DirDef.Values.IsDefined(DefTempl.Variable),' CurPath="',CurPath,'"');
if DirDef.Values.IsDefined(DefTempl.Variable) then
CalculateIfChilds;
end;
da_IfNDef: da_IfNDef:
// test if variable is not defined // test if variable is not defined

View File

@ -1914,6 +1914,7 @@ resourcestring
lisPkgDefsOutputDirectory = 'Output directory'; lisPkgDefsOutputDirectory = 'Output directory';
lisPkgDefsCompiledSrcPathAddition = 'CompiledSrcPath addition'; lisPkgDefsCompiledSrcPathAddition = 'CompiledSrcPath addition';
lisPkgDefsUnitPath = 'Unit Path'; lisPkgDefsUnitPath = 'Unit Path';
lisPkgDefsSrcDirMark = 'Package Source Directory Mark';
// add active file to package dialog // add active file to package dialog
lisAF2PInvalidPackage = 'Invalid Package'; lisAF2PInvalidPackage = 'Invalid Package';

View File

@ -105,6 +105,7 @@ type
function Compare(Version2: TPkgVersion): integer; function Compare(Version2: TPkgVersion): integer;
procedure Assign(Source: TPkgVersion); procedure Assign(Source: TPkgVersion);
function AsString: string; function AsString: string;
function AsWord: string;
function ReadString(const s: string): boolean; function ReadString(const s: string): boolean;
procedure SetValues(NewMajor, NewMinor, NewRelease, NewBuild: integer); procedure SetValues(NewMajor, NewMinor, NewRelease, NewBuild: integer);
function VersionBound(v: integer): integer; function VersionBound(v: integer): integer;
@ -318,6 +319,8 @@ type
{ TLazPackageID } { TLazPackageID }
TLazPackageID = class TLazPackageID = class
private
FIDAsWord: string;
protected protected
FName: string; FName: string;
FVersion: TPkgVersion; FVersion: TPkgVersion;
@ -335,6 +338,7 @@ type
property Name: string read FName write SetName; property Name: string read FName write SetName;
property Version: TPkgVersion read FVersion; property Version: TPkgVersion read FVersion;
property IDAsString: string read FIDAsString; property IDAsString: string read FIDAsString;
property IDAsWord: string read FIDAsWord;
end; end;
@ -357,18 +361,21 @@ type
TLazPkgDefineTemplatesFlag = ( TLazPkgDefineTemplatesFlag = (
pdtIDChanged, pdtIDChanged,
pdtSourceDirsChanged, pdtSourceDirsChanged,
pdtOutputDirChanged pdtOutputDirChanged,
pdtCustomDefinesChanged
); );
TLazPkgDefineTemplatesFlags = set of TLazPkgDefineTemplatesFlag; TLazPkgDefineTemplatesFlags = set of TLazPkgDefineTemplatesFlag;
TLazPackageDefineTemplates = class TLazPackageDefineTemplates = class
private private
FActive: boolean; FActive: boolean;
FCustomDefines: TDefineTemplate;
FFlags: TLazPkgDefineTemplatesFlags; FFlags: TLazPkgDefineTemplatesFlags;
fLastOutputDirSrcPathIDAsString: string; fLastOutputDirSrcPathIDAsString: string;
fLastSourceDirectories: TStringList; fLastSourceDirectories: TStringList;
fLastSourceDirStamp: integer; fLastSourceDirStamp: integer;
fLastSourceDirsIDAsString: string; fLastSourceDirsIDAsString: string;
FLastCustomOptions: string;
FLazPackage: TLazPackage; FLazPackage: TLazPackage;
FMain: TDefineTemplate; FMain: TDefineTemplate;
FOutputDir: TDefineTemplate; FOutputDir: TDefineTemplate;
@ -378,6 +385,7 @@ type
procedure UpdateMain; procedure UpdateMain;
procedure UpdateDefinesForOutputDirectory; procedure UpdateDefinesForOutputDirectory;
procedure UpdateDefinesForSourceDirectories; procedure UpdateDefinesForSourceDirectories;
procedure UpdateDefinesForCustomDefines;
public public
constructor Create(OwnerPackage: TLazPackage); constructor Create(OwnerPackage: TLazPackage);
destructor Destroy; override; destructor Destroy; override;
@ -387,12 +395,14 @@ type
procedure PackageIDChanged; procedure PackageIDChanged;
procedure SourceDirectoriesChanged; procedure SourceDirectoriesChanged;
procedure OutputDirectoryChanged; procedure OutputDirectoryChanged;
procedure CustomDefinesChanged;
procedure AllChanged; procedure AllChanged;
public public
property LazPackage: TLazPackage read FLazPackage; property LazPackage: TLazPackage read FLazPackage;
property Main: TDefineTemplate read FMain; property Main: TDefineTemplate read FMain;
property OutputDir: TDefineTemplate read FOutputDir; property OutputDir: TDefineTemplate read FOutputDir;
property OutPutSrcPath: TDefineTemplate read FOutPutSrcPath; property OutPutSrcPath: TDefineTemplate read FOutPutSrcPath;
property CustomDefines: TDefineTemplate read FCustomDefines;
property Active: boolean read FActive write SetActive; property Active: boolean read FActive write SetActive;
end; end;
@ -1547,6 +1557,15 @@ begin
Result:=Result+'.'+IntToStr(Release) Result:=Result+'.'+IntToStr(Release)
end; end;
function TPkgVersion.AsWord: string;
begin
Result:=IntToStr(Major)+'_'+IntToStr(Minor);
if (Build<>0) then
Result:=Result+'_'+IntToStr(Release)+'_'+IntToStr(Build)
else if (Release<>0) then
Result:=Result+'_'+IntToStr(Release)
end;
function TPkgVersion.ReadString(const s: string): boolean; function TPkgVersion.ReadString(const s: string): boolean;
var var
ints: array[1..4] of integer; ints: array[1..4] of integer;
@ -2622,6 +2641,11 @@ begin
FIDAsString:=Name+' '+FIDAsString FIDAsString:=Name+' '+FIDAsString
else else
FIDAsString:=FIDAsString; FIDAsString:=FIDAsString;
FIDAsWord:=Version.AsWord;
if FIDAsWord<>'' then
FIDAsWord:=Name+FIDAsWord
else
FIDAsWord:=FIDAsWord;
end; end;
procedure TLazPackageID.VersionChanged(Sender: TObject); procedure TLazPackageID.VersionChanged(Sender: TObject);
@ -2681,6 +2705,7 @@ begin
if CustomOptions=AValue then exit; if CustomOptions=AValue then exit;
InvalidateOptions; InvalidateOptions;
inherited SetCustomOptions(AValue); inherited SetCustomOptions(AValue);
LazPackage.DefineTemplates.CustomDefinesChanged;
end; end;
procedure TPkgCompilerOptions.SetIncludeFiles(const AValue: string); procedure TPkgCompilerOptions.SetIncludeFiles(const AValue: string);
@ -2858,7 +2883,9 @@ begin
FOutputDir:=nil; FOutputDir:=nil;
FOutPutSrcPath:=nil; FOutPutSrcPath:=nil;
fLastOutputDirSrcPathIDAsString:=''; fLastOutputDirSrcPathIDAsString:='';
FFlags:=FFlags+[pdtIDChanged,pdtOutputDirChanged,pdtSourceDirsChanged]; FLastCustomOptions:='';
FFlags:=FFlags+[pdtIDChanged,pdtOutputDirChanged,pdtSourceDirsChanged,
pdtCustomDefinesChanged];
end; end;
end; end;
@ -2875,6 +2902,7 @@ begin
if pdtIDChanged in FFlags then PackageIDChanged; if pdtIDChanged in FFlags then PackageIDChanged;
if pdtSourceDirsChanged in FFlags then SourceDirectoriesChanged; if pdtSourceDirsChanged in FFlags then SourceDirectoriesChanged;
if pdtOutputDirChanged in FFlags then OutputDirectoryChanged; if pdtOutputDirChanged in FFlags then OutputDirectoryChanged;
if pdtCustomDefinesChanged in FFlags then CustomDefinesChanged;
end; end;
end; end;
@ -2888,6 +2916,7 @@ begin
UpdateMain; UpdateMain;
UpdateDefinesForOutputDirectory; UpdateDefinesForOutputDirectory;
UpdateDefinesForSourceDirectories; UpdateDefinesForSourceDirectories;
UpdateDefinesForCustomDefines;
end; end;
procedure TLazPackageDefineTemplates.SourceDirectoriesChanged; procedure TLazPackageDefineTemplates.SourceDirectoriesChanged;
@ -2912,11 +2941,23 @@ begin
CodeToolBoss.DefineTree.ClearCache; CodeToolBoss.DefineTree.ClearCache;
end; end;
procedure TLazPackageDefineTemplates.CustomDefinesChanged;
begin
if FUpdateLock>0 then begin
Include(FFlags,pdtCustomDefinesChanged);
exit;
end;
Exclude(FFlags,pdtCustomDefinesChanged);
UpdateDefinesForCustomDefines;
CodeToolBoss.DefineTree.ClearCache;
end;
procedure TLazPackageDefineTemplates.AllChanged; procedure TLazPackageDefineTemplates.AllChanged;
begin begin
PackageIDChanged; PackageIDChanged;
SourceDirectoriesChanged; SourceDirectoriesChanged;
OutputDirectoryChanged; OutputDirectoryChanged;
CustomDefinesChanged;
end; end;
procedure TLazPackageDefineTemplates.UpdateMain; procedure TLazPackageDefineTemplates.UpdateMain;
@ -2979,6 +3020,7 @@ var
UnitPathDefTempl: TDefineTemplate; UnitPathDefTempl: TDefineTemplate;
IncPathDefTempl: TDefineTemplate; IncPathDefTempl: TDefineTemplate;
IDHasChanged: Boolean; IDHasChanged: Boolean;
SrcDirMarkDefTempl: TDefineTemplate;
begin begin
if (not LazPackage.NeedsDefineTemplates) or (not Active) then exit; if (not LazPackage.NeedsDefineTemplates) or (not Active) then exit;
@ -3023,6 +3065,10 @@ begin
SrcDirDefTempl:=TDefineTemplate.Create('Source Directory '+IntToStr(i+1), SrcDirDefTempl:=TDefineTemplate.Create('Source Directory '+IntToStr(i+1),
fLastSourceDirectories[i],'',fLastSourceDirectories[i],da_Directory); fLastSourceDirectories[i],'',fLastSourceDirectories[i],da_Directory);
fLastSourceDirectories.Objects[i]:=SrcDirDefTempl; fLastSourceDirectories.Objects[i]:=SrcDirDefTempl;
// add package source directory marker
SrcDirMarkDefTempl:=TDefineTemplate.Create('PkgSrcDirMark',
lisPkgDefsSrcDirMark,'#PkgSrcMark'+LazPackage.IDAsWord,'',da_Define);
SrcDirDefTempl.AddChild(SrcDirMarkDefTempl);
// create unit path template for this directory // create unit path template for this directory
UnitPathDefTempl:=TDefineTemplate.Create('UnitPath', lisPkgDefsUnitPath, UnitPathDefTempl:=TDefineTemplate.Create('UnitPath', lisPkgDefsUnitPath,
'#UnitPath','$(#UnitPath);$PkgUnitPath('+LazPackage.IDAsString+')', '#UnitPath','$(#UnitPath);$PkgUnitPath('+LazPackage.IDAsString+')',
@ -3045,6 +3091,45 @@ begin
end; end;
end; end;
procedure TLazPackageDefineTemplates.UpdateDefinesForCustomDefines;
var
OptionsDefTempl: TDefineTemplate;
begin
if (not LazPackage.NeedsDefineTemplates) or (not Active) then exit;
// check if something has changed
if FLastCustomOptions=LazPackage.CompilerOptions.CustomOptions then exit;
FLastCustomOptions:=LazPackage.CompilerOptions.CustomOptions;
OptionsDefTempl:=CodeToolBoss.DefinePool.CreateFPCCommandLineDefines(
'Custom Options',FLastCustomOptions,false,LazPackage);
if OptionsDefTempl=nil then begin
// no custom options -> delete old template
if FCustomDefines<>nil then begin
FCustomDefines.UnBind;
FCustomDefines.Free;
FCustomDefines:=nil;
end;
exit;
end;
// create custom options
// The custom options are enclosed by an IFDEF #PkgSrcMark<PckId> template.
// Each source directory defines this variable, so that the settings will
// activated for every source directory.
if (FMain=nil) then UpdateMain;
if FCustomDefines=nil then begin
FCustomDefines:=TDefineTemplate.Create('Source Directory Additions',
'Additional defines for package source directories',
'#PkgSrcMark'+LazPackage.IDAsWord,'',
da_IfDef);
FMain.AddChild(FCustomDefines);
end else begin
FCustomDefines.Value:='#PkgSrcMark'+LazPackage.IDAsWord;
end;
FCustomDefines.ReplaceChild(OptionsDefTempl);
end;
{ TBasePackageEditor } { TBasePackageEditor }
function TBasePackageEditor.GetLazPackage: TLazPackage; function TBasePackageEditor.GetLazPackage: TLazPackage;