Skip to content

Commit

Permalink
New runtime context
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridai Govinda Pombo committed May 15, 2020
1 parent 16af1ae commit f6ce924
Show file tree
Hide file tree
Showing 50 changed files with 2,390 additions and 1,517 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ yb
.DS_Store
release
.vscode
.env
.vscode
2 changes: 1 addition & 1 deletion .yourbase.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies:
build:
- go:1.13.4
- go:1.14.2
- python:3.6

build_targets:
Expand Down
8 changes: 5 additions & 3 deletions buildpacks/anaconda.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

. "github.com/yourbase/yb/plumbing"
"github.com/yourbase/yb/plumbing/log"
"github.com/yourbase/yb/runtime"
. "github.com/yourbase/yb/types"
)

Expand Down Expand Up @@ -50,6 +51,7 @@ func (bt AnacondaBuildTool) InstallDir() string {
func (bt AnacondaBuildTool) Install() error {
anacondaDir := bt.InstallDir()
setupDir := bt.spec.PackageDir
t := bt.spec.InstallTarget

if _, err := os.Stat(anacondaDir); err == nil {
log.Infof("anaconda installed in %s", anacondaDir)
Expand All @@ -59,7 +61,7 @@ func (bt AnacondaBuildTool) Install() error {
downloadUrl := bt.DownloadUrl()

log.Infof("Downloading Miniconda from URL %s...", downloadUrl)
localFile, err := DownloadFileWithCache(downloadUrl)
localFile, err := t.DownloadFile(downloadUrl)
if err != nil {
log.Errorf("Unable to download: %v\n", err)
return err
Expand All @@ -69,7 +71,7 @@ func (bt AnacondaBuildTool) Install() error {
fmt.Sprintf("bash %s -b -p %s", localFile, anacondaDir),
} {
log.Infof("Running: '%v' ", cmd)
ExecToStdout(cmd, setupDir)
runtime.ExecToStdout(cmd, setupDir)
}

}
Expand Down Expand Up @@ -133,7 +135,7 @@ func (bt AnacondaBuildTool) Setup() error {
fmt.Sprintf("conda update -q conda"),
} {
log.Infof("Running: '%v' ", cmd)
ExecToStdout(cmd, setupDir)
runtime.ExecToStdout(cmd, setupDir)
}

return nil
Expand Down
11 changes: 5 additions & 6 deletions buildpacks/android_ndk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package buildpacks

import (
"fmt"
"github.com/yourbase/yb/runtime"
"os"
"path/filepath"

"github.com/johnewart/archiver"
. "github.com/yourbase/yb/plumbing"
"github.com/yourbase/yb/plumbing/log"
. "github.com/yourbase/yb/types"
)
Expand Down Expand Up @@ -63,7 +62,7 @@ func (bt AndroidNdkBuildTool) Version() string {
}

func (bt AndroidNdkBuildTool) InstallDir() string {
return filepath.Join(ToolsDir(), "android-ndk")
return filepath.Join(bt.spec.InstallTarget.ToolsDir(), "android-ndk")
}

func (bt AndroidNdkBuildTool) NdkDir() string {
Expand All @@ -74,7 +73,7 @@ func (bt AndroidNdkBuildTool) Setup() error {
ndkDir := bt.NdkDir()

log.Infof("Setting ANDROID_NDK_HOME to %s", ndkDir)
os.Setenv("ANDROID_NDK_HOME", ndkDir)
runtime.SetEnv("ANDROID_NDK_HOME", ndkDir)

return nil
}
Expand All @@ -91,12 +90,12 @@ func (bt AndroidNdkBuildTool) Install() error {
downloadUrl := bt.DownloadUrl()

log.Infof("Downloading Android NDK v%s from URL %s...", bt.Version(), downloadUrl)
localFile, err := DownloadFileWithCache(downloadUrl)
localFile, err := bt.spec.InstallTarget.DownloadFile(downloadUrl)
if err != nil {
log.Errorf("Unable to download: %v", err)
return err
}
err = archiver.Unarchive(localFile, installDir)
err = bt.spec.InstallTarget.Unarchive(localFile, installDir)
if err != nil {
log.Errorf("Unable to decompress: %v", err)
return err
Expand Down
27 changes: 10 additions & 17 deletions buildpacks/android_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package buildpacks

import (
"fmt"
"github.com/yourbase/yb/runtime"
"os"
"path/filepath"
"strings"

"github.com/johnewart/archiver"
. "github.com/yourbase/yb/plumbing"
"github.com/yourbase/yb/plumbing/log"
. "github.com/yourbase/yb/types"
Expand Down Expand Up @@ -74,7 +74,7 @@ func (bt AndroidBuildTool) Version() string {
}

func (bt AndroidBuildTool) InstallDir() string {
return filepath.Join(ToolsDir(), "android", fmt.Sprintf("android-%s", bt.Version()))
return filepath.Join(bt.spec.InstallTarget.ToolsDir(), "android", fmt.Sprintf("android-%s", bt.Version()))
}

func (bt AndroidBuildTool) AndroidDir() string {
Expand Down Expand Up @@ -121,25 +121,18 @@ func (bt AndroidBuildTool) WriteAgreements() bool {

func (bt AndroidBuildTool) Setup() error {
androidDir := bt.AndroidDir()

binPath := fmt.Sprintf("%s/tools/bin", androidDir)
toolsPath := fmt.Sprintf("%s/tools", androidDir)
currentPath := os.Getenv("PATH")
newPath := fmt.Sprintf("%s:%s", binPath, currentPath)
newPath = fmt.Sprintf("%s:%s", toolsPath, newPath)
log.Infof("Setting PATH to %s", newPath)
os.Setenv("PATH", newPath)

//fmt.Printf("Setting ANDROID_HOME to %s\n", androidHomeDir)
//os.Setenv("ANDROID_HOME", androidHomeDir)
t := bt.spec.InstallTarget

log.Infof("Setting ANDROID_SDK_ROOT to %s", androidDir)
os.Setenv("ANDROID_SDK_ROOT", androidDir)
os.Setenv("ANDROID_HOME", androidDir)
runtime.SetEnv("ANDROID_SDK_ROOT", androidDir)
runtime.SetEnv("ANDROID_HOME", androidDir)

log.Infof("Writing agreement hashes...")
bt.WriteAgreements()

t.PrependToPath(filepath.Join(androidDir, "tools"))
t.PrependToPath(filepath.Join(androidDir, "tools", "bin"))

return nil
}

Expand All @@ -155,12 +148,12 @@ func (bt AndroidBuildTool) Install() error {
downloadUrl := bt.DownloadUrl()

log.Infof("Downloading Android from URL %s...", downloadUrl)
localFile, err := DownloadFileWithCache(downloadUrl)
localFile, err := bt.spec.InstallTarget.DownloadFile(downloadUrl)
if err != nil {
log.Errorf("Unable to download: %v", err)
return err
}
err = archiver.Unarchive(localFile, installDir)
err = bt.spec.InstallTarget.Unarchive(localFile, installDir)
if err != nil {
log.Errorf("Unable to decompress: %v", err)
return err
Expand Down
13 changes: 4 additions & 9 deletions buildpacks/ant.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"path/filepath"
"strings"

"github.com/johnewart/archiver"
. "github.com/yourbase/yb/plumbing"
"github.com/yourbase/yb/plumbing/log"
. "github.com/yourbase/yb/types"
)
Expand Down Expand Up @@ -66,12 +64,9 @@ func (bt AntBuildTool) InstallDir() string {

func (bt AntBuildTool) Setup() error {
antDir := bt.AntDir()
t := bt.spec.InstallTarget

cmdPath := filepath.Join(antDir, "bin")
currentPath := os.Getenv("PATH")
newPath := fmt.Sprintf("%s:%s", cmdPath, currentPath)
log.Infof("Setting PATH to %s", newPath)
os.Setenv("PATH", newPath)
t.PrependToPath(filepath.Join(antDir, "bin"))

return nil
}
Expand All @@ -88,12 +83,12 @@ func (bt AntBuildTool) Install() error {
downloadUrl := bt.DownloadUrl()

log.Infof("Downloading Ant from URL %s...", downloadUrl)
localFile, err := DownloadFileWithCache(downloadUrl)
localFile, err := bt.spec.InstallTarget.DownloadFile(downloadUrl)
if err != nil {
log.Errorf("Unable to download: %v", err)
return err
}
err = archiver.Unarchive(localFile, installDir)
err = bt.spec.InstallTarget.Unarchive(localFile, installDir)
if err != nil {
log.Errorf("Unable to decompress: %v", err)
return err
Expand Down
5 changes: 2 additions & 3 deletions buildpacks/dart.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path/filepath"
"strings"

"github.com/johnewart/archiver"
. "github.com/yourbase/yb/plumbing"
"github.com/yourbase/yb/plumbing/log"
. "github.com/yourbase/yb/types"
Expand Down Expand Up @@ -98,12 +97,12 @@ func (bt DartBuildTool) Install() error {
downloadUrl := bt.DownloadUrl()

log.Infof("Downloading Dart from URL %s...", downloadUrl)
localFile, err := DownloadFileWithCache(downloadUrl)
localFile, err := bt.spec.InstallTarget.DownloadFile(downloadUrl)
if err != nil {
log.Errorf("Unable to download: %v", err)
return err
}
err = archiver.Unarchive(localFile, installDir)
err = bt.spec.InstallTarget.Unarchive(localFile, installDir)
if err != nil {
log.Errorf("Unable to decompress: %v", err)
return err
Expand Down
13 changes: 4 additions & 9 deletions buildpacks/flutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import (
"path/filepath"
"strings"

"github.com/johnewart/archiver"
"golang.org/x/mod/semver"

. "github.com/yourbase/yb/plumbing"
"github.com/yourbase/yb/plumbing/log"
. "github.com/yourbase/yb/types"
)
Expand Down Expand Up @@ -96,12 +94,9 @@ func (bt FlutterBuildTool) FlutterDir() string {

func (bt FlutterBuildTool) Setup() error {
flutterDir := bt.FlutterDir()
t := bt.spec.InstallTarget

cmdPath := filepath.Join(flutterDir, "bin")
currentPath := os.Getenv("PATH")
newPath := fmt.Sprintf("%s:%s", cmdPath, currentPath)
log.Infof("Setting PATH to %s", newPath)
os.Setenv("PATH", newPath)
t.PrependToPath(filepath.Join(flutterDir, "bin"))

return nil
}
Expand All @@ -118,12 +113,12 @@ func (bt FlutterBuildTool) Install() error {
downloadUrl := bt.DownloadUrl()

log.Infof("Downloading Flutter from URL %s...", downloadUrl)
localFile, err := DownloadFileWithCache(downloadUrl)
localFile, err := bt.spec.InstallTarget.DownloadFile(downloadUrl)
if err != nil {
log.Errorf("Unable to download: %v", err)
return err
}
err = archiver.Unarchive(localFile, installDir)
err = bt.spec.InstallTarget.Unarchive(localFile, installDir)
if err != nil {
log.Errorf("Unable to decompress: %v", err)
return err
Expand Down
15 changes: 7 additions & 8 deletions buildpacks/glide.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"path/filepath"

"github.com/johnewart/archiver"
. "github.com/yourbase/yb/plumbing"
"github.com/yourbase/yb/plumbing/log"
. "github.com/yourbase/yb/types"
Expand Down Expand Up @@ -44,11 +43,11 @@ func (bt GlideBuildTool) GlideDir() string {

func (bt GlideBuildTool) Setup() error {
glideDir := bt.GlideDir()
cmdPath := fmt.Sprintf("%s/%s-%s", glideDir, OS(), Arch())
currentPath := os.Getenv("PATH")
newPath := fmt.Sprintf("%s:%s", cmdPath, currentPath)
log.Infof("Setting PATH to %s", newPath)
os.Setenv("PATH", newPath)

t := bt.spec.InstallTarget
cmdPath := filepath.Join(glideDir, fmt.Sprintf("%s-%s", OS(), Arch()))

t.PrependToPath(cmdPath)

return nil
}
Expand All @@ -74,7 +73,7 @@ func (bt GlideBuildTool) Install() error {
}

log.Infof("Downloading from URL %s ...", downloadUrl)
localFile, err := DownloadFileWithCache(downloadUrl)
localFile, err := bt.spec.InstallTarget.DownloadFile(downloadUrl)
if err != nil {
log.Errorf("Unable to download: %v", err)
return err
Expand All @@ -83,7 +82,7 @@ func (bt GlideBuildTool) Install() error {
extractDir := bt.GlideDir()
MkdirAsNeeded(extractDir)
log.Infof("Extracting glide %s to %s...", bt.Version(), extractDir)
err = archiver.Unarchive(localFile, extractDir)
err = bt.spec.InstallTarget.Unarchive(localFile, extractDir)
if err != nil {
log.Errorf("Unable to decompress: %v", err)
return err
Expand Down
Loading

0 comments on commit f6ce924

Please sign in to comment.