LazBuild: Add options --get-expand-text=, --get-build-modes and --get-exe-path. Clean function BuildProject. Issue #29511 and merge request !129.

This commit is contained in:
Juha 2024-02-01 14:06:38 +02:00
parent ad54dc2ceb
commit e0f086d2e0
3 changed files with 90 additions and 60 deletions

View File

@ -174,8 +174,11 @@ resourcestring
'info file after build. If not specified, build number will be incremented '+ 'info file after build. If not specified, build number will be incremented '+
'if configured.'; 'if configured.';
lisLazbuildOptionsSyntax = 'lazbuild [options] <project/package filename or package ' lisGetExpandText = 'Write text to console after substituting its macro values.';
+'name>'; lisGetBuildModes = 'Write a list of build modes in the project.';
lisGetExePath = 'Write the directory where the excutable will be placed.';
lisLazbuildOptionsSyntax = 'lazbuild [options] <project/package filename or package name>';
// component palette // component palette
lisSelectionTool = 'Selection tool'; lisSelectionTool = 'Selection tool';

View File

@ -31,7 +31,7 @@ uses
Interfaces, // this includes the NoGUI widgetset Interfaces, // this includes the NoGUI widgetset
// LazUtils // LazUtils
Masks, LConvEncoding, FileUtil, LazFileUtils, LazLoggerBase, LazUtilities, Masks, LConvEncoding, FileUtil, LazFileUtils, LazLoggerBase, LazUtilities,
LazUTF8, Laz2_XMLCfg, LazStringUtils, LazUTF8, Laz2_XMLCfg, LazStringUtils, FPCAdds,
// LCL // LCL
LCLPlatformDef, Forms, LCLPlatformDef, Forms,
// Codetools // Codetools
@ -272,6 +272,20 @@ begin
end; end;
end; end;
procedure ShowBuildModes;
var
i: Integer;
begin
for i:=0 to Project1.BuildModes.Count-1 do
begin
if Project1.BuildModes[i]=Project1.ActiveBuildMode then
Write('* ')
else
Write(' ');
WriteLn(Project1.BuildModes[i].Identifier);
end;
end;
{ TLazBuildApplication } { TLazBuildApplication }
procedure TLazBuildApplication.CodeBufferEncodeSaving(Code: TCodeBuffer; procedure TLazBuildApplication.CodeBufferEncodeSaving(Code: TCodeBuffer;
@ -399,10 +413,7 @@ begin
// We found a package link // We found a package link
case PackageAction of case PackageAction of
lpaBuild: lpaBuild:
begin exit(BuildPackage(Package.LPKFilename));
Result:=BuildPackage(Package.LPKFilename);
exit;
end;
lpaInstall: lpaInstall:
exit(true); // this is handled in AddPackagesToInstallList exit(true); // this is handled in AddPackagesToInstallList
end; end;
@ -766,28 +777,22 @@ end;
function TLazBuildApplication.BuildProject(const AFilename: string): boolean; function TLazBuildApplication.BuildProject(const AFilename: string): boolean;
var var
CompilerFilename: String; SrcFilename, TargetExeName, TargetExeDir: String;
WorkingDir: String;
SrcFilename: String;
CompilerParams, CmdLineParams: TStrings;
ToolBefore: TProjectCompilationToolOptions;
ToolAfter: TProjectCompilationToolOptions;
UnitOutputDirectory: String;
TargetExeName: String;
TargetExeDir: String;
CompilePolicy: TPackageUpdatePolicy;
i,MatchCount: Integer;
CompileHint: String;
CompReason: TCompileReason; CompReason: TCompileReason;
NeedBuildAllFlag: Boolean;
MatrixOption: TBuildMatrixOption;
ModeMask: TMask;
CurResult: Boolean;
function StartBuilding : boolean; function StartBuilding : boolean;
var var
NeedBuildAllFlag: Boolean;
CfgCode: TCodeBuffer; CfgCode: TCodeBuffer;
CfgFilename: String; CfgFilename: String;
CompilerParams, CmdLineParams: TStrings;
CompilerFilename, CompileHint: String;
UnitOutputDirectory: String;
MatrixOption: TBuildMatrixOption;
WorkingDir: String;
CompilePolicy: TPackageUpdatePolicy;
ToolBefore: TProjectCompilationToolOptions;
ToolAfter: TProjectCompilationToolOptions;
begin begin
Result := false; Result := false;
@ -851,8 +856,6 @@ var
Error(ErrorBuildFailed,'Unable to create project unit output directory '+UnitOutputDirectory); Error(ErrorBuildFailed,'Unable to create project unit output directory '+UnitOutputDirectory);
// create target output directory // create target output directory
TargetExeName := Project1.CompilerOptions.CreateTargetFilename;
TargetExeDir := ExtractFilePath(TargetExeName);
if not ForceDirectory(TargetExeDir) then if not ForceDirectory(TargetExeDir) then
Error(ErrorBuildFailed,'Unable to create project target directory '+TargetExeDir); Error(ErrorBuildFailed,'Unable to create project target directory '+TargetExeDir);
@ -937,6 +940,11 @@ var
end; end;
end; end;
var
i, MatchCount: Integer;
MacrosString: String;
ModeMask: TMask;
CurResult: Boolean;
begin begin
Result:=false; Result:=false;
CloseProject(Project1); CloseProject(Project1);
@ -953,6 +961,25 @@ begin
else else
CompReason:= crCompile; CompReason:= crCompile;
if HasOption('get-expand-text') then begin
MacrosString:=GetOptionValue('get-expand-text');
Project1.MacroEngine.SubstituteStr(MacrosString);
WriteLn(MacrosString);
exit(true);
end;
if HasOption('get-build-modes') then begin
ShowBuildModes;
exit(true);
end;
TargetExeName := Project1.CompilerOptions.CreateTargetFilename;
TargetExeDir := ExtractFilePath(TargetExeName);
if HasOption('get-exe-path') then begin
writeln(TargetExeDir);
exit(true);
end;
// first override build mode // first override build mode
if (BuildModeOverride<>'') then if (BuildModeOverride<>'') then
begin begin
@ -980,14 +1007,7 @@ begin
if Project1.BuildModes.Count>1 then if Project1.BuildModes.Count>1 then
begin begin
debugln(lisAvailableProjectBuildModes); debugln(lisAvailableProjectBuildModes);
for i:=0 to Project1.BuildModes.Count-1 do ShowBuildModes;
begin
if Project1.BuildModes[i]=Project1.ActiveBuildMode then
dbgout('* ')
else
dbgout(' ');
debugln(Project1.BuildModes[i].Identifier);
end;
end else begin end else begin
debugln(lisThisProjectHasOnlyTheDefaultBuildMode); debugln(lisThisProjectHasOnlyTheDefaultBuildMode);
end; end;
@ -1206,7 +1226,6 @@ begin
MainBuildBoss.SetBuildTarget(OSOverride,CPUOverride,SubtargetOverrideValue, MainBuildBoss.SetBuildTarget(OSOverride,CPUOverride,SubtargetOverrideValue,
WidgetSetOverride,smsfsSkip,true); WidgetSetOverride,smsfsSkip,true);
fInitResult:=true; fInitResult:=true;
Result:=fInitResult; Result:=fInitResult;
end; end;
@ -1215,29 +1234,26 @@ procedure TLazBuildApplication.LoadEnvironmentOptions;
var var
Note: string; Note: string;
begin begin
with EnvironmentOptions do begin EnvironmentOptions.CreateConfig;
CreateConfig; EnvironmentOptions.Load(false);
Load(false); fCompilerInCfg:=EnvironmentOptions.CompilerFilename;
fCompilerInCfg:=CompilerFilename; fLazarusDirInCfg:=EnvironmentOptions.LazarusDirectory;
fLazarusDirInCfg:=LazarusDirectory;
if LazBuildApp.HasOption('language') then begin if HasOption('language') then begin
if ConsoleVerbosity>=0 then if ConsoleVerbosity>=0 then
debugln('Note: (lazarus) overriding language with command line: ', debugln('Note: (lazarus) overriding language with command line: ', GetOptionValue('language'));
LazBuildApp.GetOptionValue('language')); EnvironmentOptions.LanguageID:=GetOptionValue('language');
EnvironmentOptions.LanguageID:=LazBuildApp.GetOptionValue('language');
end; end;
TranslateResourceStrings(EnvironmentOptions.GetParsedLazarusDirectory, TranslateResourceStrings(EnvironmentOptions.GetParsedLazarusDirectory,
EnvironmentOptions.LanguageID); EnvironmentOptions.LanguageID);
if CompilerOverride<>'' then if CompilerOverride<>'' then
CompilerFilename:=CompilerOverride; EnvironmentOptions.CompilerFilename:=CompilerOverride;
//debugln(['TLazBuildApplication.LoadEnvironmentOptions LazarusDirectory="',LazarusDirectory,'"']); //debugln(['TLazBuildApplication.LoadEnvironmentOptions LazarusDirectory="',LazarusDirectory,'"']);
if LazarusDirOverride<>'' then if LazarusDirOverride<>'' then
LazarusDirectory:=CleanAndExpandDirectory(LazarusDirOverride); EnvironmentOptions.LazarusDirectory:=CleanAndExpandDirectory(LazarusDirOverride);
if MaxProcessCount>=0 then if MaxProcessCount>=0 then
// set command line override // set command line override
MaxExtToolsInParallel:=MaxProcessCount; EnvironmentOptions.MaxExtToolsInParallel:=MaxProcessCount;
end;
if not FileExistsUTF8(EnvironmentOptions.GetParsedLazarusDirectory if not FileExistsUTF8(EnvironmentOptions.GetParsedLazarusDirectory
+GetForcedPathDelims('packager/registration/fcl.lpk')) +GetForcedPathDelims('packager/registration/fcl.lpk'))
then begin then begin
@ -1258,7 +1274,6 @@ end;
procedure TLazBuildApplication.SetupMacros; procedure TLazBuildApplication.SetupMacros;
begin begin
MainBuildBoss.SetupTransferMacros; MainBuildBoss.SetupTransferMacros;
(IDEMacros as TLazIDEMacros).LoadLazbuildMacros; (IDEMacros as TLazIDEMacros).LoadLazbuildMacros;
end; end;
@ -1618,6 +1633,9 @@ begin
LongOptions.Add('create-makefile'); LongOptions.Add('create-makefile');
LongOptions.Add('max-process-count:'); LongOptions.Add('max-process-count:');
LongOptions.Add('no-write-project'); LongOptions.Add('no-write-project');
LongOptions.Add('get-expand-text:');
LongOptions.Add('get-build-modes');
LongOptions.Add('get-exe-path');
ErrorMsg:=RepairedCheckOptions('lBrdq',LongOptions,Options,NonOptions); ErrorMsg:=RepairedCheckOptions('lBrdq',LongOptions,Options,NonOptions);
if ErrorMsg<>'' then begin if ErrorMsg<>'' then begin
writeln(ErrorMsg); writeln(ErrorMsg);
@ -1867,13 +1885,13 @@ begin
w(Format(lissecondaryConfigDirectoryWhereLazarusSearchesFor, [LazConf.GetSecondaryConfigPath])); w(Format(lissecondaryConfigDirectoryWhereLazarusSearchesFor, [LazConf.GetSecondaryConfigPath]));
writeln(''); writeln('');
writeln('--os=<operating-system>, --operating-system=<operating-system>'); writeln('--os=<operating-system>, --operating-system=<operating-system>');
w(Format(lisOverrideTheProjectOperatingSystemEGWin32LinuxDefau, [GetCompiledTargetOS])); w(Format(lisOverrideTheProjectOperatingSystemEGWin32LinuxDefau, [FPCAdds.GetCompiledTargetOS]));
writeln(''); writeln('');
writeln('--ws=<widgetset>, --widgetset=<widgetset>'); writeln('--ws=<widgetset>, --widgetset=<widgetset>');
w(Format(lisOverrideTheProjectWidgetsetEGGtkGtk2QtWin32CarbonD, [LCLPlatformDirNames[GetBuildLCLWidgetType]])); w(Format(lisOverrideTheProjectWidgetsetEGGtkGtk2QtWin32CarbonD, [LCLPlatformDirNames[GetBuildLCLWidgetType]]));
writeln(''); writeln('');
writeln('--cpu=<cpu>'); writeln('--cpu=<cpu>');
w(Format(lisOverrideTheProjectCpuEGI386X86_64PowerpcPowerpc_64, [GetCompiledTargetCPU])); w(Format(lisOverrideTheProjectCpuEGI386X86_64PowerpcPowerpc_64, [FPCAdds.GetCompiledTargetCPU]));
writeln(''); writeln('');
writeln('--subtarget=<subtarget>'); writeln('--subtarget=<subtarget>');
w(lisOverrideTheProjectSubtarg); w(lisOverrideTheProjectSubtarg);
@ -1896,6 +1914,15 @@ begin
writeln('--no-write-project'); writeln('--no-write-project');
w(lisDoNotWriteUpdatedProjectInfoAfterBuild); w(lisDoNotWriteUpdatedProjectInfoAfterBuild);
writeln(''); writeln('');
writeln('--get-expand-text=<count>');
w(lisGetExpandText);
writeln('');
writeln('--get-build-modes');
w(lisGetBuildModes);
writeln('');
writeln('--get-exe-path');
w(lisGetExePath);
writeln('');
end; end;
procedure TLazBuildApplication.Error(ErrorCode: Byte; const ErrorMsg: string); procedure TLazBuildApplication.Error(ErrorCode: Byte; const ErrorMsg: string);

View File

@ -154,7 +154,7 @@ begin
CfgFileDone := True; CfgFileDone := True;
CfgFileName := AppendPathDelim(ProgramDirectoryWithBundle) + 'lazarus.cfg'; CfgFileName := AppendPathDelim(ProgramDirectoryWithBundle) + 'lazarus.cfg';
if FileExistsUTF8(CfgFileName) then begin if FileExistsUTF8(CfgFileName) then begin
DebugLn(['using config file ', CfgFileName]); //DebugLn(['using config file ', CfgFileName]);
CfgFileContent := TStringList.Create; CfgFileContent := TStringList.Create;
CfgFileContent.LoadFromFile(CfgFileName); CfgFileContent.LoadFromFile(CfgFileName);
end; end;