Editing files during override-build

So I have a override build script commad with the following:

sudo swig3.0 -python /root/project/lib//mylib.i
sudo gcc -w -fPIC -shared /root/project/lib/mylib_wrap.c -o /root/project/lib/_mylib.so -L. -lpthread -lm -L/root/project/lib/ -l:libmylib32.so.1 -I/usr/include/python3.10

This command works when I run it manually. Source is my repo. However when I build my snap with the snapcraft command I get:

load state file: /root/parts/mylib-build/state/pull
+ sudo swig3.0 -python /root/project/lib/mylib.i
Unable to open file /root/project/lib/mylib_wrap.c: Permission denied
'override-build' in part 'fmyib-build' failed with code 1.
Review the scriptlet and make sure it's correct.

I added in sudo to try and get around it, but I still get the permissions error. Any ideas of how to get this to run in the current folder?

You might want to consider changing the prefix /root/project to $SNAPCRAFT_PART_BUILD. You don’t need sudo in this case. Add the --debug flag to the snapcraft command to shell into it and you can inspect the files there and trying to run it within the snapcraft build enviornment.

I originally had $SNAPCRAFT_PART_INSTALL as the path - that path is /root/project/. I changed it to hard code just to see if it fixed it. I confirmed files are in this path via debug.

$SNAPCRAFT_PART_BUILD (path is /root/parts/mylib-build/build) gives files not found.