Repository: pyinstaller/pyinstaller

Issue:
Pyinstaller --distpath broken for Mac.Not making the .app file at -distpath.
<!--
Welcome to the PyInstaller issue tracker! Before creating an issue, please heed the following:

1. This tracker should only be used to report bugs and request features / enhancements to PyInstaller
    - For questions and general support, use the mailing list, see
	  <http://www.pyinstaller.org/support.html#mailing-list>
2. Use the search function before creating a new issue. Duplicates will be closed and directed to
   the original discussion.
3. When making a bug report, make sure you provide all required information. The easier it is for
   maintainers to reproduce, the faster it'll be fixed.
-->




While working with Pyinstaller 3.5 and 3.6 (have not worked on older versions),found out that .app is being made in the same place where .spec file is placed.Did some digging and think that the file
osx.py at line number 95 is the problem which is joining the spec file path with dest path .


## Context information (for bug reports)

* Output of `pyinstaller --version`: ```VERSION 3.5 and 3.6```
* Version of Python: 3.5
* Platform: OS X
* Did you also try this on another platform? Does it work there?
N/A




### A minimal example program which shows the error
To simulate the same issue :

- Decompress the files below
[smallexample.zip](https://github.com/pyinstaller/pyinstaller/files/4666539/smallexample.zip)
- pip install -r requirement.txt
- to make spec file :  pyinstaller --noconsole --windowed small.py
-Now run the spec file from outside the smallexmaple folder.
command to run :  `pyinstaller smallexample/small.spec --distpath small_dist/small_dist2/`
The .app file will be made inside the smallexample folder even though the --distpath is provided.

As mentioned above the spec path is being joined with the dest path ,which should not be the case.


Discussion:
One way to get around this problem is using the absolute path instead of relative path as the join operation wont join the spec path if its absolute .
i.e using the `--distpath /User/<whatever>/samll_dist/small_dist2` works as expected.
Both app and collection are made at --distpath path.
@SHAANBHAYA I'll try and replicate this. In theory, a bug like this would show up on other platforms, but it might not.
@Legorooj Did you get the time to verify ?
Yes - I've been unable to replicate on Windows 10. However, windows doens't use the `BUNDLE` class in the spec file so I had to remove that. I'm pretty sure that that is the issue. Could you try figuring out what the issue is exactly? I can help then, but it'd take ages to track this down on non-macOS platforms.
Closing due to lack of response from the original author. Will re-open if you
(or anyone else who has this issue) gets back to us by commenting below.

I am really sorry for the late response .This is not a bug that can not be reproduced on windows as the problem lies in osx.py file ,where we are joining the  spec file path with dest path,which leads to the behavior mentioned above. 
We use pyinstaller for making the executables for both windows and osx and with the same spec files and this happens only in osx.
 Here is the code that i think is causing this  :

`

        for inm, name, typ in self.toc:
            if typ == "EXECUTABLE":
                self.exename = name
                if self.name is None:
                    self.appname = "Mac%s" % (os.path.splitext(inm)[0],)
                    self.name = os.path.join(CONF['specpath'], self.appname + ".app") 
                else:
                    self.name = os.path.join(CONF['specpath'], self.name)<-----------------------Problem lies here. 
                break
`
As you can see its joining the specpath with the appname and not the dest path.

@SHAANBHAYA yes it is. Good find. Could @cjakuc take a look at this?
@BoboTiG could you take a look?

@Legorooj yes I could 👍 
OK, issue reproduced. Working on a patch.

Resolving patch:
diff --git a/PyInstaller/building/osx.py b/PyInstaller/building/osx.py
--- a/PyInstaller/building/osx.py
+++ b/PyInstaller/building/osx.py
@@ -89,11 +89,6 @@ def __init__(self, *args, **kws):
         for inm, name, typ in self.toc:
             if typ == "EXECUTABLE":
                 self.exename = name
-                if self.name is None:
-                    self.appname = "Mac%s" % (os.path.splitext(inm)[0],)
-                    self.name = os.path.join(CONF['specpath'], self.appname + ".app")
-                else:
-                    self.name = os.path.join(CONF['specpath'], self.name)
                 break
         self.__postinit__()
 


Test patch: