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.
}
unit codetools;
unit CodeTools;
interface

View File

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

View File

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

View File

@ -3195,8 +3195,23 @@ var
i: Integer;
CurFile: TPkgFile;
OutputFileName: String;
NewOutputDir: String;
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;
PkgSrcDir:=ExtractFilePath(APackage.GetSrcFilename);