From 3de7d5718e7adc5746ce752aff936c346f4710ca Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Thu, 20 Sep 2018 16:50:13 +0200 Subject: [PATCH] chown built artifacts to the correct owner after build. Closes #37 Avoids having files be created on host as `root` --- docker/base/build.sh | 7 ++++++- xgo.go | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docker/base/build.sh b/docker/base/build.sh index daf1ce1..df671ee 100644 --- a/docker/base/build.sh +++ b/docker/base/build.sh @@ -46,7 +46,7 @@ function extension { fi } -# Either set a local build environemnt, or pull any remote imports +# Either set a local build environment, or pull any remote imports if [ "$EXT_GOPATH" != "" ]; then # If local builds are requested, inject the sources echo "Building locally $1..." @@ -296,6 +296,9 @@ for TARGET in $TARGETS; do (cd $archive && zip -r $bundle *) rm -rf $jni $archive fi + + # Fix up permissions on bundle file + chown $UID:$GID $bundle fi # Clean up the android builds, toolchains and runtimes rm -rf /build-android-aar @@ -600,6 +603,8 @@ for TARGET in $TARGETS; do echo -e "framework module \"$title\" {\n header \"$title.h\"\n export *\n}" > $framework/Versions/A/Modules/module.modulemap (cd $framework && ln -nsf Versions/A/Modules Modules) + # Fix up permissions on bundle file + chown $UID:$GID /build/$NAME-ios-$PLATFORM-framework chmod 777 -R /build/$NAME-ios-$PLATFORM-framework fi rm -rf /build-ios-fw diff --git a/xgo.go b/xgo.go index b2bae9c..9d08b7b 100644 --- a/xgo.go +++ b/xgo.go @@ -299,6 +299,12 @@ func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string "-e", fmt.Sprintf("FLAG_BUILDMODE=%s", flags.Mode), "-e", "TARGETS=" + strings.Replace(strings.Join(config.Targets, " "), "*", ".", -1), } + user, err := user.Current() + if err == nil { + args = append(args, + "-e", fmt.Sprintf("UID=%s", user.Uid), + "-e", fmt.Sprintf("GID=%s", user.Gid)) + } for i := 0; i < len(locals); i++ { args = append(args, []string{"-v", fmt.Sprintf("%s:%s:ro", locals[i], mounts[i])}...) }