diff --git a/e2e/bitrise.yml b/e2e/bitrise.yml index 57f499a..cc1ea0e 100644 --- a/e2e/bitrise.yml +++ b/e2e/bitrise.yml @@ -37,11 +37,16 @@ workflows: #!/usr/bin/env bash set -ex yarn - after_run: - - _run_and_build + - path::./: + title: Execute step + inputs: + - ndk_revision: 21 + - gradle-runner: + inputs: + - gradle_task: assembleDebug test_ndk_install: - summary: Test installing multiple NDK revisions + summary: Test installing multiple NDK revisions and compare installed version numbers to expected values envs: - SAMPLE_APP_URL: https://github.com/bitrise-io/android-ndk-sample-project.git - BRANCH: ndk22-compatible @@ -57,20 +62,72 @@ workflows: - path::./: title: Execute step with NDK r18 inputs: - - ndk_revision: "18" + - ndk_revision: 18 + - script: + title: Check installed NDK version + inputs: + - content: |- + EXPECTED_VERSION=18.0.5002713 + NDK_VERSION=`cat $ANDROID_HOME/ndk-bundle/source.properties | grep Pkg.Revision | cut -d'=' -f2 | cut -d' ' -f2` + if [ $NDK_VERSION != $EXPECTED_VERSION ]; then + echo "Unexpected installed NDK version: $NDK_VERSION" + echo "Expected: $EXPECTED_VERSION" + exit 1 + else + echo "NDK version is correct: $NDK_VERSION" + fi - path::./: title: Execute step again with NDK r18 inputs: - - ndk_revision: "18" + - ndk_revision: 18 + - script: + title: Check installed NDK version + inputs: + - content: |- + EXPECTED_VERSION=18.0.5002713 + NDK_VERSION=`cat $ANDROID_HOME/ndk-bundle/source.properties | grep Pkg.Revision | cut -d'=' -f2 | cut -d' ' -f2` + if [ $NDK_VERSION != $EXPECTED_VERSION ]; then + echo "Unexpected installed NDK version: $NDK_VERSION" + echo "Expected: $EXPECTED_VERSION" + exit 1 + else + echo "NDK version is correct: $NDK_VERSION" + fi - path::./: title: Execute step with NDK r17 inputs: - - ndk_revision: "17" + - ndk_revision: 17 + - script: + title: Check installed NDK version + inputs: + - content: |- + EXPECTED_VERSION=17.0.4754217 + NDK_VERSION=`cat $ANDROID_HOME/ndk-bundle/source.properties | grep Pkg.Revision | cut -d'=' -f2 | cut -d' ' -f2` + if [ $NDK_VERSION != $EXPECTED_VERSION ]; then + echo "Unexpected installed NDK version: $NDK_VERSION" + echo "Expected: $EXPECTED_VERSION" + exit 1 + else + echo "NDK version is correct: $NDK_VERSION" + fi - path::./: title: Execute step with NDK r22 description: NDK r22 doesn't contain the platforms dir anymore inputs: - - ndk_revision: "22" + - ndk_revision: 22 + - script: + title: Check installed NDK version + inputs: + - content: |- + EXPECTED_VERSION=22.0.7026061 + NDK_VERSION=`cat $ANDROID_HOME/ndk-bundle/source.properties | grep Pkg.Revision | cut -d'=' -f2 | cut -d' ' -f2` + if [ $NDK_VERSION != $EXPECTED_VERSION ]; then + echo "Unexpected installed NDK version: $NDK_VERSION" + echo "Expected: $EXPECTED_VERSION" + exit 1 + else + echo "NDK version is correct: $NDK_VERSION" + fi - gradle-runner: inputs: - gradle_task: assembleDebug diff --git a/main.go b/main.go index 7fef228..0eb6e87 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,10 @@ package main import ( "fmt" + "io/ioutil" "os" "path/filepath" + "regexp" "runtime" "strings" @@ -66,15 +68,15 @@ func ndkHome() string { return v } if v := os.Getenv("ANDROID_HOME"); v != "" { - return filepath.Join(v, "android-ndk-bundle") + return filepath.Join(v, "ndk-bundle") } if v := os.Getenv("ANDROID_SDK_ROOT"); v != "" { - return filepath.Join(v, "android-ndk-bundle") + return filepath.Join(v, "ndk-bundle") } if v := os.Getenv("HOME"); v != "" { - return filepath.Join(v, "android-ndk-bundle") + return filepath.Join(v, "ndk-bundle") } - return "android-ndk-bundle" + return "ndk-bundle" } func inPath(path string) bool { @@ -85,40 +87,63 @@ func updateNDK(revision string) error { ndkURL := ndkDownloadURL(revision) ndkHome := ndkHome() - if currentRevision := installedNDKVersion(ndkHome); currentRevision == revision { - log.Donef("NDK r%s already installed", revision) + currentRevision := installedNDKVersion(ndkHome) + if currentRevision == revision { + log.Donef("NDK r%s already installed at %s", revision, ndkHome) return nil } - log.Printf("NDK home: %s", ndkHome) - log.Printf("Cleaning") + if currentRevision != "" { + log.Printf("NDK version %s found at: %s", currentRevision, ndkHome) + } + log.Printf("Removing NDK...") if err := os.RemoveAll(ndkHome); err != nil { return err } + log.Printf("Done") - if err := pathutil.EnsureDirExist(ndkHome); err != nil { + log.Printf("Downloading NDK r%s...", revision) + // The NDK archive contents are wrapped in an extra subdirectory, so we unzip to the parent directory, + // then rename the subdirectory to ndk-bundle + subDirPattern, err := regexp.Compile("android-ndk-.*") + if err != nil { return err } - log.Printf("Downloading") + unzipTarget := filepath.Dir(ndkHome) + if err := pathutil.EnsureDirExist(unzipTarget); err != nil { + return err + } + if err := command.DownloadAndUnZIP(ndkURL, unzipTarget); err != nil { + return err + } - if err := command.DownloadAndUnZIP(ndkURL, ndkHome); err != nil { + var unzippedDirName string + dirs, err := ioutil.ReadDir(unzipTarget) + for _, dir := range dirs { + if subDirPattern.MatchString(dir.Name()) { + unzippedDirName = dir.Name() + } + } + if err := os.Rename(filepath.Join(unzipTarget, unzippedDirName), ndkHome); err != nil { return err } + log.Printf("Done") + if !inPath(ndkHome) { - log.Printf("Append to $PATH") + log.Printf("Appended NDK folder to $PATH") if err := tools.ExportEnvironmentWithEnvman("PATH", fmt.Sprintf("%s:%s", os.Getenv("PATH"), ndkHome)); err != nil { return err } } if os.Getenv(androidNDKHome) == "" { - log.Printf("Export %s: %s", androidNDKHome, ndkHome) if err := tools.ExportEnvironmentWithEnvman(androidNDKHome, ndkHome); err != nil { return err } + log.Printf("Exported $%s: %s", androidNDKHome, ndkHome) } return nil @@ -164,7 +189,8 @@ func main() { } // Initialize Android SDK - log.Printf("Initialize Android SDK") + fmt.Println() + log.Infof("Initialize Android SDK") androidSdk, err := sdk.NewDefaultModel(sdk.Environment{ AndroidHome: config.AndroidHome, AndroidSDKRoot: config.AndroidSDKRoot,