canonical / matter-pi-gpio-commander

Matter Raspberry Pi GPIO Commander - Turn your Pi into a Matter lighting device!
Apache License 2.0
90 stars 3 forks source link

build: Error loading zap env file on remote builds #31

Closed farshidtz closed 8 months ago

farshidtz commented 8 months ago

On remote build (using snapcraft remote-build, via Launchpad), the env file created in zap part doesn't get loaded in the lighting part. See the relevant logs below:

Remote build:

:: + echo 'export ZAP_INSTALL_PATH=/build/snapcraft-matter-pi-gpio-commander-dcf72f424a2401ddf9b69c72baccc6c2/parts/zap/build'
...
:: + test -f /root/parts/zap/build/env
:: + cd ../../connectedhomeip/src

On Pi:

+ echo 'export ZAP_INSTALL_PATH=/root/parts/zap/build'                                                                                              
...                                                                                                        
:: + test -f /root/parts/zap/build/env                                                                                                                 
:: + source /root/parts/zap/build/env                                                                                                                  
:: ++ export ZAP_INSTALL_PATH=/root/parts/zap/build                                                                                                    
:: ++ ZAP_INSTALL_PATH=/root/parts/zap/build                                                                                                           
:: + cd ../../connectedhomeip/src

The remote builds use the destructive mode, i.e. building directly on the host. The difference in paths appears related to that.

Originally posted by @farshidtz in https://github.com/canonical/matter-pi-gpio-commander/issues/29#issuecomment-1783189336

farshidtz commented 8 months ago

Solution 1: https://github.com/canonical/matter-pi-gpio-commander/blob/e7f8f8ab29afc41e8735ca88f660a230faed3dae/snap/snapcraft.yaml#L94

Change to relative path: ../../zap/build/env

Solution 2: Write the env file at a common location, such as $CRAFT_STAGE/zap_env. May result in bad caching because the file won't be removed when cleaning the part.