Use of override-build in multi-arch snapcraft file

I am using the override-build step in my snapcraft file as follows:

override-build: |
export JAVA_TO_USE="/usr/lib/jvm/java-8-openjdk-amd64"
export JAVA_HOME="$SNAPCRAFT_PART_INSTALL$JAVA_TO_USE"
ant
mkdir $SNAPCRAFT_PART_INSTALL/jar
mv $SNAPCRAFT_PART_BUILD/target/*.jar $SNAPCRAFT_PART_INSTALL/jar

However now I want to build multi architecture support (for armhf and amd64) into my snapcraft file. The JAVA_TO_USE env variable will be different for each platform. So what is the correct syntax for that in the yaml file.
I have tried using - on armhf like this:

> override-build: |
      -on amd64: export JAVA_TO_USE="/usr/lib/jvm/java-8-openjdk-amd64"
     -on armhf: export JAVA_TO_USE="/usr/lib/jvm/java-8-openjdk-armhf"
      export JAVA_HOME="$SNAPCRAFT_PART_INSTALL$JAVA_TO_USE"
      ant
      mkdir $SNAPCRAFT_PART_INSTALL/jar
      mv $SNAPCRAFT_PART_BUILD/target/*.jar $SNAPCRAFT_PART_INSTALL/jar

and other variations.
Any suggestions as to how to achieve this.

you could try build-environment: to set the vars i think that should support the “- on <arch>” syntax…

see “plugin variables” at the bottom of:

Yes I am trying that but I am not sure I have the correct syntax yet:

I have tried:

build-environment:
- JAVA_TO_USE:
- on amd64: “/usr/lib/jvm/java-8-openjdk-amd64”

Also

build-environment:
- on amd64:
- JAVA_TO_USE: “/usr/lib/jvm/java-8-openjdk-amd64”

Any more suggestions?

hmm, not sure perhaps i’m hoping for too much intelligence here … @sergiusens should using the on/to syntax work with build-environment: yet ?

(FWIW: i’d expect the latter example to work if snapcraft supports this yet)

I do not believe build-environment supports that syntax yet. The best best it to do it with a little scripting in override-build for now (e.g. using conditional if statements). We do want to extend advanced grammar in the near future.

2 Likes

Thank you. I got sorted with use if else conditional in override-build.
I have moved on to a new challenge now.


Appreciate any feedback.