mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 02:59:13 +02:00
* implemented -e option, to use the environment to pass arguments to the
compiler. Does only work when compiled with fcl-process git-svn-id: trunk@18164 -
This commit is contained in:
parent
b160aed929
commit
e114d05d19
@ -703,6 +703,7 @@ Type
|
|||||||
FTarget: String;
|
FTarget: String;
|
||||||
FUnixPaths: Boolean;
|
FUnixPaths: Boolean;
|
||||||
FNoFPCCfg: Boolean;
|
FNoFPCCfg: Boolean;
|
||||||
|
FUseEnvironment: Boolean;
|
||||||
function GetFPDocOutputDir: String;
|
function GetFPDocOutputDir: String;
|
||||||
function GetLocalUnitDir: String;
|
function GetLocalUnitDir: String;
|
||||||
function GetGlobalUnitDir: String;
|
function GetGlobalUnitDir: String;
|
||||||
@ -763,6 +764,7 @@ Type
|
|||||||
Property MkDir : String Read FMkDir write FMkDir; // Make $(DIRECTORY)
|
Property MkDir : String Read FMkDir write FMkDir; // Make $(DIRECTORY)
|
||||||
Property Archive : String Read FArchive Write FArchive; // zip $(ARCHIVE) $(FILESORDIRS)
|
Property Archive : String Read FArchive Write FArchive; // zip $(ARCHIVE) $(FILESORDIRS)
|
||||||
// Misc
|
// Misc
|
||||||
|
Property UseEnvironment : Boolean read FUseEnvironment write FUseEnvironment;
|
||||||
Property IgnoreInvalidOptions: Boolean read FIgnoreInvalidOptions write FIgnoreInvalidOptions;
|
Property IgnoreInvalidOptions: Boolean read FIgnoreInvalidOptions write FIgnoreInvalidOptions;
|
||||||
// Installation optioms
|
// Installation optioms
|
||||||
Property InstallExamples: Boolean read FInstallExamples write FInstallExamples;
|
Property InstallExamples: Boolean read FInstallExamples write FInstallExamples;
|
||||||
@ -844,7 +846,7 @@ Type
|
|||||||
Procedure ResolveFileNames(APackage : TPackage; ACPU:TCPU;AOS:TOS;DoChangeDir:boolean=true);
|
Procedure ResolveFileNames(APackage : TPackage; ACPU:TCPU;AOS:TOS;DoChangeDir:boolean=true);
|
||||||
|
|
||||||
// Public Copy/delete/Move/Archive/Mkdir Commands.
|
// Public Copy/delete/Move/Archive/Mkdir Commands.
|
||||||
Procedure ExecuteCommand(const Cmd,Args : String; IgnoreError : Boolean = False); virtual;
|
Procedure ExecuteCommand(const Cmd,Args : String; const Env: TStrings = nil; IgnoreError : Boolean = False); virtual;
|
||||||
Procedure CmdCopyFiles(List : TStrings; Const DestDir : String);
|
Procedure CmdCopyFiles(List : TStrings; Const DestDir : String);
|
||||||
Procedure CmdCreateDir(const DestDir : String);
|
Procedure CmdCreateDir(const DestDir : String);
|
||||||
Procedure CmdMoveFiles(List : TStrings; Const DestDir : String);
|
Procedure CmdMoveFiles(List : TStrings; Const DestDir : String);
|
||||||
@ -857,7 +859,7 @@ Type
|
|||||||
// Dependency commands
|
// Dependency commands
|
||||||
Function DependencyOK(ADependency : TDependency) : Boolean;
|
Function DependencyOK(ADependency : TDependency) : Boolean;
|
||||||
// Target commands
|
// Target commands
|
||||||
Function GetCompilerCommand(APackage : TPackage; ATarget : TTarget) : String;
|
Function GetCompilerCommand(APackage : TPackage; ATarget : TTarget; Env: TStrings) : String;
|
||||||
Function TargetOK(ATarget : TTarget) : Boolean;
|
Function TargetOK(ATarget : TTarget) : Boolean;
|
||||||
Function NeedsCompile(APackage:TPackage; ATarget : TTarget) : Boolean;
|
Function NeedsCompile(APackage:TPackage; ATarget : TTarget) : Boolean;
|
||||||
Procedure Compile(APackage:TPackage; ATarget : TTarget); virtual;
|
Procedure Compile(APackage:TPackage; ATarget : TTarget); virtual;
|
||||||
@ -1176,6 +1178,7 @@ ResourceString
|
|||||||
SHelpInstExamples = 'Install the example-sources.';
|
SHelpInstExamples = 'Install the example-sources.';
|
||||||
SHelpIgnoreInvOpt = 'Ignore further invalid options.';
|
SHelpIgnoreInvOpt = 'Ignore further invalid options.';
|
||||||
sHelpFpdocOutputDir = 'Use indicated directory as fpdoc output folder.';
|
sHelpFpdocOutputDir = 'Use indicated directory as fpdoc output folder.';
|
||||||
|
sHelpUseEnvironment = 'Use environment to pass options to compiler.';
|
||||||
|
|
||||||
|
|
||||||
Const
|
Const
|
||||||
@ -1195,6 +1198,7 @@ Const
|
|||||||
KeyPrefix = 'Prefix';
|
KeyPrefix = 'Prefix';
|
||||||
KeyTarget = 'Target';
|
KeyTarget = 'Target';
|
||||||
KeyNoFPCCfg = 'NoFPCCfg';
|
KeyNoFPCCfg = 'NoFPCCfg';
|
||||||
|
KeyUseEnv = 'UseEnv';
|
||||||
KeyLocalUnitDir = 'LocalUnitDir';
|
KeyLocalUnitDir = 'LocalUnitDir';
|
||||||
KeyGlobalUnitDir = 'GlobalUnitDir';
|
KeyGlobalUnitDir = 'GlobalUnitDir';
|
||||||
KeyBaseInstallDir = 'BaseInstallDir';
|
KeyBaseInstallDir = 'BaseInstallDir';
|
||||||
@ -1218,7 +1222,7 @@ Const
|
|||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
|
|
||||||
{$ifdef HAS_UNIT_PROCESS}
|
{$ifdef HAS_UNIT_PROCESS}
|
||||||
function ExecuteFPC(Verbose: boolean; const Path: string; const ComLine: string; ConsoleOutput: TMemoryStream): integer;
|
function ExecuteFPC(Verbose: boolean; const Path: string; const ComLine: string; const Env: TStrings; ConsoleOutput: TMemoryStream): integer;
|
||||||
var
|
var
|
||||||
P: TProcess;
|
P: TProcess;
|
||||||
BytesRead: longint;
|
BytesRead: longint;
|
||||||
@ -1299,6 +1303,9 @@ begin
|
|||||||
P := TProcess.Create(nil);
|
P := TProcess.Create(nil);
|
||||||
try
|
try
|
||||||
P.CommandLine := Path + ' ' + ComLine;
|
P.CommandLine := Path + ' ' + ComLine;
|
||||||
|
if assigned(Env) then
|
||||||
|
P.Environment.Assign(Env);
|
||||||
|
|
||||||
P.Options := [poUsePipes];
|
P.Options := [poUsePipes];
|
||||||
|
|
||||||
P.Execute;
|
P.Execute;
|
||||||
@ -3067,6 +3074,8 @@ begin
|
|||||||
Values[KeyTarget]:=FTarget;
|
Values[KeyTarget]:=FTarget;
|
||||||
if FNoFPCCfg then
|
if FNoFPCCfg then
|
||||||
Values[KeyNoFPCCfg]:='Y';
|
Values[KeyNoFPCCfg]:='Y';
|
||||||
|
if FUseEnvironment then
|
||||||
|
Values[KeyUseEnv]:='Y';
|
||||||
if FInstallExamples then
|
if FInstallExamples then
|
||||||
Values[KeyInstallExamples]:='Y';
|
Values[KeyInstallExamples]:='Y';
|
||||||
end;
|
end;
|
||||||
@ -3128,6 +3137,7 @@ begin
|
|||||||
FExamplesInstallDir:=Values[KeyExamplesInstallDir];
|
FExamplesInstallDir:=Values[KeyExamplesInstallDir];
|
||||||
FInstallExamples:=(Upcase(Values[KeyInstallExamples])='Y');
|
FInstallExamples:=(Upcase(Values[KeyInstallExamples])='Y');
|
||||||
FNoFPCCfg:=(Upcase(Values[KeyNoFPCCfg])='Y');
|
FNoFPCCfg:=(Upcase(Values[KeyNoFPCCfg])='Y');
|
||||||
|
FUseEnvironment:=(Upcase(Values[KeyUseEnv])='Y');
|
||||||
end;
|
end;
|
||||||
Finally
|
Finally
|
||||||
L.Free;
|
L.Free;
|
||||||
@ -3373,6 +3383,10 @@ begin
|
|||||||
Defaults.Prefix:=OptionArg(I)
|
Defaults.Prefix:=OptionArg(I)
|
||||||
else if Checkoption(I,'n','nofpccfg') then
|
else if Checkoption(I,'n','nofpccfg') then
|
||||||
Defaults.NoFPCCfg:=true
|
Defaults.NoFPCCfg:=true
|
||||||
|
{$ifdef HAS_UNIT_PROCESS}
|
||||||
|
else if Checkoption(I,'e','useenv') then
|
||||||
|
Defaults.UseEnvironment:=true
|
||||||
|
{$endif}
|
||||||
else if CheckOption(I,'B','baseinstalldir') then
|
else if CheckOption(I,'B','baseinstalldir') then
|
||||||
Defaults.BaseInstallDir:=OptionArg(I)
|
Defaults.BaseInstallDir:=OptionArg(I)
|
||||||
else if CheckOption(I,'U','unitinstalldir') then
|
else if CheckOption(I,'U','unitinstalldir') then
|
||||||
@ -3451,6 +3465,9 @@ begin
|
|||||||
LogOption('l','list-commands',SHelpList);
|
LogOption('l','list-commands',SHelpList);
|
||||||
LogOption('n','nofpccfg',SHelpNoFPCCfg);
|
LogOption('n','nofpccfg',SHelpNoFPCCfg);
|
||||||
LogOption('v','verbose',SHelpVerbose);
|
LogOption('v','verbose',SHelpVerbose);
|
||||||
|
{$ifdef HAS_UNIT_PROCESS}
|
||||||
|
LogOption('e', 'useenv', sHelpUseEnvironment);
|
||||||
|
{$endif}
|
||||||
LogOption('ie','installexamples',SHelpInstExamples);
|
LogOption('ie','installexamples',SHelpInstExamples);
|
||||||
LogArgOption('C','cpu',SHelpCPU);
|
LogArgOption('C','cpu',SHelpCPU);
|
||||||
LogArgOption('O','os',SHelpOS);
|
LogArgOption('O','os',SHelpOS);
|
||||||
@ -3606,7 +3623,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TBuildEngine.ExecuteCommand(const Cmd,Args : String; IgnoreError : Boolean = False);
|
procedure TBuildEngine.ExecuteCommand(const Cmd,Args : String; const Env: TStrings = nil; IgnoreError : Boolean = False);
|
||||||
Var
|
Var
|
||||||
E : Integer;
|
E : Integer;
|
||||||
cmdLine: string;
|
cmdLine: string;
|
||||||
@ -3622,7 +3639,7 @@ begin
|
|||||||
ConsoleOutput := TMemoryStream.Create;
|
ConsoleOutput := TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
{$ifdef HAS_UNIT_PROCESS}
|
{$ifdef HAS_UNIT_PROCESS}
|
||||||
E:=ExecuteFPC(Verbose, cmd, args, ConsoleOutput);
|
E:=ExecuteFPC(Verbose, cmd, args, env, ConsoleOutput);
|
||||||
{$else}
|
{$else}
|
||||||
E:=ExecuteProcess(cmd,args);
|
E:=ExecuteProcess(cmd,args);
|
||||||
{$endif}
|
{$endif}
|
||||||
@ -4007,7 +4024,7 @@ begin
|
|||||||
Cmd:=C.Command;
|
Cmd:=C.Command;
|
||||||
If (ExtractFilePath(Cmd)='') then
|
If (ExtractFilePath(Cmd)='') then
|
||||||
Cmd:=ExeSearch(Cmd,GetEnvironmentvariable('PATH'));
|
Cmd:=ExeSearch(Cmd,GetEnvironmentvariable('PATH'));
|
||||||
ExecuteCommand(Cmd,O,C.IgnoreResult);
|
ExecuteCommand(Cmd,O,nil,C.IgnoreResult);
|
||||||
If Assigned(C.AfterCommand) then
|
If Assigned(C.AfterCommand) then
|
||||||
C.AfterCommand(C);
|
C.AfterCommand(C);
|
||||||
end;
|
end;
|
||||||
@ -4309,10 +4326,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function TBuildEngine.GetCompilerCommand(APackage : TPackage; ATarget : TTarget) : String;
|
Function TBuildEngine.GetCompilerCommand(APackage : TPackage; ATarget : TTarget; Env: TStrings) : String;
|
||||||
Var
|
Var
|
||||||
L : TUnsortedDuplicatesStringList;
|
L : TUnsortedDuplicatesStringList;
|
||||||
Args : TStringList;
|
Args : TStringList;
|
||||||
|
s : string;
|
||||||
i : Integer;
|
i : Integer;
|
||||||
begin
|
begin
|
||||||
if ATarget.TargetSourceFileName = '' then
|
if ATarget.TargetSourceFileName = '' then
|
||||||
@ -4386,6 +4404,20 @@ begin
|
|||||||
for i:=0 to Args.Count-1 do
|
for i:=0 to Args.Count-1 do
|
||||||
Result:=Result+' '+maybequoted(Args[i]);
|
Result:=Result+' '+maybequoted(Args[i]);
|
||||||
Delete(result,1,1);
|
Delete(result,1,1);
|
||||||
|
|
||||||
|
if Defaults.UseEnvironment and assigned(Env) then
|
||||||
|
begin
|
||||||
|
env.Values['FPCEXTCMD'] := Result;
|
||||||
|
result := '!FPCEXTCMD';
|
||||||
|
// Make sure that this process' environment variables are passed to the
|
||||||
|
// compiler's environment
|
||||||
|
for i := 0 to GetEnvironmentVariableCount-1 do
|
||||||
|
env.Add(GetEnvironmentString(i));
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Add Filename to compile
|
||||||
|
result := result + ' ' + ATarget.TargetSourceFileName;
|
||||||
|
|
||||||
Args.Free;
|
Args.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -4559,14 +4591,29 @@ end;
|
|||||||
procedure TBuildEngine.Compile(APackage: TPackage; ATarget: TTarget);
|
procedure TBuildEngine.Compile(APackage: TPackage; ATarget: TTarget);
|
||||||
Var
|
Var
|
||||||
S : String;
|
S : String;
|
||||||
|
Env : TStrings;
|
||||||
begin
|
begin
|
||||||
Log(vlInfo,SInfoCompilingTarget,[ATarget.Name]);
|
Log(vlInfo,SInfoCompilingTarget,[ATarget.Name]);
|
||||||
LogIndent;
|
LogIndent;
|
||||||
ExecuteCommands(ATarget.Commands,caBeforeCompile);
|
ExecuteCommands(ATarget.Commands,caBeforeCompile);
|
||||||
If Assigned(ATarget.BeforeCompile) then
|
If Assigned(ATarget.BeforeCompile) then
|
||||||
ATarget.BeforeCompile(ATarget);
|
ATarget.BeforeCompile(ATarget);
|
||||||
S:=GetCompilerCommand(APackage,ATarget);
|
|
||||||
ExecuteCommand(GetCompiler,S);
|
if Defaults.UseEnvironment then
|
||||||
|
begin
|
||||||
|
Env := TStringList.Create;
|
||||||
|
try
|
||||||
|
S:=GetCompilerCommand(APackage,ATarget,Env);
|
||||||
|
ExecuteCommand(GetCompiler,S,Env);
|
||||||
|
finally
|
||||||
|
Env.Free;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
S:=GetCompilerCommand(APackage,ATarget,Env);
|
||||||
|
ExecuteCommand(GetCompiler,S,nil);
|
||||||
|
end;
|
||||||
If Assigned(ATarget.AfterCompile) then
|
If Assigned(ATarget.AfterCompile) then
|
||||||
ATarget.AfterCompile(ATarget);
|
ATarget.AfterCompile(ATarget);
|
||||||
ExecuteCommands(ATarget.Commands,caAfterCompile);
|
ExecuteCommands(ATarget.Commands,caAfterCompile);
|
||||||
|
Loading…
Reference in New Issue
Block a user