mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-19 23:49:36 +02:00
LazBuild: Fix the logic for case insensitive long options. Issue #40217.
This commit is contained in:
parent
a82f0d4e39
commit
3e977099f1
125
ide/lazbuild.lpr
125
ide/lazbuild.lpr
@ -79,6 +79,9 @@ type
|
||||
FSkipDependencies: boolean;
|
||||
fWidgetsetOverride: String;
|
||||
|
||||
function HasLongOptIgnoreCase(const S: String; out aValue: String): Boolean;
|
||||
function HasShortOrLongOpt(const C: Char; const S: String): Boolean;
|
||||
|
||||
// codetools
|
||||
procedure OnCodeBufferDecodeLoaded({%H-}Code: TCodeBuffer;
|
||||
const {%H-}Filename: string; var Source, DiskEncoding, MemEncoding: string);
|
||||
@ -167,8 +170,7 @@ type
|
||||
property BuildIDE: boolean read FBuildIDE write FBuildIDE; // build IDE (as opposed to a project/package etc)
|
||||
property BuildIDEOptions: string read FBuildIDEOptions write FBuildIDEOptions;
|
||||
property CreateMakefile: boolean read FCreateMakefile write FCreateMakefile;
|
||||
property WidgetSetOverride: String read fWidgetsetOverride
|
||||
write fWidgetsetOverride;
|
||||
property WidgetSetOverride: String read FWidgetsetOverride write FWidgetsetOverride;
|
||||
property OSOverride: String read fOSOverride write fOSOverride;
|
||||
property CPUOverride: String read fCPUOverride write fCPUOverride;
|
||||
property CompilerOverride: String read fCompilerOverride write fCompilerOverride;
|
||||
@ -1312,23 +1314,21 @@ end;
|
||||
function TLazBuildApplication.RepairedCheckOptions(const ShortOptions: String;
|
||||
const Longopts: TStrings; Opts, NonOpts: TStrings): String;
|
||||
|
||||
Function FindLongOpt(S : String) : boolean;
|
||||
Var
|
||||
I : integer;
|
||||
begin
|
||||
I:=LongOpts.Count-1;
|
||||
While (I>=0) and (LongOpts[I]<>S) do
|
||||
Dec(I);
|
||||
Result:=(I<>-1);
|
||||
end;
|
||||
|
||||
Var
|
||||
I,J,L,P : Integer;
|
||||
O,OV : String;
|
||||
HaveArg : Boolean;
|
||||
NeedArg: Boolean;
|
||||
|
||||
Function FindLongOpt(S : String) : boolean;
|
||||
Var
|
||||
I : integer;
|
||||
begin
|
||||
S:=LowerCase(S);
|
||||
I:=LongOpts.Count-1;
|
||||
While (I>=0) and (LowerCase(LongOpts[i])<>S) do
|
||||
Dec(i);
|
||||
Result:=(I<>-1);
|
||||
end;
|
||||
|
||||
begin
|
||||
Result:='';
|
||||
I:=1;
|
||||
@ -1360,6 +1360,7 @@ begin
|
||||
Delete(OV,1,J);
|
||||
O:=Copy(O,1,J-1);
|
||||
end;
|
||||
O:=LowerCase(O); // Long options are case-insensitive.
|
||||
// Switch Option
|
||||
If FindLongopt(O) then
|
||||
begin
|
||||
@ -1500,17 +1501,37 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
Function TLazBuildApplication.HasLongOptIgnoreCase(const S: String; out aValue: String): Boolean;
|
||||
// Check existence of a long option case-insensitively.
|
||||
begin
|
||||
CaseSensitiveOptions:=False;
|
||||
Result:=HasOption(S);
|
||||
if Result then
|
||||
aValue:=GetOptionValue(S)
|
||||
else
|
||||
aValue:='';
|
||||
CaseSensitiveOptions:=True;
|
||||
end;
|
||||
|
||||
Function TLazBuildApplication.HasShortOrLongOpt(const C: Char; const S: String): Boolean;
|
||||
// Check existence of a short option casesensitively and long option case-insensitively.
|
||||
begin
|
||||
Result:=HasOption(C);
|
||||
CaseSensitiveOptions:=False;
|
||||
Result:=Result or HasOption(S);
|
||||
CaseSensitiveOptions:=True;
|
||||
end;
|
||||
|
||||
function TLazBuildApplication.ParseParameters: boolean;
|
||||
var
|
||||
Options: TStringList;
|
||||
NonOptions: TStringList;
|
||||
ErrorMsg: String;
|
||||
LongOptions: TStringList;
|
||||
i: Integer;
|
||||
p: String;
|
||||
p, ErrorMsg: String;
|
||||
FilesNeeded: Boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
Result:=False;
|
||||
if (ToolParamCount<=0)
|
||||
or (CompareText(ToolParamStr(1),'--help')=0)
|
||||
or (CompareText(ToolParamStr(1),'-help')=0)
|
||||
@ -1520,11 +1541,11 @@ begin
|
||||
WriteUsage;
|
||||
exit;
|
||||
end;
|
||||
if HasOption('h','help') or HasOption('?') then begin
|
||||
if HasShortOrLongOpt('h','help') or HasOption('?') then begin
|
||||
WriteUsage;
|
||||
exit;
|
||||
end;
|
||||
if HasOption('v','version') then begin
|
||||
if HasShortOrLongOpt('v','version') then begin
|
||||
writeln(VersionStr);
|
||||
exit;
|
||||
end;
|
||||
@ -1578,11 +1599,11 @@ begin
|
||||
|
||||
FilesNeeded:=true;
|
||||
|
||||
if HasOption('verbose-pkgsearch') then
|
||||
if HasLongOptIgnoreCase('verbose-pkgsearch',p) then
|
||||
Include(fPkgGraphVerbosity,pvPkgSearch);
|
||||
|
||||
// PackageAction: register lpk files
|
||||
if HasOption('add-package-link') then begin
|
||||
if HasLongOptIgnoreCase('add-package-link',p) then begin
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: add-package-link');
|
||||
if PackageAction<>lpaBuild then begin
|
||||
@ -1595,7 +1616,7 @@ begin
|
||||
end;
|
||||
|
||||
// PackageAction: install lpk files
|
||||
if HasOption('add-package') then begin
|
||||
if HasLongOptIgnoreCase('add-package',p) then begin
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: add-package');
|
||||
if PackageAction<>lpaBuild then begin
|
||||
@ -1608,9 +1629,8 @@ begin
|
||||
end;
|
||||
|
||||
// building IDE
|
||||
if HasOption('build-ide') then begin
|
||||
if HasLongOptIgnoreCase('build-ide', FBuildIDEOptions) then begin
|
||||
BuildIDE:=true;
|
||||
BuildIDEOptions:=GetOptionValue('build-ide');
|
||||
FilesNeeded:=false;
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: build-ide=',BuildIDEOptions);
|
||||
@ -1625,40 +1645,40 @@ begin
|
||||
end;
|
||||
|
||||
// primary config path
|
||||
if HasOption('primary-config-path') then begin
|
||||
SetPrimaryConfigPath(GetOptionValue('primary-config-path'));
|
||||
if HasLongOptIgnoreCase('primary-config-path',p) then begin
|
||||
SetPrimaryConfigPath(p);
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: primary-config-path=',GetPrimaryConfigPath);
|
||||
end else if HasOption('pcp') then begin
|
||||
SetPrimaryConfigPath(GetOptionValue('pcp'));
|
||||
end else if HasLongOptIgnoreCase('pcp',p) then begin
|
||||
SetPrimaryConfigPath(p);
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: pcp=',GetPrimaryConfigPath);
|
||||
end;
|
||||
|
||||
// secondary config path
|
||||
if HasOption('secondary-config-path') then begin
|
||||
SetPrimaryConfigPath(GetOptionValue('secondary-config-path'));
|
||||
if HasLongOptIgnoreCase('secondary-config-path',p) then begin
|
||||
SetPrimaryConfigPath(p);
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: secondary-config-path=',GetSecondaryConfigPath);
|
||||
end else if HasOption('scp') then begin
|
||||
SetSecondaryConfigPath(GetOptionValue('scp'));
|
||||
end else if HasLongOptIgnoreCase('scp',p) then begin
|
||||
SetSecondaryConfigPath(p);
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: scp=',GetSecondaryConfigPath);
|
||||
end;
|
||||
|
||||
// build all
|
||||
if HasOption('B','build-all') then begin
|
||||
if HasShortOrLongOpt('B','build-all') then begin
|
||||
BuildAll:=true;
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: build-all');
|
||||
end;
|
||||
if HasOption('r','recursive') then begin
|
||||
if HasShortOrLongOpt('r','recursive') then begin
|
||||
BuildAll:=true;
|
||||
BuildRecursive:=true;
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: recursive');
|
||||
end;
|
||||
if HasOption('d','skip-dependencies') then begin
|
||||
if HasShortOrLongOpt('d','skip-dependencies') then begin
|
||||
SkipDependencies:=true;
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: skip-dependencies');
|
||||
@ -1671,74 +1691,65 @@ begin
|
||||
|
||||
// overides
|
||||
// widgetset
|
||||
if HasOption('ws') then begin
|
||||
WidgetSetOverride := GetOptionValue('ws');
|
||||
if HasLongOptIgnoreCase('ws',FWidgetSetOverride) then begin
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: ws=',WidgetSetOverride);
|
||||
end else if HasOption('widgetset') then begin
|
||||
WidgetSetOverride := GetOptionValue('widgetset');
|
||||
end else if HasLongOptIgnoreCase('widgetset',FWidgetSetOverride) then begin
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: widgetset=',WidgetSetOverride);
|
||||
end;
|
||||
|
||||
// operating system
|
||||
if HasOption('os') then begin
|
||||
OSOverride := GetOptionValue('os');
|
||||
if HasLongOptIgnoreCase('os',FOSOverride) then begin
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: os=',OSOverride);
|
||||
end else if HasOption('operating-system') then begin
|
||||
OSOverride := GetOptionValue('operating-system');
|
||||
end else if HasLongOptIgnoreCase('operating-system',FOSOverride) then begin
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: operating-system=',OSOverride);
|
||||
end;
|
||||
|
||||
// cpu
|
||||
if HasOption('cpu') then begin
|
||||
CPUOverride := GetOptionValue('cpu');
|
||||
if HasLongOptIgnoreCase('cpu',FCPUOverride) then begin
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: cpu=',CPUOverride);
|
||||
end;
|
||||
|
||||
// build mode
|
||||
if HasOption('bm') then begin
|
||||
BuildModeOverride := GetOptionValue('bm');
|
||||
if HasLongOptIgnoreCase('bm',FBuildModeOverride) then begin
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: bm=',BuildModeOverride);
|
||||
end else if HasOption('build-mode') then begin
|
||||
BuildModeOverride := GetOptionValue('build-mode');
|
||||
end else if HasLongOptIgnoreCase('build-mode',FBuildModeOverride) then begin
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: build-mode=',BuildModeOverride);
|
||||
end;
|
||||
|
||||
// compiler
|
||||
if HasOption('compiler') then begin
|
||||
CompilerOverride := GetOptionValue('compiler');
|
||||
if HasLongOptIgnoreCase('compiler',FCompilerOverride) then begin
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: compiler=',CompilerOverride);
|
||||
end;
|
||||
|
||||
// lazarusdir
|
||||
if HasOption('lazarusdir') then begin
|
||||
LazarusDirOverride := GetOptionValue('lazarusdir');
|
||||
if HasLongOptIgnoreCase('lazarusdir',FLazarusDirOverride) then begin
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: lazarusdir=',LazarusDirOverride);
|
||||
end;
|
||||
|
||||
// max-process-count
|
||||
if HasOption('max-process-count') then begin
|
||||
MaxProcessCount:=StrToInt(GetOptionValue('max-process-count'));
|
||||
if HasLongOptIgnoreCase('max-process-count',p) then begin
|
||||
MaxProcessCount:=StrToInt(p);
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: max-process-count=',MaxProcessCount);
|
||||
end;
|
||||
|
||||
if HasOption('no-write-project') then
|
||||
if HasLongOptIgnoreCase('no-write-project',p) then
|
||||
begin
|
||||
NoWriteProject := true;
|
||||
if ConsoleVerbosity>=0 then
|
||||
writeln('Parameter: no-write-project');
|
||||
end;
|
||||
|
||||
if HasOption('create-makefile') then
|
||||
if HasLongOptIgnoreCase('create-makefile',p) then
|
||||
begin
|
||||
CreateMakefile := true;
|
||||
if ConsoleVerbosity>=0 then
|
||||
|
Loading…
Reference in New Issue
Block a user