View Issue Details

IDProjectCategoryView StatusLast Update
0036314LazarusIDEpublic2019-12-11 14:00
ReporterHans LuijtenAssigned ToJuha Manninen 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformCocoaOSmacOSOS Version10.14.x
Product Version2.0.7 (SVN)Product Buildr62054M 
Target VersionFixed in Version 
Summary0036314: External Tools fail to execute when the external tool is an .app application (low priority)
DescriptionWhen adding an external tool, the tool does not get executed when the said tool is an .app.

Most likely what happens is that "someapplication.app" is being called, instead of "open someapplication.app". So the call fails.
I tried digging into the IDE code, but this went a little over my head.

To illustrate this in Terminal:

$ /Applications/BBEdit.app
-bash: /Applications/BBEdit.app: is a directory (fail)

$ open /Applications/BBEdit.app
(success - the .app starts)
Steps To ReproduceOn macOS, go to the menu "Tools" - "Configure external tools" - "Add".
Enter some title, and select an .app application (for example BBEdit, Calculator, or any app for that matter).
Click "OK" and click "OK" again to get out of the external tool editor.

Now go back to the "Tools" menu and select the newly added tool.
Nothing happens.

When running Lazarus from Terminal, clicking the newly added tool will show:
Error: (lazarus) [TExternalTools.RunToolAndDetach] BBEdit failed: executable is a directory: "/Applications/BBEdit.app"

(I have tested this with several .app's - they all come back with the same result)
Additional InformationLazarus 2.1.0 r62054M FPC 3.0.4 x86_64-darwin-cocoa (beta)
TagsNo tags attached.
Fixed in Revisionr62254
LazTarget-
WidgetsetCocoa
Attached Files
  • exttools.diff (1,640 bytes)
    Index: ide/exttools.pas
    ===================================================================
    --- ide/exttools.pas	(revision 62218)
    +++ ide/exttools.pas	(working copy)
    @@ -1041,18 +1041,32 @@
           debugln(['Error: (lazarus) [TExternalTools.RunToolAndDetach] ',ToolOptions.Title,'  failed: missing executable: "',s,'"']);
           exit;
         end;
    -    if DirectoryExistsUTF8(s) then begin
    +    if DirectoryExistsUTF8(s) {$IFDEF DARWIN}and (ExtractFileExt(s)<>'.app'){$ENDIF} then begin
           debugln(['Error: (lazarus) [TExternalTools.RunToolAndDetach] ',ToolOptions.Title,'  failed: executable is a directory: "',s,'"']);
           exit;
         end;
    -    if not FileIsExecutable(s) then begin
    +    if {$IFDEF DARWIN}(ExtractFileExt(s)<>'.app') and{$ENDIF} not FileIsExecutable(s) then begin
           debugln(['Error: (lazarus) [TExternalTools.RunToolAndDetach] ',ToolOptions.Title,'  failed: executable lacks permission to run: "',s,'"']);
           exit;
         end;
    +
    +    {$IFDEF DARWIN}
    +    if DirectoryExistsUTF8(s) then
    +      begin
    +        Proc.Executable:='/usr/bin/open';
    +        s:=s+LineEnding+ToolOptions.CmdLineParams;
    +      end
    +    else
    +      begin
    +        Proc.Executable:=s;
    +        s:=ToolOptions.CmdLineParams;
    +      end;
    +    {$ELSE}
         Proc.Executable:=s;
    +    s:=ToolOptions.CmdLineParams;
    +    {$ENDIF}
     
         // params
    -    s:=ToolOptions.CmdLineParams;
         if ToolOptions.ResolveMacros then begin
           if not GlobalMacroList.SubstituteStr(s) then begin
             debugln(['Error: (lazarus) [TExternalTools.RunToolAndDetach] ',ToolOptions.Title,' failed: macros in cmd line params "',ToolOptions.CmdLineParams,'"']);
    
    exttools.diff (1,640 bytes)

Relationships

related to 0036418 closedJuha Manninen External Tools again fail to execute when the external tool is an .app application (+patch attached) 

Activities

Mattias Gaertner

2019-11-14 12:39

manager   ~0119299

You can start an app with /Applications/Lazarus.app/Contents/MacOS/lazarus

Hans Luijten

2019-11-14 13:19

reporter  

exttools.diff (1,640 bytes)
Index: ide/exttools.pas
===================================================================
--- ide/exttools.pas	(revision 62218)
+++ ide/exttools.pas	(working copy)
@@ -1041,18 +1041,32 @@
       debugln(['Error: (lazarus) [TExternalTools.RunToolAndDetach] ',ToolOptions.Title,'  failed: missing executable: "',s,'"']);
       exit;
     end;
-    if DirectoryExistsUTF8(s) then begin
+    if DirectoryExistsUTF8(s) {$IFDEF DARWIN}and (ExtractFileExt(s)<>'.app'){$ENDIF} then begin
       debugln(['Error: (lazarus) [TExternalTools.RunToolAndDetach] ',ToolOptions.Title,'  failed: executable is a directory: "',s,'"']);
       exit;
     end;
-    if not FileIsExecutable(s) then begin
+    if {$IFDEF DARWIN}(ExtractFileExt(s)<>'.app') and{$ENDIF} not FileIsExecutable(s) then begin
       debugln(['Error: (lazarus) [TExternalTools.RunToolAndDetach] ',ToolOptions.Title,'  failed: executable lacks permission to run: "',s,'"']);
       exit;
     end;
+
+    {$IFDEF DARWIN}
+    if DirectoryExistsUTF8(s) then
+      begin
+        Proc.Executable:='/usr/bin/open';
+        s:=s+LineEnding+ToolOptions.CmdLineParams;
+      end
+    else
+      begin
+        Proc.Executable:=s;
+        s:=ToolOptions.CmdLineParams;
+      end;
+    {$ELSE}
     Proc.Executable:=s;
+    s:=ToolOptions.CmdLineParams;
+    {$ENDIF}
 
     // params
-    s:=ToolOptions.CmdLineParams;
     if ToolOptions.ResolveMacros then begin
       if not GlobalMacroList.SubstituteStr(s) then begin
         debugln(['Error: (lazarus) [TExternalTools.RunToolAndDetach] ',ToolOptions.Title,' failed: macros in cmd line params "',ToolOptions.CmdLineParams,'"']);
exttools.diff (1,640 bytes)

Hans Luijten

2019-11-14 13:19

reporter   ~0119300

You're correct about that, however you'd have to type/paste the full path manually as the "External tools" editor will not allow you to browse inside an .app bundle. Right click "Show Package Content" is not available either. 😞

After some tinkering (found where to look based on the error message), I did manage to create a fix (only tested under macOS).
I have no idea on how to better submit a diff/patch, so I'm attaching it here.
After all, the Wiki page "Creating A Patch" suggest: "The recommended way to submit a patch is through the bug tracker".

The patch changes a very few lines in ide/exttools.pas, which I've added using compiler directives so it only looks for ".app" under macOS (Darwin).
If it is an .app, the executable will be '/usr/bin/open' and the original executable (the .app) will be added in front of the parameters.
Both without affecting the details in the "External tools" editor.

Hans Luijten

2019-11-16 11:25

reporter   ~0119337

After some more testing of my modification, some useful tips for macOS users, which work great;

When adding "-n" tot the "parameters" list, another instance of the .app will be opened, even if the app was already open.

When adding "--args" (followed by arguments), the arguments will be passed the the .app (in Lazarus Pascal written apps, received through "ParamStr(x)").

For example, these parameters will start a new instance of the .app and passes the project LPR file to the app:

-n
--args
$ProjFile()

Hans Luijten

2019-11-16 11:27

reporter   ~0119338

Just being curious: should I submit the patch in a different way?
(eg. new ticket with category "Patch"?)

Bart Broersma

2019-11-16 15:08

developer   ~0119347

> Just being curious: should I submit the patch in a different way?
No, it's OK this way.
Some devel with MacOSX knowledge will have to look at it.

Hans Luijten

2019-11-16 15:11

reporter   ~0119348

Thanks Bart! 😊

Juha Manninen

2019-11-17 10:50

developer   ~0119355

Last edited: 2019-11-17 10:52

View 2 revisions

I applied the patch after some modification although I don't have a Mac.
I count on your testing on Mac, I tested on Linux. IFDEFed code is OK in this special case, it already has Windows specific code.
I was able to simplify and eliminate an {$ELSE} block completely from your code.

About submitting a patch: You are a long time contributor so this should not be a new task for you. I remember you implemented a nice MacOS specific NewLine feature for OI ListBox property editor (or something) a couple of years ago. Good!

Hans Luijten

2019-11-17 11:20

reporter   ~0119358

Thanks Juha, Mattias and Bart!

Just tested the latest SVN, and it works! 😊

As for submitting a patch;
I may be a long time contributor, but this has been only my second patch.
I remember last time I had to learn how to make a diff, so out of respect and not wanting to making anyone's life miserable, I just ask (the Wiki isn't always up to date either).

You guys do a LOT of work which is very much appreciated.
Lesson learned: Report bug here, post patch here if I have one.

Good memory on the NewLine patch 😁
Thanks again!

Issue History

Date Modified Username Field Change
2019-11-14 12:34 Hans Luijten New Issue
2019-11-14 12:39 Mattias Gaertner Note Added: 0119299
2019-11-14 13:19 Hans Luijten File Added: exttools.diff
2019-11-14 13:19 Hans Luijten Note Added: 0119300
2019-11-16 11:25 Hans Luijten Note Added: 0119337
2019-11-16 11:27 Hans Luijten Note Added: 0119338
2019-11-16 15:08 Bart Broersma Note Added: 0119347
2019-11-16 15:11 Hans Luijten Note Added: 0119348
2019-11-17 10:20 Juha Manninen Assigned To => Juha Manninen
2019-11-17 10:20 Juha Manninen Status new => assigned
2019-11-17 10:50 Juha Manninen Status assigned => resolved
2019-11-17 10:50 Juha Manninen Resolution open => fixed
2019-11-17 10:50 Juha Manninen Fixed in Revision => r62254
2019-11-17 10:50 Juha Manninen LazTarget => -
2019-11-17 10:50 Juha Manninen Widgetset Cocoa => Cocoa
2019-11-17 10:50 Juha Manninen Note Added: 0119355
2019-11-17 10:52 Juha Manninen Note Edited: 0119355 View Revisions
2019-11-17 11:20 Hans Luijten Status resolved => closed
2019-11-17 11:20 Hans Luijten Note Added: 0119358
2019-12-11 14:00 Juha Manninen Relationship added related to 0036418