jwinarske / meta-flutter

Yocto meta layer for recipes related to using Google Flutter Engine
MIT License
45 stars 22 forks source link

support for gatesgarth #27

Closed xobs closed 3 years ago

xobs commented 3 years ago

The flutter-sdk_git.bb recipe leaks out of the sysroot and attempts to read files in the user's home directory.

$ rm -rf ~/.pub-cache
$ touch ~/.pub-cache
$ Loading cache: 100% |##############################################################################################| Time: 0:00:00
Loaded 4859 entries from dependency cache.
Parsing recipes: 100% |############################################################################################| Time: 0:00:03
Parsing of 3296 .bb files complete (3286 cached, 10 parsed). 4871 targets, 499 skipped, 1 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.48.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "ubuntu-20.04"
TARGET_SYS           = "aarch64-poky-linux"
MACHINE              = "imx8qxpmek"
DISTRO               = "fsl-imx-wayland"
DISTRO_VERSION       = "5.10-gatesgarth"
TUNE_FEATURES        = "aarch64 armv8a crc cortexa35 crypto"
TARGET_FPU           = ""
meta
meta-poky            = "HEAD:943ef2fad8428f002850e3655a3312e13d0dcb2c"
meta-oe
meta-multimedia
meta-python          = "HEAD:ac4ccd2fbbb599d75ca4051911fcbaca39dbe6d7"
meta-freescale       = "HEAD:41d4f625c6db7a778f0f9a735c2cb48e023bc49b"
meta-freescale-3rdparty = "HEAD:b85d08a55cb833bfc4e8b5034ff804286c67620e"
meta-freescale-distro = "HEAD:11be3f01962df8436c5c7b0d61cd3dbd1b872905"
meta-bsp
meta-sdk
meta-ml              = "HEAD:478d788fc1ecb4783a2702752a61f1035fe9ab9f"
meta-nxp-demo-experience = "HEAD:c7263d9f3cc7bbf44e7164ffeda494cf283d3dec"
meta-browser         = "HEAD:ee3be3b5986a4aa0e73df2204a625ae1fe5df37e"
meta-rust            = "HEAD:53bfa324891966a2daf5d36dc13d4a43725aebed"
meta-clang           = "HEAD:61faae011fb95712064f2c58abe6293f0daeeab5"
meta-gnome
meta-networking
meta-filesystems     = "HEAD:ac4ccd2fbbb599d75ca4051911fcbaca39dbe6d7"
meta-qt5             = "HEAD:8d5672cc6ca327576a814d35dfb5d59ab24043cb"
meta-python2         = "HEAD:c43c29e57f16af4e77441b201855321fbd546661"
meta-flutter         = "dunfell:9d50ce85de4d249d3bdf194753d38276c567b949"

Initialising tasks: 100% |#########################################################################################| Time: 0:00:02
Sstate summary: Wanted 421 Found 397 Missed 24 Current 2850 (94% match, 99% complete)
NOTE: Executing Tasks
ERROR: flutter-gallery-git-r0 do_compile: Execution of '/opt/Ion/yocto/imx-yocto-bsp/mek-build/tmp/work/cortexa35-poky-linux/flutter-gallery/git-r0/temp/run.do_compile.31770' failed with exit code 66:
Running "flutter pub get" in flutter_tools...
Creation failed, path = '/home/user/.pub-cache' (OS Error: Not a directory, errno = 20)
pub get failed (66; Creation failed, path = '/home/user/.pub-cache' (OS Error: Not a directory, errno = 20))
WARNING: exit code 66 from a shell command.
...
xobs commented 3 years ago

Part of this could be due to me using this dunfell release on gatesgarth, but I don't believe that's the case.

jwinarske commented 3 years ago

What happens if you remove 'touch ~/.pub-cache', and just have 'rm -rf ~/.pub-cache' prior to build?

xobs commented 3 years ago

If I remove ~/.pub-cache the build continues but fails at the final packaging QA step because there are undeclared files -- namely /usr/share/flutter/sdl/.git/* and /usr/share/flutter/sdk/.github/*, which is a separate issue.

jwinarske commented 3 years ago

Looks like PUB_CACHE defaults to '~/.pub-cache' and can be overridden. Maybe point it to '${S}/.pub-cache' and see what happens

https://github.com/flutter/flutter/issues/37481

jwinarske commented 3 years ago

This works fine for me (git pull meta-flutter)

repo init -u https://source.codeaurora.org/external/imx/imx-manifest -b imx-linux-gatesgarth -m imx-5.10.9-1.0.0.xml
repo sync -j48
DISTRO=fslc-wayland MACHINE=imx8qxpmek source setup-environment build
pushd ../sources
git clone -b dunfell https://github.com/jwinarske/meta-flutter.git
popd
bitbake-layers add-layer ../sources/meta-clang ../sources/meta-flutter
echo -e 'TARGET_GCC_VERSION = "10.2.0"' >> conf/local.conf
echo -e 'FLUTTER_CHANNEL = "dev"' >> conf/local.conf
echo -e 'IMAGE_INSTALL_append = " flutter-wayland"' >> conf/local.conf
echo -e 'IMAGE_INSTALL_append = " flutter-gallery"' >> conf/local.conf
bitbake flutter-sdk-native

Are you doing "bitbake flutter-sdk"?

I have no use case for supporting flutter application development on target, host side development with hot reload makes more sense. I will be updating flutter-sdk and depot-tools to be native only to avoid this confusion.

xobs commented 3 years ago

Thanks, I can confirm that things are working on my end as well. Furthermore, flutter-engine would not build until I removed this from my ~/.gitconfig (which lets me use ssh authentication with https URLs for github):

[url "git@github.com:"]
       insteadOf = https://github.com/

I have not yet gotten flutter_wayland to work on the device itself. glmark-wayland works, but flutter_wayland crashes with a segfault and no error messages. There are no symbols, so gdb is not useful.

Is there any way I can determine if this is a bug with Gatesgarth or the imx-image-multimedia image I'm building? For example, getting debug messages out?

jwinarske commented 3 years ago

Yes removing your .gitconfig makes sense, or at least associating it with a specific set of repos opposed to all.

You might want to build a debug version of flutter_wayland, as the default is release. Also to look at the wayland dialog execute on target "export WAYLAND_DEBUG=1" prior to execution.

jwinarske commented 3 years ago

Change flutter-wayland recipe to look like this:

EXTRA_OECMAKE = " \
    -DCMAKE_BUILD_TYPE=Debug \
    -DCMAKE_VERBOSE_MAKEFILE=TRUE \
    -DFLUTTER_ENGINE_LIBRARY=${STAGING_LIBDIR}/libflutter_engine.so \
    "

That should give you symbols. Please share the stack trace.

jwinarske commented 3 years ago

This may help: https://developer.ridgerun.com/wiki/index.php?title=Preparing_Yocto_Development_Environment_for_Debugging

The other option is to fork flutter_wayland and instrument it with logs statements. This might be faster depending on your current setup.

There has been a recent interface change in flutter_embedder.h that may have impacted things. I'll see if I can repo on another target on my end. I think in general it needs more log statements, at least with a command line option.

jwinarske commented 3 years ago

Actually what's the output of env on your target's console window (same window you're starting app from)?

These are minimum required to run:

XDG_RUNTIME_DIR
WAYLAND_DISPLAY

The most common variable missing is WAYLAND_DISPLAY

jwinarske commented 3 years ago

What's the status? Can I close this?

xobs commented 3 years ago

It still leaks out into the user's home directory, which was the original bug.

Let me try setting PUB_CACHE and seeing if that fixes it.

xobs commented 3 years ago

This is the patch I've applied, which appears to fix the original issue:

diff --git a/recipes-graphics/flutter-apps/flutter-sdk_git.bb b/recipes-graphics/flutter-apps/flutter-sdk_git.bb
index b23d357..c0855db 100644
--- a/recipes-graphics/flutter-apps/flutter-sdk_git.bb
+++ b/recipes-graphics/flutter-apps/flutter-sdk_git.bb
@@ -25,6 +25,7 @@ S = "${WORKDIR}/git"
 do_compile() {
     export CURL_CA_BUNDLE=${WORKDIR}/ca-certificates.crt
     export PATH=${S}/bin:$PATH
+    export PUB_CACHE=${S}/.pub-cache
     flutter channel ${FLUTTER_CHANNEL}
     flutter upgrade
 }

I've just completed a complete rebuild from scratch to verify this works.

xobs commented 3 years ago

Actually what's the output of env on your target's console window (same window you're starting app from)?

It should work, and as I said I can run programs such as weston-terminal, however flutter_wayland segfaults:

bash-5.0# env
SHELL=/bin/bash
PWD=/usr/share/flutter-gallery/sony/data
LOGNAME=root
XDG_SESSION_TYPE=tty
MOTD_SHOWN=pam
HOME=/root
LANG=C.UTF-8
WAYLAND_DISPLAY=wayland-0
INVOCATION_ID=e36266bc56d84615b95cda10b029f6d3
XDG_SESSION_CLASS=user
TERM=vt220
USER=root
SHLVL=2
XDG_SESSION_ID=1
XDG_RUNTIME_DIR=/run/user/0
JOURNAL_STREAM=8:2029
HUSHLOGIN=FALSE
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MAIL=/var/mail/root
_=/usr/bin/env
OLDPWD=/usr/share/flutter-gallery/sony
bash-5.0# flutter_wayland /usr/share/flutter-gallery/sony/data/flutter_assets/
LOG: /usr/src/debug/flutter-wayland/git-r0/git/src/main.cc:65: Arg: /usr/share/flutter-gallery/sony/data/flutter_assets/
Segmentation fault
bash-5.0# weston-terminal
could not load cursor 'dnd-move'
could not load cursor 'dnd-copy'
could not load cursor 'dnd-none'
^C
bash-5.0#
xobs commented 3 years ago

I can now debug flutter_wayland, and I can start working on that issue:

bash-5.0# gdb --args flutter_wayland /usr/share/flutter-gallery/sony/data/flutter_assets/
GNU gdb (GDB) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-poky-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from flutter_wayland...
Reading symbols from /usr/bin/.debug/flutter_wayland...
(gdb) run
Starting program: /usr/bin/flutter_wayland /usr/share/flutter-gallery/sony/data/flutter_assets/
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
LOG: /usr/src/debug/flutter-wayland/git-r0/git/src/main.cc:65: Arg: /usr/share/flutter-gallery/sony/data/flutter_assets/

Program received signal SIGSEGV, Segmentation fault.
std::function<void (wayland::seat_capability)>::swap(std::function<void (wayland::seat_capability)>&) (__x=..., this=0xffffffffeee8)
    at /usr/include/c++/10.2.0/bits/std_function.h:483
483             std::swap(_M_functor, __x._M_functor);
(gdb) bt
#0  std::function<void (wayland::seat_capability)>::swap(std::function<void (wayland::seat_capability)>&) (__x=...,
    this=0xffffffffeee8) at /usr/include/c++/10.2.0/bits/std_function.h:483
#1  std::function<void(wayland::seat_capability)>::operator=<flutter::WaylandDisplay::WaylandDisplay(size_t, size_t, const std::vector<std::__cxx11::basic_string<char> >&)::<lambda(wayland::seat_capability)> > (__f=..., __f=..., this=0x8)
    at /usr/include/c++/10.2.0/bits/std_function.h:459
#2  flutter::WaylandDisplay::WaylandDisplay (this=0xffffffffefd0, width=<optimized out>, height=<optimized out>, args=...)
    at /usr/src/debug/flutter-wayland/git-r0/git/src/wayland_display.cc:196
#3  0x0000aaaaaaabce04 in flutter::Main (args=...) at /usr/src/debug/flutter-wayland/git-r0/git/src/main.cc:68
#4  0x0000aaaaaaaa59e0 in main (argc=<optimized out>, argv=<optimized out>) at /usr/include/c++/10.2.0/bits/stl_vector.h:102
(gdb)

However, this is outside of the scope of the bug.

Would you like me to create a PR with the PUB_CACHE patch?

jwinarske commented 3 years ago

Great thanks for the stack trace. I'll open a new issue for this.

I just checked in the PUB_CACHE change.

I'm not clear about the error case for PUB_CACHE.

Can you help me understand this better? How does the error manifest? Are you developing Flutter app on the same machine that you are building Yocto image?

xobs commented 3 years ago

My concern about the PUB_CACHE error is that it makes builds non-reproducible.

For example, if you're doing development on your local machine, then it will share the PUB_CACHE with the build inside Yocto.

Or if you have two builds going at once (e.g. in a CI infrastructure), then two different versions will use the same cache, and it's unclear to me what the implications are of two concurrent builds using the same cache.

Or if you're on a system where home directories are much smaller than the global builder directories.

xobs commented 3 years ago

With https://github.com/jwinarske/meta-flutter/commit/265eab0cbc10bee03d101cb28a78709b5ce0b747 the original issue is solved. Thanks for the fix and the pointers!

jwinarske commented 3 years ago

I agree with your concern :+1: I just had not hit this yet! Thanks Sean!