Use the "on <arch>" on override-stage

My application has some yaml config files which contain absolute paths to other files. My application was designed to be packaged as a deb and those abs paths can’t be replicated on my snap. E.g. they contain paths like /opt/stuff/file which on snaps end up on /snap/<snapName>/current/opt/suff/file.

I manged to patch these files by doing

    override-stage: |
      craftctl default
      <sed command> <filepath> 

And that worked fine. But now I need different sed commands and list of files to patch based on the arch the snap targets. I tried to do

    override-stage:
      - on amd64: |
      craftctl default

But it doesn’t work

snapcraft.yaml parsing error: while scanning a simple key
  in "snap/snapcraft.yaml", line 43, column 7
could not find expected ':'
  in "snap/snapcraft.yaml", line 44, column 7      

Is there a way to use the arch conditionals on the override-<> sections?

You can use if else, like

override-stage: |
  craftctl default
  if [ $CRAFT_ARCH_BUILD_FOR -eq amd64 ]; then
    # do something here
  fi

Awesome, thanks for the quick response. It works after a small modification (-eq only works for integers)

    override-stage: |
      craftctl default
      if [ $CRAFT_ARCH_BUILD_FOR = amd64 ]; then
        # do something here
      fi

I recommend to use this syntax instead

 override-stage: |
      craftctl default
      if [[ $CRAFT_ARCH_BUILD_FOR == "amd64" ]]; then
        # do something here
      fi
2 Likes

Thanks for letting me know! (Not a bash expert)

1 Like