Skip to content

Commit

Permalink
Update expected SDK layout (#75)
Browse files Browse the repository at this point in the history
* Using NewDefaultModel to initialize SDK
* Update NDK lookup path
  • Loading branch information
lpusok authored Jun 24, 2021
1 parent 8e2a107 commit 6ed845c
Show file tree
Hide file tree
Showing 29 changed files with 1,286 additions and 1,096 deletions.
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ module github.com/bitrise-steplib/steps-install-missing-android-tools
go 1.16

require (
github.com/bitrise-io/go-android v0.0.0-20210301151701-791fb4b5216b
github.com/bitrise-io/go-steputils v0.0.0-20210507072936-92fde382fb33
github.com/bitrise-io/go-utils v0.0.0-20210507100250-37de47dfa6ce
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
github.com/hashicorp/go-version v1.3.0
github.com/pkg/errors v0.9.1
)
30 changes: 19 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
github.com/bitrise-io/go-android v0.0.0-20210301151701-791fb4b5216b h1:lsdgaoWqwLWa7ohHRBblY2lAafvK+m9bKAWm8ZCjNo8=
github.com/bitrise-io/go-android v0.0.0-20210301151701-791fb4b5216b/go.mod h1:ZMsq2ivTUD2q50BYEUGjd68S9CXYqDYqFds43rnx84g=
github.com/bitrise-io/go-steputils v0.0.0-20210507072936-92fde382fb33 h1:4QpxkX2oNefww7k76ZUD4C7unfP4c8H0c0QP7SdfrTQ=
github.com/bitrise-io/go-steputils v0.0.0-20210507072936-92fde382fb33/go.mod h1:YCtb1VETn/rF9tCt9oInhd/cwbt1ETPm+dTlDIfyD+A=
github.com/bitrise-io/go-utils v0.0.0-20210506064210-b22e2b7b3ad3/go.mod h1:nhdaDQFvaMny1CugVV6KjK92/q97ENo0RuKSW5I4fbA=
github.com/bitrise-io/go-utils v0.0.0-20210507100250-37de47dfa6ce h1:z9t020cBpCZdwO4teTXbj7XyLwQDvMcMmfnhHe36mWc=
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e h1:lkJnz+yXbIqFGpDTdRBBshqxeX0UCndJmEOp0yy2GRQ=
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e/go.mod h1:gGXmY8hJ1x44AC98TIvZZvxP7o+hs4VI6wgmO4JMfEg=
github.com/bitrise-io/go-steputils v0.0.0-20210514150206-5b6261447e77/go.mod h1:H0iZjgsAR5NA6pnlD/zKB6AbxEsskq55pwJ9klVmP8w=
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1 h1:gi29hTdxGXAGQvZckPZ9V8BAEfP3eK/tiZgTC5s6h1c=
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1/go.mod h1:H0iZjgsAR5NA6pnlD/zKB6AbxEsskq55pwJ9klVmP8w=
github.com/bitrise-io/go-utils v0.0.0-20210507100250-37de47dfa6ce/go.mod h1:15EZZf02noI5nWFqXMZEoyb1CyqYRXTMz5Fyu4CWFzI=
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5 h1:kclxBfygfNK6kWUB+9xcsfPLBen8Us9gubhitfL/Z6c=
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5/go.mod h1:DRx7oFuAqk0dbKpAKCqWl0TgrowfJUb/MqYPRscxJOQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -13,17 +14,14 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.6.6 h1:HJunrbHTDDbBb/ay4kxa1n+dLmttUlnP3V9oNE4hmsM=
github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4=
github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand All @@ -32,14 +30,24 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
78 changes: 24 additions & 54 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,27 @@ import (
"strings"

"github.com/bitrise-io/go-android/sdk"
"github.com/bitrise-io/go-steputils/input"
"github.com/bitrise-io/go-steputils/stepconf"
"github.com/bitrise-io/go-steputils/tools"
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/fileutil"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-io/go-utils/pathutil"
"github.com/bitrise-steplib/steps-install-missing-android-tools/androidcomponents"
"github.com/hashicorp/go-version"
"github.com/pkg/errors"
)

const platformDirName = "platforms"
const androidNDKHome = "ANDROID_NDK_HOME"

// ConfigsModel ...
type ConfigsModel struct {
GradlewPath string
AndroidHome string
NDKRevision string
// Config ...
type Config struct {
GradlewPath string `env:"gradlew_path,file"`
AndroidHome string `env:"ANDROID_HOME"`
AndroidSDKRoot string `env:"ANDROID_SDK_ROOT"`
NDKRevision string `env:"ndk_revision"`
}

func createConfigsModelFromEnvs() ConfigsModel {
return ConfigsModel{
GradlewPath: os.Getenv("gradlew_path"),
AndroidHome: os.Getenv("ANDROID_HOME"),
NDKRevision: os.Getenv("ndk_revision"),
}
}

func (configs ConfigsModel) print() {
log.Infof("Configs:")
log.Printf("- GradlewPath: %s", configs.GradlewPath)
log.Printf("- AndroidHome: %s", configs.AndroidHome)
log.Printf("- NDKRevision: %s", configs.NDKRevision)
}

func (configs ConfigsModel) validate() error {
if err := input.ValidateIfPathExists(configs.GradlewPath); err != nil {
return errors.New("Issue with input GradlewPath: " + err.Error())
}

if err := input.ValidateIfNotEmpty(configs.AndroidHome); err != nil {
return errors.New("Issue with input AndroidHome: " + err.Error())
}

return nil
}

// -----------------------
// --- Functions
// -----------------------

func failf(format string, v ...interface{}) {
log.Errorf(format, v...)
os.Exit(1)
Expand Down Expand Up @@ -101,6 +70,9 @@ func ndkHome() string {
if v := os.Getenv("ANDROID_HOME"); v != "" {
return filepath.Join(v, "android-ndk-bundle")
}
if v := os.Getenv("ANDROID_SDK_ROOT"); v != "" {
return filepath.Join(v, "android-ndk-bundle")
}
if v := os.Getenv("HOME"); v != "" {
return filepath.Join(v, "android-ndk-bundle")
}
Expand Down Expand Up @@ -196,35 +168,30 @@ func updateNDKPath(path string) error {
return nil
}

// -----------------------
// --- Main
// -----------------------

func main() {
// Input validation
configs := createConfigsModelFromEnvs()
var config Config
if err := stepconf.Parse(&config); err != nil {
log.Errorf("%s", err)
}

fmt.Println()
configs.print()

if err := configs.validate(); err != nil {
failf(err.Error())
}
stepconf.Print(config)

fmt.Println()
log.Infof("Preparation")

// Set executable permission for gradlew
log.Printf("Set executable permission for gradlew")
if err := os.Chmod(configs.GradlewPath, 0770); err != nil {
if err := os.Chmod(config.GradlewPath, 0770); err != nil {
failf("Failed to set executable permission for gradlew, error: %s", err)
}

fmt.Println()
if configs.NDKRevision != "" {
if config.NDKRevision != "" {
log.Infof("Installing NDK bundle")

if err := updateNDK(configs.NDKRevision); err != nil {
if err := updateNDK(config.NDKRevision); err != nil {
failf("Failed to download NDK bundle, error: %s", err)
}
} else {
Expand All @@ -242,9 +209,12 @@ func main() {

// Initialize Android SDK
log.Printf("Initialize Android SDK")
androidSdk, err := sdk.New(configs.AndroidHome)
androidSdk, err := sdk.NewDefaultModel(sdk.Environment{
AndroidHome: config.AndroidHome,
AndroidSDKRoot: config.AndroidSDKRoot,
})
if err != nil {
failf("Failed to initialize Android SDK, error: %s", err)
failf("Failed to initialize Android SDK: %s", err)
}

androidcomponents.SetLogger(log.NewDefaultLogger(false))
Expand All @@ -260,7 +230,7 @@ func main() {
fmt.Println()
log.Infof("Ensure required Android SDK components")

if err := androidcomponents.Ensure(androidSdk, configs.GradlewPath); err != nil {
if err := androidcomponents.Ensure(androidSdk, config.GradlewPath); err != nil {
failf("Failed to ensure android components, error: %s", err)
}

Expand Down
7 changes: 0 additions & 7 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,8 @@ project_type_tags:
- react-native
type_tags:
- installer
is_requires_admin_user: false
is_always_run: false
is_skippable: false
deps:
brew:
- name: go
apt_get:
- name: golang
bin_name: go
toolkit:
go:
package_name: github.com/bitrise-steplib/steps-install-missing-android-tools
Expand Down
99 changes: 93 additions & 6 deletions vendor/github.com/bitrise-io/go-android/sdk/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6ed845c

Please sign in to comment.