Skip to content

Commit

Permalink
Use WriteFileContents to write license agreements
Browse files Browse the repository at this point in the history
So it works in a container or in Metal
  • Loading branch information
Ridai Govinda Pombo committed Jul 6, 2020
1 parent 8beeab1 commit c8f44c5
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions buildpacks/android_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package buildpacks
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -71,7 +70,7 @@ func (bt AndroidBuildTool) Version() string {
return bt.version
}

func (bt AndroidBuildTool) WriteAgreements(ctx context.Context, androidDir string) bool {
func (bt AndroidBuildTool) writeAgreements(ctx context.Context, androidDir string) bool {
agreements := map[string]string{
"android-googletv-license": "601085b94cd77f0b54ff86406957099ebe79c4d6",
"android-sdk-license": "24333f8a63b6825ea9c5514f83c2829b004d1fee",
Expand All @@ -87,23 +86,11 @@ func (bt AndroidBuildTool) WriteAgreements(ctx context.Context, androidDir strin

for filename, hash := range agreements {
agreementFile := filepath.Join(licensesDir, filename)
// TODO add as a Runtime/Target method: CreateFile
f, err := os.Create(agreementFile)
err := t.WriteFileContents(ctx, hash, agreementFile)
if err != nil {
log.Errorf("Can't create agreement file %s: %v", agreementFile, err)
return false
}

defer f.Close()
_, err = f.WriteString(hash)

if err != nil {
log.Errorf("Can't write agreement file %s: %v", agreementFile, err)
return false
}

f.Sync()

log.Infof("Wrote hash for agreement: %s", agreementFile)
}

Expand All @@ -119,8 +106,8 @@ func (bt AndroidBuildTool) Setup(ctx context.Context, androidDir string) error {
t.SetEnv("ANDROID_HOME", androidDir)

log.Infof("Writing agreement hashes...")
if !bt.WriteAgreements(ctx, androidDir) {
return fmt.Errorf("Unable to auto write the agreements")
if !bt.writeAgreements(ctx, androidDir) {
return fmt.Errorf("auto write the agreements")
}

t.PrependToPath(ctx, filepath.Join(androidDir, "tools"))
Expand Down

0 comments on commit c8f44c5

Please sign in to comment.