IDE: using default package output directory until rebuild is needed

git-svn-id: trunk@23049 -
This commit is contained in:
mattias 2009-12-09 12:41:30 +00:00
parent 65daa78b02
commit 0603ce86c8
4 changed files with 51 additions and 31 deletions

View File

@ -2,7 +2,7 @@
This source is only used to compile and install the package. This source is only used to compile and install the package.
} }
unit codetools; unit CodeTools;
interface interface

View File

@ -383,9 +383,10 @@ type
TParsedCompilerOptions = class TParsedCompilerOptions = class
private private
FConditionals: TCompOptConditionals; FConditionals: TCompOptConditionals;
FGetWritableOutputDirectory: TGetWritableOutputDirectory;
FInvalidateParseOnChange: boolean; FInvalidateParseOnChange: boolean;
FOnLocalSubstitute: TLocalSubstitutionEvent; FOnLocalSubstitute: TLocalSubstitutionEvent;
FOutputDirectoryOverride: string;
procedure SetOutputDirectoryOverride(const AValue: string);
public public
UnparsedValues: array[TParsedCompilerOptString] of string; UnparsedValues: array[TParsedCompilerOptString] of string;
// parsed // parsed
@ -397,13 +398,13 @@ type
ParsedPIStamp: array[TParsedCompilerOptString] of integer; ParsedPIStamp: array[TParsedCompilerOptString] of integer;
ParsingPI: array[TParsedCompilerOptString] of boolean; ParsingPI: array[TParsedCompilerOptString] of boolean;
constructor Create(TheConditionals: TCompOptConditionals); constructor Create(TheConditionals: TCompOptConditionals);
function GetParsedValue(Option: TParsedCompilerOptString): string; function GetParsedValue(Option: TParsedCompilerOptString;
function GetParsedPIValue(Option: TParsedCompilerOptString): string; WithOverrides: boolean = true): string;
function GetParsedPIValue(Option: TParsedCompilerOptString): string;// platform independent
procedure SetUnparsedValue(Option: TParsedCompilerOptString; procedure SetUnparsedValue(Option: TParsedCompilerOptString;
const NewValue: string); const NewValue: string);
function DoParseOption(const OptionText: string; function DoParseOption(const OptionText: string;
Option: TParsedCompilerOptString; Option: TParsedCompilerOptString;
UseGetWritableOutputDirectory,
PlatformIndependent: boolean): string; PlatformIndependent: boolean): string;
procedure Clear; procedure Clear;
procedure InvalidateAll; procedure InvalidateAll;
@ -413,8 +414,8 @@ type
write FOnLocalSubstitute; write FOnLocalSubstitute;
property InvalidateParseOnChange: boolean read FInvalidateParseOnChange property InvalidateParseOnChange: boolean read FInvalidateParseOnChange
write FInvalidateParseOnChange; write FInvalidateParseOnChange;
property GetWritableOutputDirectory: TGetWritableOutputDirectory property OutputDirectoryOverride: string read FOutputDirectoryOverride
read FGetWritableOutputDirectory write FGetWritableOutputDirectory; write SetOutputDirectoryOverride;
property Conditionals: TCompOptConditionals read FConditionals; property Conditionals: TCompOptConditionals read FConditionals;
end; end;
@ -3331,17 +3332,36 @@ end;
{ TParsedCompilerOptions } { TParsedCompilerOptions }
procedure TParsedCompilerOptions.SetOutputDirectoryOverride(const AValue: string
);
begin
if FOutputDirectoryOverride=AValue then exit;
FOutputDirectoryOverride:=AValue;
if InvalidateParseOnChange then
IncreaseCompilerParseStamp;// the output dir is used by other packages
if FOutputDirectoryOverride<>'' then
DebugLn(['TParsedCompilerOptions.SetOutputDirectoryOverride New=',FOutputDirectoryOverride])
else
DebugLn(['TParsedCompilerOptions.SetOutputDirectoryOverride using default']);
end;
constructor TParsedCompilerOptions.Create(TheConditionals: TCompOptConditionals); constructor TParsedCompilerOptions.Create(TheConditionals: TCompOptConditionals);
begin begin
FConditionals:=TheConditionals; FConditionals:=TheConditionals;
Clear; Clear;
end; end;
function TParsedCompilerOptions.GetParsedValue(Option: TParsedCompilerOptString function TParsedCompilerOptions.GetParsedValue(Option: TParsedCompilerOptString;
): string; WithOverrides: boolean): string;
var var
s: String; s: String;
begin begin
if WithOverrides then begin
if (Option=pcosOutputDir) and (OutputDirectoryOverride<>'') then begin
Result:=OutputDirectoryOverride;
exit;
end;
end;
if ParsedStamp[Option]<>CompilerParseStamp then begin if ParsedStamp[Option]<>CompilerParseStamp then begin
if Parsing[Option] then begin if Parsing[Option] then begin
DebugLn('TParsedCompilerOptions.GetParsedValue Circle in Options: ',ParsedCompilerOptStringNames[Option]); DebugLn('TParsedCompilerOptions.GetParsedValue Circle in Options: ',ParsedCompilerOptStringNames[Option]);
@ -3349,7 +3369,7 @@ begin
end; end;
Parsing[Option]:=true; Parsing[Option]:=true;
try try
s:=DoParseOption(UnparsedValues[Option],Option,true,false); s:=DoParseOption(UnparsedValues[Option],Option,false);
ParsedValues[Option]:=s; ParsedValues[Option]:=s;
ParsedStamp[Option]:=CompilerParseStamp; ParsedStamp[Option]:=CompilerParseStamp;
//if Option=pcosCustomOptions then begin //if Option=pcosCustomOptions then begin
@ -3374,7 +3394,7 @@ begin
end; end;
ParsingPI[Option]:=true; ParsingPI[Option]:=true;
try try
s:=DoParseOption(UnparsedValues[Option],Option,false,true); s:=DoParseOption(UnparsedValues[Option],Option,true);
ParsedPIValues[Option]:=s; ParsedPIValues[Option]:=s;
ParsedPIStamp[Option]:=CompilerParseStamp; ParsedPIStamp[Option]:=CompilerParseStamp;
//if Option=pcosCustomOptions then begin //if Option=pcosCustomOptions then begin
@ -3402,8 +3422,7 @@ begin
end; end;
function TParsedCompilerOptions.DoParseOption(const OptionText: string; function TParsedCompilerOptions.DoParseOption(const OptionText: string;
Option: TParsedCompilerOptString; UseGetWritableOutputDirectory, Option: TParsedCompilerOptString; PlatformIndependent: boolean): string;
PlatformIndependent: boolean): string;
var var
s: String; s: String;
BaseDirectory: String; BaseDirectory: String;
@ -3460,11 +3479,6 @@ begin
else else
BaseDirectory:=GetParsedValue(pcosBaseDir); BaseDirectory:=GetParsedValue(pcosBaseDir);
if (BaseDirectory<>'') then s:=TrimFilename(BaseDirectory+s); if (BaseDirectory<>'') then s:=TrimFilename(BaseDirectory+s);
if (Option in ParsedCompilerOutDirectories)
and UseGetWritableOutputDirectory
and Assigned(GetWritableOutputDirectory) then begin
GetWritableOutputDirectory(s);
end;
end; end;
s:=AppendPathDelim(s); s:=AppendPathDelim(s);
end end

View File

@ -684,7 +684,6 @@ type
procedure OnMacroListSubstitution(TheMacro: TTransferMacro; procedure OnMacroListSubstitution(TheMacro: TTransferMacro;
const MacroName: string; var s: string; const MacroName: string; var s: string;
const Data: PtrInt; var Handled, Abort: boolean); const Data: PtrInt; var Handled, Abort: boolean);
procedure GetWritableOutputDirectory(var AnOutDir: string);
procedure Clear; procedure Clear;
procedure UpdateSourceDirectories; procedure UpdateSourceDirectories;
procedure SourceDirectoriesChanged(Sender: TObject); procedure SourceDirectoriesChanged(Sender: TObject);
@ -715,7 +714,7 @@ type
function GetResolvedFilename(ResolveMacros: boolean): string; function GetResolvedFilename(ResolveMacros: boolean): string;
function GetSourceDirs(WithPkgDir, WithoutOutputDir: boolean): string; function GetSourceDirs(WithPkgDir, WithoutOutputDir: boolean): string;
procedure GetInheritedCompilerOptions(var OptionsList: TFPList); procedure GetInheritedCompilerOptions(var OptionsList: TFPList);
function GetOutputDirectory: string; function GetOutputDirectory(UseOverride: boolean = true): string; // this can change before building, when default dir is readonly
function GetStateFilename: string; function GetStateFilename: string;
function GetCompileSourceFilename: string;// as GetSrcFilename without directory function GetCompileSourceFilename: string;// as GetSrcFilename without directory
function GetSrcFilename: string; function GetSrcFilename: string;
@ -2217,12 +2216,6 @@ begin
end; end;
end; end;
procedure TLazPackage.GetWritableOutputDirectory(var AnOutDir: string);
begin
if Assigned(OnGetWritablePkgOutputDirectory) then
OnGetWritablePkgOutputDirectory(Self,AnOutDir);
end;
function TLazPackage.GetAutoIncrementVersionOnBuild: boolean; function TLazPackage.GetAutoIncrementVersionOnBuild: boolean;
begin begin
Result:=lpfAutoIncrementVersionOnBuild in FFlags; Result:=lpfAutoIncrementVersionOnBuild in FFlags;
@ -2506,8 +2499,6 @@ begin
FCompilerOptions:=TPkgCompilerOptions.Create(Self); FCompilerOptions:=TPkgCompilerOptions.Create(Self);
FCompilerOptions.ParsedOpts.InvalidateParseOnChange:=true; FCompilerOptions.ParsedOpts.InvalidateParseOnChange:=true;
FCompilerOptions.ParsedOpts.OnLocalSubstitute:=@SubstitutePkgMacro; FCompilerOptions.ParsedOpts.OnLocalSubstitute:=@SubstitutePkgMacro;
FCompilerOptions.ParsedOpts.GetWritableOutputDirectory:=
@GetWritableOutputDirectory;
FCompilerOptions.DefaultMakeOptionsFlags:=[ccloNoLinkerOpts]; FCompilerOptions.DefaultMakeOptionsFlags:=[ccloNoLinkerOpts];
FUsageOptions:=TPkgAdditionalCompilerOptions.Create(Self); FUsageOptions:=TPkgAdditionalCompilerOptions.Create(Self);
FUsageOptions.ParsedOpts.OnLocalSubstitute:=@SubstitutePkgMacro; FUsageOptions.ParsedOpts.OnLocalSubstitute:=@SubstitutePkgMacro;
@ -3410,10 +3401,10 @@ begin
Result:=ChangeFileExt(ExtractFilename(Filename),'.pas'); Result:=ChangeFileExt(ExtractFilename(Filename),'.pas');
end; end;
function TLazPackage.GetOutputDirectory: string; function TLazPackage.GetOutputDirectory(UseOverride: boolean = true): string;
begin begin
if HasDirectory then begin if HasDirectory then begin
Result:=CompilerOptions.ParsedOpts.GetParsedValue(pcosOutputDir); Result:=CompilerOptions.ParsedOpts.GetParsedValue(pcosOutputDir,UseOverride);
end else end else
Result:=''; Result:='';
end; end;

View File

@ -3195,8 +3195,23 @@ var
i: Integer; i: Integer;
CurFile: TPkgFile; CurFile: TPkgFile;
OutputFileName: String; OutputFileName: String;
NewOutputDir: String;
begin begin
OutputDir:=APackage.GetOutputDirectory; // get default output directory
OutputDir:=APackage.GetOutputDirectory(false);
if Assigned(OnGetWritablePkgOutputDirectory) then begin
// check if default output directory is writable
NewOutputDir:=OutputDir;
OnGetWritablePkgOutputDirectory(APackage,NewOutputDir);
if NewOutputDir<>OutputDir then begin
// default output directory is not writable => redirect to another place
OutputDir:=NewOutputDir;
APackage.CompilerOptions.ParsedOpts.OutputDirectoryOverride:=OutputDir;
end else begin
// default output directory is writable => no redirect
APackage.CompilerOptions.ParsedOpts.OutputDirectoryOverride:='';
end;
end;
StateFile:=APackage.GetStateFilename; StateFile:=APackage.GetStateFilename;
PkgSrcDir:=ExtractFilePath(APackage.GetSrcFilename); PkgSrcDir:=ExtractFilePath(APackage.GetSrcFilename);