codetools: sourcecloser: option to add compiler options

git-svn-id: trunk@42546 -
This commit is contained in:
mattias 2013-09-01 15:26:24 +00:00
parent 05147efc44
commit 1925d86093

View File

@ -52,10 +52,10 @@ type
TSourceCloser = class(TCustomApplication) TSourceCloser = class(TCustomApplication)
private private
FCompilerOptions: string;
FDefines: TStringToStringTree; FDefines: TStringToStringTree;
FIncludePath: string; FIncludePath: string;
FLPKFilenames: TStrings; FLPKFilenames: TStrings;
FRemoveComments: boolean;
FUndefines: TStringToStringTree; FUndefines: TStringToStringTree;
FUnitFilenames: TStrings; FUnitFilenames: TStrings;
FVerbosity: integer; FVerbosity: integer;
@ -70,12 +70,12 @@ type
destructor Destroy; override; destructor Destroy; override;
procedure WriteHelp; virtual; procedure WriteHelp; virtual;
property Verbosity: integer read FVerbosity write FVerbosity; property Verbosity: integer read FVerbosity write FVerbosity;
property RemoveComments: boolean read FRemoveComments write FRemoveComments;
property Defines: TStringToStringTree read FDefines; property Defines: TStringToStringTree read FDefines;
property Undefines: TStringToStringTree read FUndefines; property Undefines: TStringToStringTree read FUndefines;
property IncludePath: string read FIncludePath write FIncludePath; property IncludePath: string read FIncludePath write FIncludePath;
property LPKFilenames: TStrings read FLPKFilenames; property LPKFilenames: TStrings read FLPKFilenames;
property UnitFilenames: TStrings read FUnitFilenames; property UnitFilenames: TStrings read FUnitFilenames;
property CompilerOptions: string read FCompilerOptions write FCompilerOptions;
end; end;
function IndexOfFilename(List: TStrings; Filename: string): integer; function IndexOfFilename(List: TStrings; Filename: string): integer;
@ -113,8 +113,8 @@ end;
procedure TSourceCloser.DoRun; procedure TSourceCloser.DoRun;
const const
ShortOpts = 'hvqrd:u:i:t:'; ShortOpts = 'hvqc:d:u:i:';
LongOpts = 'help verbose quiet removecomments define: undefine: includepath:'; LongOpts = 'help verbose quiet compileroptions: define: undefine: includepath:';
procedure E(Msg: string; WithHelp: boolean = false); procedure E(Msg: string; WithHelp: boolean = false);
begin begin
@ -128,6 +128,10 @@ const
procedure ParseValueParam(ShortOpt: char; Value: string); procedure ParseValueParam(ShortOpt: char; Value: string);
begin begin
case ShortOpt of case ShortOpt of
'c':
begin
FCompilerOptions+=Value;
end;
'i': 'i':
begin begin
Value:=UTF8Trim(Value,[]); Value:=UTF8Trim(Value,[]);
@ -216,8 +220,6 @@ begin
dec(fVerbosity) dec(fVerbosity)
else if (Param='-v') or (Param='--verbose') then else if (Param='-v') or (Param='--verbose') then
inc(fVerbosity) inc(fVerbosity)
else if (Param='-r') or (Param='--removecomments') then
RemoveComments:=true
else if Param[1]<>'-' then begin else if Param[1]<>'-' then begin
Filename:=TrimAndExpandFilename(Param); Filename:=TrimAndExpandFilename(Param);
if (Pos('*',ExtractFileName(Filename))>0) or (Pos('?',ExtractFileName(Filename))>0) if (Pos('*',ExtractFileName(Filename))>0) or (Pos('?',ExtractFileName(Filename))>0)
@ -244,7 +246,7 @@ begin
E('invalid option: '+Param); E('invalid option: '+Param);
Option:=copy(Param,3,p-3); Option:=copy(Param,3,p-3);
delete(Param,1,p); delete(Param,1,p);
if Option='target' then Option:='t' if Option='compileroptions' then Option:='c'
else if Option='define' then Option:='d' else if Option='define' then Option:='d'
else if Option='undefine' then Option:='u' else if Option='undefine' then Option:='u'
else if Option='includepath' then Option:='i' else if Option='includepath' then Option:='i'
@ -258,7 +260,6 @@ begin
if Verbosity>0 then begin if Verbosity>0 then begin
debugln(['Options:']); debugln(['Options:']);
debugln(['Verbosity=',Verbosity]); debugln(['Verbosity=',Verbosity]);
debugln(['RemoveComments=',RemoveComments]);
debugln(['IncludePath=',IncludePath]); debugln(['IncludePath=',IncludePath]);
for S2SItem in Defines do for S2SItem in Defines do
debugln('Define:',S2SItem^.Name); debugln('Define:',S2SItem^.Name);
@ -326,6 +327,7 @@ const
var var
xml: TXMLConfig; xml: TXMLConfig;
CustomOptions: String; CustomOptions: String;
NewOptions: String;
begin begin
debugln(['Converting lpk: ',LPKFilename]); debugln(['Converting lpk: ',LPKFilename]);
xml:=TXMLConfig.Create(LPKFilename); xml:=TXMLConfig.Create(LPKFilename);
@ -335,11 +337,16 @@ begin
// add -Ur to compiler options // add -Ur to compiler options
CustomOptions:=xml.GetValue(CustomOptionsPath,''); CustomOptions:=xml.GetValue(CustomOptionsPath,'');
if Pos('-Ur',CustomOptions)<1 then begin NewOptions:=CustomOptions;
if CustomOptions<>'' then CustomOptions+=' '; if Pos('-Ur',NewOptions)<1 then begin
CustomOptions+='-Ur'; if NewOptions<>'' then NewOptions+=' ';
xml.SetValue(CustomOptionsPath,CustomOptions); NewOptions+='-Ur';
end; end;
if FCompilerOptions<>'' then begin
if NewOptions<>'' then NewOptions+=' ';
NewOptions+=FCompilerOptions;
end;
xml.SetValue(CustomOptionsPath,NewOptions);
// write // write
xml.Flush; xml.Flush;
@ -452,16 +459,15 @@ begin
writeln(' You can pass multiple lpk files and they will be edited in this order.'); writeln(' You can pass multiple lpk files and they will be edited in this order.');
writeln(' If you pass a .pas or .pp file it will be treated as a pascal unit and'); writeln(' If you pass a .pas or .pp file it will be treated as a pascal unit and');
writeln(' will remove the implementation, initialization, finalization sections.'); writeln(' will remove the implementation, initialization, finalization sections.');
//writeln(' If you pass the removecomments option the comments in the units will');
//writeln(' removed as well.');
//writeln(' If you pass the target option, lazbuild is called once for each lpk');
//writeln(' and each target.');
writeln; writeln;
writeln('Options:'); writeln('Options:');
writeln(' -h, --help : This help messages.'); writeln(' -h, --help : This help messages.');
writeln(' -v, --verbose : be more verbose.'); writeln(' -v, --verbose : be more verbose.');
writeln(' -q, --quiet : be more quiet.'); writeln(' -q, --quiet : be more quiet.');
writeln(' -r, --removecomments : remove comments from units'); writeln('Package/lpk options:');
writeln(' --compileroptions=<compiler options>');
writeln(' Add custom compiler options to lpk.');
writeln('Unit options:');
writeln(' -d <MacroName>, --define=<MacroName> :'); writeln(' -d <MacroName>, --define=<MacroName> :');
writeln(' Define Free Pascal macro. Can be passed multiple times.'); writeln(' Define Free Pascal macro. Can be passed multiple times.');
writeln(' -u <MacroName>, --undefine=<MacroName> :'); writeln(' -u <MacroName>, --undefine=<MacroName> :');