pas2js: started checking compiler executable

git-svn-id: trunk@56764 -
This commit is contained in:
mattias 2017-12-17 11:44:48 +00:00
parent 3011be98c3
commit 06998e316b
6 changed files with 217 additions and 134 deletions

1
.gitattributes vendored
View File

@ -3764,6 +3764,7 @@ components/pas2js/languages/pjsdsgnregister.pt_BR.po svneol=native#text/plain
components/pas2js/languages/pjsdsgnregister.ru.po svneol=native#text/plain
components/pas2js/pas2jsdsgn.lpk svneol=native#text/plain
components/pas2js/pas2jsdsgn.pas svneol=native#text/plain
components/pas2js/pjsdsgnoptions.pas svneol=native#text/plain
components/pas2js/pjsdsgnoptsframe.lfm svneol=native#text/plain
components/pas2js/pjsdsgnoptsframe.pas svneol=native#text/plain
components/pas2js/pjsdsgnregister.pas svneol=native#text/plain

View File

@ -16,27 +16,34 @@
</Parsing>
</CompilerOptions>
<Description Value="Adds a Lazarus project for pas2js browser applications."/>
<License Value="Modified LGPL-2"/>
<License Value="GPL-2"/>
<Version Major="1" Release="1"/>
<Files Count="2">
<Files Count="3">
<Item1>
<Filename Value="pjsdsgnregister.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="pjsdsgnregister"/>
<UnitName Value="PJSDsgnRegister"/>
</Item1>
<Item2>
<Filename Value="pjsdsgnoptsframe.pas"/>
<UnitName Value="pjsdsgnoptsframe"/>
<UnitName Value="PJSDsgnOptsFrame"/>
</Item2>
<Item3>
<Filename Value="pjsdsgnoptions.pas"/>
<UnitName Value="PJSDsgnOptions"/>
</Item3>
</Files>
<i18n>
<EnableI18N Value="True"/>
<OutDir Value="languages"/>
</i18n>
<RequiredPkgs Count="1">
<RequiredPkgs Count="2">
<Item1>
<PackageName Value="IDEIntf"/>
<PackageName Value="CodeTools"/>
</Item1>
<Item2>
<PackageName Value="IDEIntf"/>
</Item2>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)"/>

View File

@ -8,7 +8,7 @@ unit Pas2JSDsgn;
interface
uses
PJSDsgnRegister, PJSDsgnOptsFrame, LazarusPackageIntf;
PJSDsgnRegister, PJSDsgnOptsFrame, PJSDsgnOptions, LazarusPackageIntf;
implementation

View File

@ -0,0 +1,188 @@
{ pas2js options
Author: Mattias Gaertner
}
unit PJSDsgnOptions;
{$mode objfpc}{$H+}
{$Inline on}
interface
uses
Classes, SysUtils, LazFileCache, LazConfigStorage, LazFileUtils, FileUtil,
MacroIntf, BaseIDEIntf, IDEUtils,
DefineTemplates;
const
PJSDsgnOptsFile = 'pas2jsdsgnoptions.xml';
PJSDefaultCompiler = '$MakeExe(IDE,pas2js)';
type
{ TPas2jsOptions }
TPas2jsOptions = class
private
FChangeStamp: int64;
FSavedStamp: int64;
FCompilerFilename: string;
FCompilerFilenameStamp: int64;
FCompilerFilenameParsed: string;
function GetModified: boolean;
procedure SetModified(AValue: boolean);
procedure SetCompilerFilename(AValue: string);
public
constructor Create;
destructor Destroy; override;
procedure IncreaseChangeStamp; inline;
procedure Load;
procedure Save;
procedure LoadFromConfig(Cfg: TConfigStorage);
procedure SaveToConfig(Cfg: TConfigStorage);
function GetParsedCompilerFilename: string;
public
property CompilerFilename: string read FCompilerFilename write SetCompilerFilename;
property ChangeStamp: int64 read FChangeStamp;
property Modified: boolean read GetModified write SetModified;
end;
var
PJSOptions: TPas2jsOptions = nil;
function GetStandardPas2jsExe: string;
function GetPas2jsQuality(Filename: string; out Msg: string): boolean;
implementation
function GetStandardPas2jsExe: string;
begin
Result:='$MakeExe(IDE,pas2js)';
if not IDEMacros.SubstituteMacros(Result) then
Result:='pas2js';
end;
function GetPas2jsQuality(Filename: string; out Msg: string): boolean;
var
ShortFile: String;
begin
Msg:='';
Filename:=TrimFilename(Filename);
if (Filename='') then begin
Msg:='missing path to pas2js';
exit(false);
end;
if not FileExistsCached(Filename) then begin
Msg:='file "'+Filename+'" not found';
exit(false);
end;
if not DirPathExistsCached(ExtractFilePath(Filename)) then begin
Msg:='directory "'+ExtractFilePath(Filename)+'" not found';
exit(false);
end;
if not FileIsExecutable(Filename) then begin
Msg:='file "'+Filename+'" not executable';
exit(false);
end;
ShortFile:=ExtractFileNameOnly(Filename);
if not CompareText(LeftStr(ShortFile,length('pas2js')),'pas2js')<>0 then begin
Msg:='file name does not start with "pas2js"';
exit(false);
end;
// run it
//RunTool(Filename);
end;
{ TPas2jsOptions }
procedure TPas2jsOptions.SetModified(AValue: boolean);
begin
if AValue then
IncreaseChangeStamp
else
FSavedStamp:=FChangeStamp;
end;
function TPas2jsOptions.GetModified: boolean;
begin
Result:=FSavedStamp<>FChangeStamp;
end;
procedure TPas2jsOptions.SetCompilerFilename(AValue: string);
begin
if FCompilerFilename=AValue then Exit;
FCompilerFilename:=AValue;
IncreaseChangeStamp;
IDEMacros.IncreaseBaseStamp;
end;
constructor TPas2jsOptions.Create;
begin
FChangeStamp:=LUInvalidChangeStamp64;
FCompilerFilename:=PJSDefaultCompiler;
end;
destructor TPas2jsOptions.Destroy;
begin
inherited Destroy;
end;
procedure TPas2jsOptions.IncreaseChangeStamp;
begin
LUIncreaseChangeStamp64(FChangeStamp);
end;
procedure TPas2jsOptions.Load;
var
Cfg: TConfigStorage;
begin
Cfg:=GetIDEConfigStorage(PJSDsgnOptsFile,true);
try
LoadFromConfig(Cfg);
finally
Cfg.Free;
end;
end;
procedure TPas2jsOptions.Save;
var
Cfg: TConfigStorage;
begin
Cfg:=GetIDEConfigStorage(PJSDsgnOptsFile,false);
try
SaveToConfig(Cfg);
finally
Cfg.Free;
end;
end;
procedure TPas2jsOptions.LoadFromConfig(Cfg: TConfigStorage);
begin
CompilerFilename:=Cfg.GetValue('compiler/value',PJSDefaultCompiler);
Modified:=false;
end;
procedure TPas2jsOptions.SaveToConfig(Cfg: TConfigStorage);
begin
Cfg.SetDeleteValue('compiler/value',CompilerFilename,PJSDefaultCompiler);
end;
function TPas2jsOptions.GetParsedCompilerFilename: string;
begin
if FCompilerFilenameStamp<>IDEMacros.BaseTimeStamp then begin
FCompilerFilenameStamp:=IDEMacros.BaseTimeStamp;
FCompilerFilenameParsed:=FCompilerFilename;
IDEMacros.SubstituteMacros(FCompilerFilenameParsed);
FCompilerFilenameParsed:=TrimFilename(FCompilerFilenameParsed);
if (FCompilerFilenameParsed<>'')
and not FilenameIsAbsolute(FCompilerFilenameParsed) then begin
FCompilerFilenameParsed:=FindDefaultExecutablePath(FCompilerFilenameParsed);
end;
end;
Result:=FCompilerFilenameParsed;
end;
finalization
FreeAndNil(PJSOptions);
end.

View File

@ -1,6 +1,6 @@
{ Installs pas2js options frame in the Lazarus IDE.
{ IDE options frame for pas2js options
Copyright (C) 2017 Mattias Gaertner mattias@freepascal.org
Author: Mattias Gaertner
}
unit PJSDsgnOptsFrame;
@ -10,40 +10,12 @@ unit PJSDsgnOptsFrame;
interface
uses
Classes, SysUtils, Forms, Controls, StdCtrls, Dialogs, IDEOptionsIntf,
MacroIntf, BaseIDEIntf, IDEUtils, LazFileCache, LazConfigStorage,
LazFileUtils;
const
PJSDsgnOptsFile = 'pas2jsdsgnoptions.xml';
PJSDefaultCompiler = '$MakeExe(IDE,pas2js)';
Classes, SysUtils, LazFileCache, LazConfigStorage, LazFileUtils, FileUtil,
Forms, Controls, StdCtrls, Dialogs,
IDEOptionsIntf, MacroIntf, BaseIDEIntf, IDEUtils,
PJSDsgnOptions;
type
{ TPas2jsOptions }
TPas2jsOptions = class
private
FChangeStamp: int64;
FSavedStamp: int64;
FCompilerFilename: string;
function GetModified: boolean;
procedure SetModified(AValue: boolean);
procedure SetCompilerFilename(AValue: string);
public
constructor Create;
destructor Destroy; override;
procedure IncreaseChangeStamp; inline;
procedure Load;
procedure Save;
procedure LoadFromConfig(Cfg: TConfigStorage);
procedure SaveToConfig(Cfg: TConfigStorage);
public
property CompilerFilename: string read FCompilerFilename write SetCompilerFilename;
property ChangeStamp: int64 read FChangeStamp;
property Modified: boolean read GetModified write SetModified;
end;
{ TPas2jsOptionsFrame }
TPas2jsOptionsFrame = class(TAbstractIDEOptionsEditor)
@ -55,101 +27,16 @@ type
function CheckCompiler(Buttons: TMsgDlgButtons): boolean;
public
function GetTitle: String; override;
procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
procedure ReadSettings({%H-}AOptions: TAbstractIDEOptions); override;
procedure WriteSettings({%H-}AOptions: TAbstractIDEOptions); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
end;
var
PJSOptions: TPas2jsOptions = nil;
function GetStandardPas2jsExe: string;
implementation
function GetStandardPas2jsExe: string;
begin
Result:='$MakeExe(IDE,pas2js)';
if not IDEMacros.SubstituteMacros(Result) then
Result:='pas2js';
end;
{$R *.lfm}
{ TPas2jsOptions }
procedure TPas2jsOptions.SetModified(AValue: boolean);
begin
if AValue then
IncreaseChangeStamp
else
FSavedStamp:=FChangeStamp;
end;
function TPas2jsOptions.GetModified: boolean;
begin
Result:=FSavedStamp<>FChangeStamp;
end;
procedure TPas2jsOptions.SetCompilerFilename(AValue: string);
begin
if FCompilerFilename=AValue then Exit;
FCompilerFilename:=AValue;
IncreaseChangeStamp;
end;
constructor TPas2jsOptions.Create;
begin
FChangeStamp:=LUInvalidChangeStamp64;
FCompilerFilename:=PJSDefaultCompiler;
end;
destructor TPas2jsOptions.Destroy;
begin
inherited Destroy;
end;
procedure TPas2jsOptions.IncreaseChangeStamp;
begin
LUIncreaseChangeStamp64(FChangeStamp);
end;
procedure TPas2jsOptions.Load;
var
Cfg: TConfigStorage;
begin
Cfg:=GetIDEConfigStorage(PJSDsgnOptsFile,true);
try
LoadFromConfig(Cfg);
finally
Cfg.Free;
end;
end;
procedure TPas2jsOptions.Save;
var
Cfg: TConfigStorage;
begin
Cfg:=GetIDEConfigStorage(PJSDsgnOptsFile,false);
try
SaveToConfig(Cfg);
finally
Cfg.Free;
end;
end;
procedure TPas2jsOptions.LoadFromConfig(Cfg: TConfigStorage);
begin
CompilerFilename:=Cfg.GetValue('compiler/value',PJSDefaultCompiler);
Modified:=false;
end;
procedure TPas2jsOptions.SaveToConfig(Cfg: TConfigStorage);
begin
Cfg.SetDeleteValue('compiler/value',CompilerFilename,PJSDefaultCompiler);
end;
{ TPas2jsOptionsFrame }
procedure TPas2jsOptionsFrame.Pas2jsPathBrowseButtonClick(Sender: TObject);
@ -174,12 +61,13 @@ end;
function TPas2jsOptionsFrame.CheckCompiler(Buttons: TMsgDlgButtons): boolean;
var
NewExe: TCaption;
NewExe: string;
begin
NewExe:=Pas2jsPathComboBox.Text;
if NewExe=PJSOptions.CompilerFilename then exit(true);
Result:=false;
PJSOptions.CompilerFilename:=NewExe;
// ToDo: check file
//NewExe:=PJSOptions.GetParsedCompilerExe;
end;
@ -214,7 +102,5 @@ begin
Result:=IDEEditorGroups.GetByIndex(GroupEnvironment)^.GroupClass;
end;
finalization
FreeAndNil(PJSOptions);
end.

View File

@ -5,8 +5,9 @@ unit PJSDsgnRegister;
interface
uses
Classes, SysUtils, ProjectIntf, CompOptsIntf, LazIDEIntf, IDEOptionsIntf,
PJSDsgnOptsFrame, Forms, Controls;
Classes, SysUtils, Forms, Controls,
ProjectIntf, CompOptsIntf, LazIDEIntf, IDEOptionsIntf,
PJSDsgnOptions, PJSDsgnOptsFrame;
const
ProjDescNamePas2JSWebApp = 'Web Application';