mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-11 11:28:07 +02:00
* googleapiconv fixes and cleanup (ref #40094)
- Add updated URL for google api discovery - Fix incorrect usage / help messages and put options in alpha order - Replace "with .. do" statement with a local variable for clarity - Add missing DiscoveryJSONToPas.Execute so output files are not empty - Add FreeAndNil(Application) to clear a memory leak (it now has a clean Heaptrc) - Minor fix to .lpi file which had incorrect dependency.
This commit is contained in:
parent
fba7595bb1
commit
ab3aae149b
@ -34,7 +34,7 @@
|
|||||||
<CommandLineParams Value="-i apis/googleblogger.json -o gb.pp"/>
|
<CommandLineParams Value="-i apis/googleblogger.json -o gb.pp"/>
|
||||||
</local>
|
</local>
|
||||||
</RunParams>
|
</RunParams>
|
||||||
<Units Count="5">
|
<Units Count="4">
|
||||||
<Unit0>
|
<Unit0>
|
||||||
<Filename Value="googleapiconv.pp"/>
|
<Filename Value="googleapiconv.pp"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
@ -51,10 +51,6 @@
|
|||||||
<Filename Value="../src/base/googleclient.pp"/>
|
<Filename Value="../src/base/googleclient.pp"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
</Unit3>
|
</Unit3>
|
||||||
<Unit4>
|
|
||||||
<Filename Value="googlediscoverytopas.pp"/>
|
|
||||||
<IsPartOfProject Value="True"/>
|
|
||||||
</Unit4>
|
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
|
@ -20,7 +20,8 @@ uses
|
|||||||
googlediscoverytopas, googleservice, restbase, pascodegen, restcodegen;
|
googlediscoverytopas, googleservice, restbase, pascodegen, restcodegen;
|
||||||
|
|
||||||
Const
|
Const
|
||||||
BaseDiscoveryURL = 'https://www.googleapis.com/discovery/v1/apis/';
|
// BaseDiscoveryURL = 'https://www.googleapis.com/discovery/v1/apis/';
|
||||||
|
BaseDiscoveryURL = 'https://discovery.googleapis.com/discovery/v1/apis/';
|
||||||
|
|
||||||
|
|
||||||
Type
|
Type
|
||||||
@ -145,27 +146,27 @@ begin
|
|||||||
Writeln(' a) The service name will be appended to the output filename.');
|
Writeln(' a) The service name will be appended to the output filename.');
|
||||||
Writeln(' b) The --input will be used as a json which lists the services.');
|
Writeln(' b) The --input will be used as a json which lists the services.');
|
||||||
Writeln('-b --baseclass=classname Class name to use as parent class for all classes.');
|
Writeln('-b --baseclass=classname Class name to use as parent class for all classes.');
|
||||||
Writeln('-b --baseclass=classname Class name to use as parent class for all classes.');
|
Writeln('-d --onlydownload Just download the files, do not actually convert.');
|
||||||
Writeln('-m --fpmake=filename Generate fpmake program.');
|
Writeln(' Only effective if -k or --keepjson is also specified.');
|
||||||
Writeln('-e --extraunits=units comma separated list of units to add to uses clause.');
|
Writeln('-e --extraunits=units comma separated list of units to add to uses clause.');
|
||||||
|
Writeln('-f --unitprefix Prefix for generated unit names. Default is "google"');
|
||||||
Writeln('-h --help this message');
|
Writeln('-h --help this message');
|
||||||
Writeln('-i --input=file input filename (overrides non-option inputfile)');
|
Writeln('-i --input=file input filename (overrides non-option inputfile)');
|
||||||
Writeln('-I --icons Download service icon (size 16)');
|
Writeln('-I --icon Download service icon (size 16)');
|
||||||
|
Writeln('-k --keepjson Keep the downloaded JSON files');
|
||||||
Writeln('-L --license=licensetext Set license text to be added to the top of the unit.');
|
Writeln('-L --license=licensetext Set license text to be added to the top of the unit.');
|
||||||
Writeln(' Use @filename to load license text from filename');
|
Writeln(' Use @filename to load license text from filename');
|
||||||
|
Writeln('-m --fpmake=filename Generate fpmake program.');
|
||||||
Writeln('-o --output=file output filename (overrides non-option outputfile)');
|
Writeln('-o --output=file output filename (overrides non-option outputfile)');
|
||||||
Writeln(' Default is to use input filename with extension .pp');
|
Writeln(' Default is to use input filename with extension .pp');
|
||||||
Writeln('-p --classprefix=prefix Prefix to use in class names for all classes.');
|
Writeln('-p --classprefix=prefix Prefix to use in class names for all classes.');
|
||||||
Writeln('-r --resourcesuffix=suffix Suffix to use for resource names. Default is Resource.');
|
Writeln('-r --resourcesuffix=suffix Suffix to use for resource names. Default is Resource.');
|
||||||
Writeln('-R --register=unit Register unit for Lazarus.');
|
Writeln('-R --register=unit Register unit for Lazarus.');
|
||||||
|
Writeln('-s --service=servicename Service name to download the REST description for.');
|
||||||
Writeln('-t --timestamp Add timestamp to generated unit.');
|
Writeln('-t --timestamp Add timestamp to generated unit.');
|
||||||
Writeln('-u --url=URL URL to download the REST description from.');
|
Writeln('-u --url=URL URL to download the REST description from.');
|
||||||
Writeln('-v --serviceversion=v Service version to download the REST description for.');
|
Writeln('-v --serviceversion=v Service version to download the REST description for.');
|
||||||
Writeln('-V --verbose Write some diagnostic messages');
|
Writeln('-V --verbose Write some diagnostic messages');
|
||||||
Writeln('-k --keepjson Keep the downloaded JSON files');
|
|
||||||
Writeln('-d --onlydownload Just download the files, do not actually convert.');
|
|
||||||
Writeln(' Only effective if -k or --keepjson is also specified.');
|
|
||||||
Writeln('-f --unitprefix Prefix for generated unit names. Default is "google"');
|
|
||||||
Writeln('If the outputfilename is empty and cannot be determined, an error is returned');
|
Writeln('If the outputfilename is empty and cannot be determined, an error is returned');
|
||||||
Halt(Ord(Msg<>''));
|
Halt(Ord(Msg<>''));
|
||||||
end;
|
end;
|
||||||
@ -542,40 +543,41 @@ Procedure TGoogleAPIConverter.DoConversion(JS: TStream; AEntry: TAPIEntry);
|
|||||||
Var
|
Var
|
||||||
L: String;
|
L: String;
|
||||||
O : TGoogleIcons;
|
O : TGoogleIcons;
|
||||||
|
DiscoveryJSONToPas: TDiscoveryJSONToPas;
|
||||||
begin
|
begin
|
||||||
With TDiscoveryJSONToPas.Create(Nil) do
|
DiscoveryJSONToPas := TDiscoveryJSONToPas.Create(Nil);
|
||||||
try
|
try
|
||||||
L:=GetOptionValue('L','license');
|
L:=GetOptionValue('L','license');
|
||||||
if (L<>'') then
|
if (L<>'') then
|
||||||
|
begin
|
||||||
|
if (L[1]<>'@') then
|
||||||
|
DiscoveryJSONToPas.LicenseText.Text:=L
|
||||||
|
else
|
||||||
begin
|
begin
|
||||||
if (L[1]<>'@') then
|
Delete(L,1,1);
|
||||||
LicenseText.Text:=L
|
DiscoveryJSONToPas.LicenseText.LoadFromFile(L);
|
||||||
else
|
|
||||||
begin
|
|
||||||
Delete(L,1,1);
|
|
||||||
LicenseText.LoadFromFile(L);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
OnLog:=@ConversionLog;
|
end;
|
||||||
ExtraUnits:=GetOptionValue('e','extraunits');
|
DiscoveryJSONToPas.OnLog := @ConversionLog;
|
||||||
if HasOption('b','baseclass') then
|
DiscoveryJSONToPas.ExtraUnits:=GetOptionValue('e','extraunits');
|
||||||
BaseClassName:=GetOptionValue('b','baseclass');
|
if HasOption('b','baseclass') then
|
||||||
if HasOption('p','classprefix') then
|
DiscoveryJSONToPas.BaseClassName:=GetOptionValue('b','baseclass');
|
||||||
ClassPrefix:=GetOptionValue('p','classprefix');
|
if HasOption('p','classprefix') then
|
||||||
if HasOption('r','resourcesuffix') then
|
DiscoveryJSONToPas.ClassPrefix:=GetOptionValue('p','classprefix');
|
||||||
ResourceSuffix:=GetOptionValue('r','resourcesuffix');
|
if HasOption('r','resourcesuffix') then
|
||||||
AddTimeStamp:=HasOption('t','timestamp');
|
DiscoveryJSONToPas.ResourceSuffix:=GetOptionValue('r','resourcesuffix');
|
||||||
LoadFromStream(JS);
|
DiscoveryJSONToPas.AddTimeStamp:=HasOption('t','timestamp');
|
||||||
AEntry.APIUnitName:=ChangeFileExt(ExtractFileName(AEntry.FileName),'');
|
DiscoveryJSONToPas.LoadFromStream(JS);
|
||||||
AEntry.APIName:=APIClassName;
|
AEntry.APIUnitName:=ChangeFileExt(ExtractFileName(AEntry.FileName),'');
|
||||||
O:=Description.icons;
|
AEntry.APIName:=DiscoveryJSONToPas.APIClassName;
|
||||||
if Assigned(O) then
|
O:=DiscoveryJSONToPas.Description.icons;
|
||||||
AEntry.APIIcon:=O.x16;
|
if Assigned(O) then
|
||||||
SaveToFile(AEntry.FileName);
|
AEntry.APIIcon:=O.x16;
|
||||||
finally
|
DiscoveryJSONToPas.Execute;
|
||||||
Free;
|
DiscoveryJSONToPas.SaveToFile(AEntry.FileName);
|
||||||
end;
|
finally
|
||||||
|
DiscoveryJSONToPas.Free;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
@ -590,5 +592,6 @@ begin
|
|||||||
Application:=TGoogleAPIConverter.Create(Nil);
|
Application:=TGoogleAPIConverter.Create(Nil);
|
||||||
Application.Initialize;
|
Application.Initialize;
|
||||||
Application.Run;
|
Application.Run;
|
||||||
|
FreeAndNil(Application); //gets rid of memory leak and makes Heaptrc happy
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user