Skip to content

Commit

Permalink
simba.env refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jul 11, 2023
1 parent 33ef3fd commit a28c486
Show file tree
Hide file tree
Showing 30 changed files with 147 additions and 342 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,15 @@ jobs:
- name: Test Simba
if: matrix.config.test != ''
run: |
if [ "${{ matrix.config.runs-on }}" = "ubuntu-20.04" ]; then
if [[ "${{ matrix.config.runs-on }}" == ubuntu* ]]; then
export DISPLAY=:1
Xvfb :1 & sleep 2
fi
if [ "${{ matrix.config.runs-on }}" != "windows-latest" ]; then
chmod +x ${{ matrix.config.test }}
fi
./${{ matrix.config.test }} --run "Tests/tester.simba"
chmod +x ${{ matrix.config.test }}
./${{ matrix.config.test }} --run "Tests/RunTests/tester.simba"
- name: Upload Binary
- name: Upload Simba Binary
uses: actions/upload-artifact@v3.1.2
with:
name: ${{ matrix.config.binary }}
Expand Down
2 changes: 1 addition & 1 deletion Source/codetools/simba.ide_codetools_setup.pas
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ procedure SetupCodeTools;
List := nil;

try
List := SimbaProcess.RunDump(HashFile(Application.ExeName), ['--dumpcompiler']);
List := SimbaProcess.RunDump(Application.ExeName, ['--dumpcompiler']);

for I := 0 to List.Count - 1 do
begin
Expand Down
6 changes: 3 additions & 3 deletions Source/codetools/simba.ide_codetools_utils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ function FindInclude(Sender: TmwBasePasLex): String;
case Sender.TokenID of
tokLibraryDirect:
begin
if FindPlugin(FileName, [ExtractFileDir(Sender.FileName), GetPluginPath(), GetSimbaPath()]) then
if FindPlugin(FileName, [ExtractFileDir(Sender.FileName)]) then
Result := FileName;
end;

tokIncludeDirect, tokIncludeOnceDirect:
begin
if FindFile(FileName, '', [ExtractFileDir(Sender.FileName), GetIncludePath(), GetSimbaPath()]) then
if simba.env.FindInclude(FileName, [ExtractFileDir(Sender.FileName)]) then
Result := FileName;
end;
end;
Expand All @@ -180,7 +180,7 @@ function FindPluginExports(FileName: String): String;

List := nil;
try
List := SimbaProcess.RunDump(HashFile(FileName), ['--dumpplugin=' + FileName]);
List := SimbaProcess.RunDump(FileName, ['--dumpplugin=' + FileName]);

Result := List.Text;
except
Expand Down
4 changes: 2 additions & 2 deletions Source/forms/simba.aboutform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ implementation

uses
lclintf, lazversion,
simba.env;
simba.files;

procedure TSimbaAboutForm.DoFirstShow(Sender: TObject);
begin
Expand All @@ -56,7 +56,7 @@ procedure TSimbaAboutForm.DoFirstShow(Sender: TObject);
AboutMemo.Lines.Add(' FPC %d.%d.%d', [FPC_VERSION, FPC_RELEASE, FPC_PATCH]);
AboutMemo.Lines.Add(' Lazarus version %s', [LAZ_VERSION]);
AboutMemo.Lines.Add('');
AboutMemo.Lines.Add('Binary hash: %s', [HashFile(Application.ExeName)]);
AboutMemo.Lines.Add('Simba SHA1 hash: %s', [TSimbaFile.FileHash(Application.ExeName)]);

if (SIMBA_COMMIT <> '') then
begin
Expand Down
4 changes: 2 additions & 2 deletions Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ procedure TSimbaForm.HandleException(Sender: TObject; E: Exception);

DumpStack(Log);

FileName := GetDataPath() + FormatDateTime('dd-mm_hh-mm-ss', Now()) + '.crash';
FileName := SimbaEnv.DataPath + FormatDateTime('dd-mm_hh-mm-ss', Now()) + '.crash';

Log.SaveToFile(FileName);
Log.Free();
Expand All @@ -337,7 +337,7 @@ procedure TSimbaForm.HandleException(Sender: TObject; E: Exception);
'' + LineEnding +
'A crash log has been saved in the data directory.';

if MessageDlg(Format(Message, [E.Message, ExtractRelativePath(GetSimbaPath(), FileName)]), mtError, mbOKCancel, 0) = mrOk then
if MessageDlg(Format(Message, [E.Message, ExtractRelativePath(SimbaEnv.DataPath, FileName)]), mtError, mbOKCancel, 0) = mrOk then
begin
SimbaScriptTabsForm.CloseAllTabs();

Expand Down
2 changes: 1 addition & 1 deletion Source/forms/simba.scripttabsform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ procedure TSimbaScriptTabsForm.Open;
try
OpenDialog.InitialDir := ExtractFileDir(CurrentTab.ScriptFileName);
if (OpenDialog.InitialDir = '') then
OpenDialog.InitialDir := GetScriptPath();
OpenDialog.InitialDir := SimbaEnv.ScriptsPath;

if OpenDialog.Execute() then
for I := 0 to OpenDialog.Files.Count - 1 do
Expand Down
2 changes: 1 addition & 1 deletion Source/forms/simba.settingsform_backup.pas
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ constructor TSimbaBackupFrame.Create(AOwner: TComponent);
begin
inherited Create(AOwner);

LabelBackupDirectory.Caption := GetBackupsPath();
LabelBackupDirectory.Caption := SimbaEnv.BackupsPath;
end;

procedure TSimbaBackupFrame.Load;
Expand Down
6 changes: 3 additions & 3 deletions Source/forms/simba.settingsform_editor_colors.pas
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ procedure TEditorColorsFrame.Save;
var
FileName: String;
begin
FileName := GetDataPath() + 'colors_editor.ini';
FileName := SimbaEnv.DataPath + 'colors_editor.ini';

FEditor.Attributes.SaveToFile(FileName);

Expand All @@ -192,7 +192,7 @@ procedure TEditorColorsFrame.DoSaveButtonClick(Sender: TObject);
begin
with TSaveDialog.Create(Self) do
try
InitialDir := GetDataPath();
InitialDir := SimbaEnv.DataPath;
Title := 'Save Editor Colors';
Filter := 'Colors Files (*.ini)|*.ini';
FileName := 'colors';
Expand All @@ -216,7 +216,7 @@ procedure TEditorColorsFrame.LoadButtonClick(Sender: TObject);
begin
with TOpenDialog.Create(Self) do
try
InitialDir := GetDataPath();
InitialDir := SimbaEnv.DataPath;
Title := 'Load Editor Colors';
Filter := 'INI Files (*.ini)|*.ini';

Expand Down
4 changes: 2 additions & 2 deletions Source/forms/simba.shapeboxform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ procedure TSimbaShapeBoxForm.FormCreate(Sender: TObject);
procedure TSimbaShapeBoxForm.FormHide(Sender: TObject);
begin
ShapeBox.PrintShapes();
ShapeBox.SaveToFile(GetDataPath() + 'shapes');
ShapeBox.SaveToFile(SimbaEnv.DataPath + 'shapes');
if (not HasBackground) then
ShapeBox.Background.SetSize(0, 0);
end;
Expand All @@ -65,7 +65,7 @@ procedure TSimbaShapeBoxForm.FormShow(Sender: TObject);
ShapeBox.Background.SetSize(1000, 1000);
end;

ShapeBox.LoadFromFile(GetDataPath() + 'shapes');
ShapeBox.LoadFromFile(SimbaEnv.DataPath + 'shapes');
end;

procedure TSimbaShapeBoxForm.MenuItem3Click(Sender: TObject);
Expand Down
2 changes: 1 addition & 1 deletion Source/forms/simba.showdeclarationform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ procedure TShowDeclarationForm.Execute(Decls: TDeclarationArray);

Grid.Cells[1, Grid.FixedRows + I] := TDeclaration_Method(Decls[I]).HeaderString;
Grid.Cells[2, Grid.FixedRows + I] := TDeclaration_Method(Decls[I]).Line.ToString();
Grid.Cells[3, Grid.FixedRows + I] := ExtractRelativePath(GetSimbaPath(), TDeclaration_Method(Decls[I]).Lexer.FileName);
Grid.Cells[3, Grid.FixedRows + I] := ExtractRelativePath(SimbaEnv.SimbaPath, TDeclaration_Method(Decls[I]).Lexer.FileName);
end;

Grid.AutoSizeColumns();
Expand Down
10 changes: 5 additions & 5 deletions Source/package/simba.package.pas
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function LoadPackageURLs: TStringArray;
Thread.WaitFor();
Thread.Free();

with TIniFile.Create(GetPackagePath() + 'packages.ini') do
with TIniFile.Create(SimbaEnv.PackagesPath + 'packages.ini') do
try
ReadSections(Sections);

Expand Down Expand Up @@ -247,7 +247,7 @@ procedure TSimbaPackage.ClearConfig;
Keys := TStringList.Create();

try
with TIniFile.Create(GetPackagePath() + 'packages.ini') do
with TIniFile.Create(SimbaEnv.PackagesPath + 'packages.ini') do
try
ReadSection(FURL, Keys);
for Key in Keys do
Expand All @@ -266,7 +266,7 @@ procedure TSimbaPackage.ClearConfig;
procedure TSimbaPackage.WriteConfig(Key: String; Value: String);
begin
try
with TIniFile.Create(GetPackagePath() + 'packages.ini') do
with TIniFile.Create(SimbaEnv.PackagesPath + 'packages.ini') do
try
WriteInteger('Settings', 'Version', PACKAGE_SETTINGS_VERSION);
WriteString(FURL, Key, Value);
Expand All @@ -282,7 +282,7 @@ procedure TSimbaPackage.WriteConfig(Key: String; Value: String);
function TSimbaPackage.ReadConfig(Key: String): String;
begin
try
with TIniFile.Create(GetPackagePath() + 'packages.ini') do
with TIniFile.Create(SimbaEnv.PackagesPath + 'packages.ini') do
try
Result := ReadString(FURL, Key, '');
finally
Expand Down Expand Up @@ -360,7 +360,7 @@ function TSimbaPackage.UnInstall(RemoveFiles: Boolean): Boolean;

if Result then
begin
if RemoveFiles and PathIsInPath(InstalledPath, GetSimbaPath()) then
if RemoveFiles and PathIsInPath(InstalledPath, SimbaEnv.SimbaPath) then
DeleteDirectory(InstalledPath, False);

ClearConfig();
Expand Down
2 changes: 1 addition & 1 deletion Source/package/simba.package_endpoint_github.pas
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function TSimbaPackageEndpoint_Github.GetPageCache(Key: String; URL: String): St
begin
Result := '';

CacheFileName := GetPackagePath() + FOwner + '-' + FName + '.' + Key;
CacheFileName := SimbaEnv.PackagesPath + FOwner + '-' + FName + '.' + Key;
Cache := TStringList.Create();

try
Expand Down
8 changes: 4 additions & 4 deletions Source/package/simba.package_installer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ function TSimbaPackageInstaller.InternalInstall(URL: String; Path: String; Ignor
if Assigned(OnStartInstall) then
OnStartInstall(Self);

// Move old files to Data/OldPackages/
// Move old files to Data/Temp/
if DirectoryExists(Path) then
begin
FileName := GetOldPackagePath() + ExtractFileName(Path);
FileName := SimbaEnv.TempPath + ExtractFileName(Path);
if DirectoryExists(FileName) then
DeleteDirectory(FileName, False);

Expand Down Expand Up @@ -288,9 +288,9 @@ function TSimbaPackageInstaller.GetOptions(Version: TSimbaPackageRelease; out Op
end;

if (Options.Path = '') then
Options.Path := ConcatPaths([GetIncludePath(), FPackage.Info.Name])
Options.Path := ConcatPaths([SimbaEnv.IncludesPath, FPackage.Info.Name])
else
Options.Path := ConcatPaths([GetSimbaPath(), SetDirSeparators(Options.Path)]);
Options.Path := ConcatPaths([SimbaEnv.SimbaPath, SetDirSeparators(Options.Path)]);

Thread.Free();
Strings.Free();
Expand Down
6 changes: 3 additions & 3 deletions Source/package/simba.package_installform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ procedure TSimbaPackageInstallForm.DoVersionChange(Sender: TObject);
end else
Log('Release "%s" has no install options'.Format([Rel.Name]));

PathEdit.Text := GetIncludePath() + FPackage.Info.Name;
PathEdit.Text := SimbaEnv.IncludesPath + FPackage.Info.Name;
FlatCheckbox.Checked := False;
IgnoreListMemo.Clear();
end;
Expand Down Expand Up @@ -150,10 +150,10 @@ procedure TSimbaPackageInstallForm.DoInstallButtonClick(Sender: TObject);
Options.IgnoreList := IgnoreListMemo.Lines.ToStringArray();
Options.AutoUpdate := False;

if GetSelectedRelease(Rel) and (SimbaQuestionDlg('Install Package', 'Install "%s" to "%s" ?'.Format([FPackage.Info.FullName, ExtractRelativePath(GetSimbaPath(), Options.Path)])) = ESimbaDialogResult.YES) then
if GetSelectedRelease(Rel) and (SimbaQuestionDlg('Install Package', 'Install "%s" to "%s" ?'.Format([FPackage.Info.FullName, ExtractRelativePath(SimbaEnv.SimbaPath, Options.Path)])) = ESimbaDialogResult.YES) then
FInstaller.Install(Rel, Options)
else
if GetSelectedBranch(Branch) and (SimbaQuestionDlg('Install Package', 'Install "%s" to "%s" ?'.Format([FPackage.Info.FullName, ExtractRelativePath(GetSimbaPath(), Options.Path)])) = ESimbaDialogResult.YES) then
if GetSelectedBranch(Branch) and (SimbaQuestionDlg('Install Package', 'Install "%s" to "%s" ?'.Format([FPackage.Info.FullName, ExtractRelativePath(SimbaEnv.SimbaPath, Options.Path)])) = ESimbaDialogResult.YES) then
FInstaller.InstallBranch(Branch, Options.Path);
end;

Expand Down
12 changes: 6 additions & 6 deletions Source/script/imports/simba/simba.import_file.pas
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ procedure ImportFile(Compiler: TSimbaScript_Compiler);
addGlobalVar(PATH_SEP, 'PATH_SEP').isConstant := True;
addGlobalVar(LINE_SEP, 'LINE_SEP').isConstant := True;

addGlobalVar(GetIncludePath(), 'IncludePath').isConstant := True;
addGlobalVar(GetPluginPath(), 'PluginPath').isConstant := True;
addGlobalVar(GetSimbaPath(), 'SimbaPath').isConstant := True;
addGlobalVar(GetScriptPath(), 'ScriptPath').isConstant := True;
addGlobalVar(GetDataPath(), 'DataPath').isConstant := True;
addGlobalVar(GetScreenshotPath(), 'ScreenshotPath').isConstant := True;
addGlobalVar(SimbaEnv.IncludesPath, 'INCLUDES_PATH').isConstant := True;
addGlobalVar(SimbaEnv.PluginsPath, 'PLUGINS_PATH').isConstant := True;
addGlobalVar(SimbaEnv.SimbaPath, 'SIMBA_PATH').isConstant := True;
addGlobalVar(SimbaEnv.ScriptsPath, 'SCRIPTS_PATH').isConstant := True;
addGlobalVar(SimbaEnv.DataPath, 'SIMBA_DATA_PATH').isConstant := True;
addGlobalVar(SimbaEnv.ScreenshotsPath, 'SCREENSHOTS_PATH').isConstant := True;

addGlobalFunc('procedure WriteINI(Section, KeyName, NewString, FileName: String)', @_LapeWriteINI);
addGlobalFunc('function ReadINI(Section, KeyName, FileName: String): String', @_LapeReadINI);
Expand Down
3 changes: 1 addition & 2 deletions Source/script/imports/simba/simba.import_script.pas
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ procedure ImportScript(Compiler: TSimbaScript_Compiler);
begin
ImportingSection := 'Script';

addGlobalVar('', 'ScriptFile').isConstant := True;
addGlobalVar('', 'ScriptName').isConstant := True;
addGlobalVar('', 'SCRIPT_FILE').isConstant := True;

addGlobalFunc('function RunScript(Script: String; Parameters: TStringArray; out Output: String): TProcessExitStatus; overload', @_LapeRunScript);
addGlobalFunc('function RunScript(Script: String; Parameters: TStringArray): TProcessID; overload', @_LapeRunScriptEx);
Expand Down
14 changes: 6 additions & 8 deletions Source/script/simba.script.pas
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ procedure TSimbaScript.DoCompilerHint(Sender: TLapeCompilerBase; Hint: lpString)
function TSimbaScript.DoCompilerFindFile(Sender: TLapeCompiler; var FileName: lpString): TLapeTokenizerBase;
begin
Result := nil;
if (not FindFile(FileName, '', [IncludeTrailingPathDelimiter(ExtractFileDir(Sender.Tokenizer.FileName)), GetIncludePath(), GetSimbaPath()])) then
if (not FindInclude(FileName, [ExtractFileDir(Sender.Tokenizer.FileName)])) then
FileName := '';
end;

Expand Down Expand Up @@ -106,7 +106,7 @@ function TSimbaScript.DoCompilerHandleDirective(Sender: TLapeCompiler; Directive
if InIgnore or InPeek then
Exit;

if not FindPlugin(Argument, [FCompiler.CurrentDir(), GetPluginPath(), GetSimbaPath()]) then
if not FindPlugin(Argument, [FCompiler.CurrentDir()]) then
raise Exception.Create('Plugin "' + Argument + '" not found');

CopyPlugin(Argument);
Expand All @@ -124,7 +124,7 @@ function TSimbaScript.DoCompilerHandleDirective(Sender: TLapeCompiler; Directive
if InIgnore then
FCompiler.pushConditional(False, Sender.DocPos)
else
FCompiler.pushConditional(FindPlugin(Argument, [FCompiler.CurrentDir(), GetPluginPath(), GetSimbaPath()]), Sender.DocPos);
FCompiler.pushConditional(FindPlugin(Argument, [FCompiler.CurrentDir()]), Sender.DocPos);
end;

function DoHasFile: Boolean;
Expand All @@ -134,7 +134,7 @@ function TSimbaScript.DoCompilerHandleDirective(Sender: TLapeCompiler; Directive
if InIgnore then
FCompiler.pushConditional(False, Sender.DocPos)
else
FCompiler.pushConditional(FindFile(Argument, '', [FCompiler.CurrentDir(), GetIncludePath(), GetSimbaPath()]), Sender.DocPos);
FCompiler.pushConditional(FindInclude(Argument, [FCompiler.CurrentDir()]), Sender.DocPos);
end;

function DoError: Boolean;
Expand Down Expand Up @@ -190,7 +190,7 @@ function TSimbaScript.DoFindMacro(Sender: TLapeCompiler; Name: lpString; var Val
Result := Lib <> '';
if Result then
begin
if not FindPlugin(Lib, [FCompiler.CurrentDir(), GetPluginPath(), GetSimbaPath()]) then
if not FindPlugin(Lib, [FCompiler.CurrentDir()]) then
Lib := '';

Value := '"' + Lib + '"';
Expand Down Expand Up @@ -252,9 +252,7 @@ function TSimbaScript.Run: Boolean;
FTargetWindow := GetDesktopWindow();

PSimbaTarget(FCompiler['Target'].Ptr)^.SetWindow(FTargetWindow);

PString(FCompiler['ScriptFile'].Ptr)^ := FScriptFileName;
PString(FCompiler['ScriptName'].Ptr)^ := ExtractFileName(FScriptFileName);
PString(FCompiler['SCRIPT_FILE'].Ptr)^ := FScriptFileName;

FRunningTime := HighResolutionTime();
try
Expand Down
2 changes: 1 addition & 1 deletion Source/script/simba.script_pluginloader.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ implementation

function LoadPlugin(FileName: String; ExtraSearchDirs: TStringArray): TLibHandle;
begin
if (not FindPlugin(FileName, [GetPluginPath(), GetSimbaPath()] + ExtraSearchDirs)) then
if (not FindPlugin(FileName, ExtraSearchDirs)) then
raise Exception.CreateFmt('Unable to find plugin "%s"', [FileName]);

Result := LoadLibrary(FileName);
Expand Down
2 changes: 1 addition & 1 deletion Source/script/simba.scriptthread.pas
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ constructor TSimbaScriptRunner.Create(FileName: String; SimbaCommunication, Targ
FScript.TargetWindow := TargetWindow;

// Simba created a temp file. Most likely default script.
if FileIsInDirectory(FileName, GetDataPath()) then
if FileIsInDirectory(FileName, SimbaEnv.DataPath) then
begin
FScript.ScriptFileName := ChangeFileExt(ExtractFileName(FileName), '');

Expand Down

0 comments on commit a28c486

Please sign in to comment.