[possible bug] macos app bundling

This subforum is specifically to discuss packaging issues on different platforms (windows, mac, linux), and using different packaging systems (conda, etc...)
Post Reply
User avatar
ipatch
Posts: 112
Joined: Wed Apr 08, 2020 3:40 pm
Location: dfw
Contact:

[possible bug] macos app bundling

Post by ipatch »

i have been messing around with building freecad (git master) on macos for sometime now. i can successfully build the latest HEAD without any issues, but when i try to generate a macos app bunlde ie. a `FreeCAD.app` for my macos platform (macos mojave/10.14) i run into issues when the process (make install) begins to run the python2 script that assembles the relocatable bundle.

the first issue i ran into was the processing of the `homebrew-[PKG_NAME].pth` files within the the python `site-packages` directory.

those `.pth` files can contain standard UNIX filesystem paths, and also contain lines requiring "interpretation" by a python interpreter (i believe) for example,

i have the `sphinx-doc` and `sphinx` packages installed on my system using `brew install sphinx sphinx-doc` after installing that homebrew package it will place a `sphinxcontrib_htmlhelp-1.0.3-py3.9-nspkg.pth` within the below dir

Code: Select all

$(brew --prefix)/opt/sphinx-doc/libexec/lib/python3.9/site-packages/
the output of that file is,

Code: Select all

import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('sphinxcontrib',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('sphinxcontrib', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('sphinxcontrib', [os.path.dirname(p)])));m = m or sys.modules.setdefault('sphinxcontrib', types.ModuleType('sphinxcontrib'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
as can be seen, there is a lot more going on in that `.pth` file other than a standard `/some/path/to/a/python/library/on/filesystem`

so after running,

Code: Select all

cmake \
[INSERT_CMAKE_ARGS] \
[ARGS_OMITTED_FOR_PREVITY] \
-DFREECAD_CREATE_MAC_APP=ON \
-DCMAKE_INSTALL_PREFIX=/opt/beta/freecad.apl.bundle ../freecad-src
then running

Code: Select all

make

Code: Select all

make install
the following error will be reported to STDOUT

Code: Select all


-- Installing: /opt/beta/freecad.apl.bundle/FreeCAD.app/Contents/libexec/matplotlib/lib/python3.9/site-packages/dateutil/tz/win.py
CMake Error at src/MacAppBundle/cmake_install.cmake:74 (file):
  file INSTALL cannot find
  "/opt/code/github/public/forks/freecad-git/freecad-src/src/MacAppBundle/import
  site": No such file or directory.
Call Stack (most recent call first):
  src/cmake_install.cmake:51 (include)
  cmake_install.cmake:68 (include)


make: *** [install] Error 1
i believe above mentioned error is related to this block of code

my current work around for above such issues when running `make install` and to use a standard UNIX style filesystem path, ie.

```
/usr/local/library/libexec/matplotlib/lib/python3.9/site-packages
```

and the `make install` process moves along further until another error is presented.

keep in mind this error only seems to happen when enabling the below cmake flag

Code: Select all

-DFREECAD_CREATE_MAC_APP=ON
i'm still able to run and use freecad from a CLI and launch it using an automater action to simulate an app bundle experience on macos, but thought i'd share this issue here.
chrisb
Veteran
Posts: 53939
Joined: Tue Mar 17, 2015 9:14 am

Re: [possible bug] macos app bundling

Post by chrisb »

Looo is the Mac package expert, perhaps he can help.
looo wrote: pinged by pinger macro
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: [possible bug] macos app bundling

Post by looo »

chrisb wrote: Thu May 27, 2021 5:41 am Looo is the Mac package expert, perhaps he can help.
looo wrote: pinged by pinger macro
sorry, I use only conda for packaging. I guess this is more related to brew. So maybe pinging:
vejmarie wrote: Fri Feb 03, 2017 1:29 pm
User avatar
ipatch
Posts: 112
Joined: Wed Apr 08, 2020 3:40 pm
Location: dfw
Contact:

Re: [possible bug] macos app bundling

Post by ipatch »

a little follow up about said issue.

the above mentioned cmake file for mac app bundling

```
echo "`freecad-src` dir is a git clone of the freecad source hosted on github"
freecad-git/freecad-src/src/MacAppBundle/CMakeLists.txt
```

will generate the below file with the following lines

```
freecad-git/build.master/src/MacAppBundle/cmake_install.cmake
```

that file, will contain the following code,

Code: Select all

if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
  list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES
   "/opt/beta/freecad.apl.bundle/FreeCAD.app/Contents/libexec/pybind11/lib/python3.9/site-packages")
  if(CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
    message(WARNING "ABSOLUTE path INSTALL DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
  endif()
  if(CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
    message(FATAL_ERROR "ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
  endif()
file(INSTALL DESTINATION "/opt/beta/freecad.apl.bundle/FreeCAD.app/Contents/libexec/pybind11/lib/python3.9" TYPE DIRECTORY FILES "/usr/local/Cellar/pybind11/2.6.2/libexec/lib/python3.9/site-packages")
endif()

which will properly find the python library of pybind11 and add to the `FreeCAD.app` bundle. and that is because i have modified the,

```
/usr/local/Cellar/pybind11/2.6.2/lib/python3.9/site-packages/homebrew-pybind11.pth
```

with the following line,

```
/usr/local/Cellar/pybind11/2.6.2/libexec/lib/python3.9/site-packages
```

---

NOW, the original file `homebrew-pybind11.pth` from the homebrew installation contains

```
import site; site.addsitedir('/usr/local/Cellar/pybind11/2.6.2/libexec/lib/python3.9/site-packages')
```

so with that file changed with above such line in it, it will produce a `cmake_install.cmake` with the below code block in it

Code: Select all

if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
  list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES
   "/opt/beta/freecad.apl.bundle/FreeCAD.app/Contents/libexec/import site site.addsitedir('/usr/local/Cellar/pybind11/2.6.2/libexec/lib/python3.9/site-packages')/lib/python3.9')/import site;/opt/beta/freecad.apl.bundle/FreeCAD.app/Contents/libexec/import site site.addsitedir('/usr/local/Cellar/pybind11/2.6.2/libexec/lib/python3.9/site-packages')/lib/python3.9')/site-packages')")
  if(CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
    message(WARNING "ABSOLUTE path INSTALL DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
  endif()
  if(CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
    message(FATAL_ERROR "ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
  endif()
file(INSTALL DESTINATION "/opt/beta/freecad.apl.bundle/FreeCAD.app/Contents/libexec/import site site.addsitedir('/usr/local/Cellar/pybind11/2.6.2/libexec/lib/python3.9/site-packages')/lib/python3.9')" TYPE DIRECTORY FILES
    "/opt/code/github/public/forks/freecad-git/freecad-src/src/MacAppBundle/import site"
    "/opt/code/github/public/forks/freecad-git/freecad-src/src/MacAppBundle/ site.addsitedir('/usr/local/Cellar/pybind11/2.6.2/libexec/lib/python3.9/site-packages')"
    )
endif()
when i run the `make install` task "cmake" or whatever is running underneath (using that term loosely here) errors out due to the fact that is unable to process the paths contained within the `cmake_install.cmake` generated file from the,

```
freecad-git/freecad-src/src/MacAppBundle/CMakeLists.txt
```

i hope that is perfectly clear here. i wish i knew more about cmake, and how to inspect and print variables in realtime ala a cmake style debugger as opposed to littering the cmake file print statements, but nonetheless i'll leave this here (for future me) and for anybody who interested mac app bundling.
Post Reply