canonical / flutter-snap

GNU General Public License v3.0
18 stars 8 forks source link

Possibil to override build install step for monorepositorys #65

Open KirioXX opened 2 years ago

KirioXX commented 2 years ago

Hi, thanks for this project. It made the start to package our flutter app a breeze.

We lately moved to a mono repository structure with melos to make the maintenance of our flutter apps a bit easier and share some code between the project. Our structure looks like this:

.
├── README.md
├── apps
│   ├── snap_app
│   │   ├── snap
│   ├── cli
│   ├── app1
│   └── app2
├── melos.yaml
├── packages
│   └── widgets

I'm pretty new to snapcraft and my question is would it be possible to switch out the install step for melos to link up the widgets or do I need to rebuild the build completely from scratch to make this work? Also, would I need to move the snap configuration to the root of the project to make the widgets even discoverable for the build process?

For a bit more context this is our current configuration that lives in apps/snap_app/snap :

name: supercool-app
version: 1.0.3
summary: Supercool App
description: Supercool App to visulize pilot data.

confinement: strict
base: core18
grade: stable

architectures:
  - build-on: [amd64]
  - build-on: [arm64]

environment:
  # TODO: remove when https://github.com/MirServer/ubuntu-frame/issues/49 is resolved
  GDK_GL: gles

apps:
  daemon:
    daemon: simple
    restart-condition: always
    command-chain:
      - bin/run-daemon
      - bin/wayland-launch
    command: bin/supercool-app
    extensions: [flutter-master]

  supercool-app:
    command-chain:
      - bin/wayland-launch
    command: supercool-app
    extensions: [flutter-master]

parts:
  supercool-app:
    source: .
    plugin: flutter
    flutter-target: lib/main.dart

  mir-kiosk-snap-launch:
    plugin: dump
    source: https://github.com/MirServer/mir-kiosk-snap-launch.git
    override-build: $SNAPCRAFT_PART_BUILD/build-with-plugs.sh opengl wayland
    stage-packages:
      - inotify-tools

  assets:
    plugin: nil
    stage-packages:
      - dmz-cursor-theme
      - fonts-dejavu
      - fonts-freefont-ttf
      - fonts-ubuntu

layout:
  /usr/share/fonts:
    bind: $SNAP/usr/share/fonts
  /etc/fonts:
    bind: $SNAP/etc/fonts
  /usr/share/icons:
    bind: $SNAP/usr/share/icons

Thank you in advance!

KirioXX commented 2 years ago

I found that I can override the build with the override-build option. My config looks now like this:

parts:
  supercool-app:
    source: .
    plugin: flutter
    flutter-target: lib/main.dart
    override-build: |
      export PATH="$PATH":"$HOME/.pub-cache/bin"
      flutter pub global activate melos
      melos bootstrap
      snapcraftctl build

The new problem is that the build path is set to apps/snap_app. This means the other packages are not imported and melos fails that the project is not a melos project.

jpnurmi commented 2 years ago

What's the error? You can run Melos from anywhere in the project tree and it walks up the tree until it finds melos.yaml.

For example, running Melos somewhere deep in a subdirectory such as ./packages/ubuntu_desktop_installer/build/linux/x64/debug/bundle finds ./melos.yaml:

jpnurmi@xps-13-9310:~/Projects/canonical/ubuntu-desktop-installer/packages/ubuntu_desktop_installer/build/linux/x64/debug/bundle (main)$ melos bootstrap
melos bootstrap
   └> /home/jpnurmi/Projects/canonical/ubuntu-desktop-installer

Running "flutter pub get" in workspace packages...
  ✓ glibc
    └> packages/glibc
  ✓ subiquity_client
    └> packages/subiquity_client
  ✓ ubuntu_desktop_installer
    └> packages/ubuntu_desktop_installer
  ✓ ubuntu_test
    └> packages/ubuntu_test
  ✓ ubuntu_wizard
    └> packages/ubuntu_wizard
  ✓ ubuntu_wsl_setup
    └> packages/ubuntu_wsl_setup
  ✓ udev
    └> packages/udev

Linking workspace packages...
  > SUCCESS

Generating IntelliJ IDE files...
  > SUCCESS

 -> 7 plugins bootstrapped
KirioXX commented 2 years ago

Thanks for the response @jpnurmi. The configuration in my github action looks like this:

- name: Build snap
    uses: snapcore/action-build@v1
    with:
      path: ./apps/snap_app
    id: snapcraft

and I think that is the problem. It looks like it just imports the snap_app folder and not the complete project. The error I get is this one:

melos.yaml: Your current directory does not appear to be a valid Melos workspace.

You must have one of the following to be a valid Melos workspace:
  - a "melos.yaml" file in the root with a "packages" option defined
  - a "packages" directory

But when I move the snap config to the root of the project is it not running the snapcraftctl build in the snap_app folder. Even not when I try to navigate to it in the override-build configuration.

I probably just miss something in the config for the snapcraftctl build comand to point the command to the correct place but I can not find what I could miss.