-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
262 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module github.com/maxmcd/bramble | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/maxmcd/tester v0.0.0-20200315004439-02c29039e2ff | ||
github.com/pkg/errors v0.9.1 | ||
go.starlark.net v0.0.0-20200619143648-50ca820fafb9 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= | ||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= | ||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/maxmcd/tester v0.0.0-20200315004439-02c29039e2ff h1:KlEKaOPoMw2EezjcSqxUIMsB88SnbLmjPgl0FSe03bA= | ||
github.com/maxmcd/tester v0.0.0-20200315004439-02c29039e2ff/go.mod h1:Am0GjdS6T4scTzpHRAZWnKNZvmX3BdBzIHqhaEwsV20= | ||
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= | ||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= | ||
go.starlark.net v0.0.0-20200619143648-50ca820fafb9 h1:GXxsgecRXvpdwo8UtXZyEzJww54A+54NaO+86/pBr+c= | ||
go.starlark.net v0.0.0-20200619143648-50ca820fafb9/go.mod h1:7MJ5a3UGvhYDcmDibLTlO6EEOVwPCNVCsthcNTmVbYE= | ||
golang.org/x/sys v0.0.0-20191002063906-3421d5a6bb1c h1:Vco5b+cuG5NNfORVxZy6bYZQ7rsigisU1WQFkvQ0L5E= | ||
golang.org/x/sys v0.0.0-20191002063906-3421d5a6bb1c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/maxmcd/bramble/pkg/bramble" | ||
) | ||
|
||
func main() { | ||
if err := bramble.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
def build_python_package(*args, **kwargs): | ||
pass | ||
|
||
|
||
build_python_package( | ||
pname="numpy", | ||
version="1.18.5", | ||
nativeBuildInputs=["gfortran", "pytest", "cython", "setuptoolsBuildHook"], | ||
buildInputs=["blas", "lapack"], | ||
checkPhase=""" | ||
echo hi | ||
""", | ||
# def build_python_package(*args, **kwargs): | ||
# pass | ||
|
||
|
||
# build_python_package( | ||
# pname="numpy", | ||
# version="1.18.5", | ||
# nativeBuildInputs=["gfortran", "pytest", "cython", "setuptoolsBuildHook"], | ||
# buildInputs=["blas", "lapack"], | ||
# checkPhase=""" | ||
# echo hi | ||
# """, | ||
# ) | ||
|
||
|
||
build( | ||
name="bootstrap-tools", | ||
builder="fetch_url", | ||
environment={ | ||
"url": "http://tarballs.nixos.org/stdenv-linux/x86_64/c5aabb0d603e2c1ea05f5a93b3be82437f5ebf31/bootstrap-tools.tar.xz", | ||
"hash": "a5ce9c155ed09397614646c9717fc7cd94b1023d7b76b618d409e4fefd6e9d39", | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package bramble | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/maxmcd/tester" | ||
"github.com/pkg/errors" | ||
"go.starlark.net/starlark" | ||
) | ||
|
||
func Run() (err error) { | ||
thread := &starlark.Thread{Name: ""} | ||
globals, err := starlark.ExecFile(thread, os.Args[1], nil, starlark.StringDict{ | ||
"load": starlark.NewBuiltin("load", StarlarkLoad), | ||
"build": starlark.NewBuiltin("build", StarlarkBuild), | ||
}) | ||
if err != nil { | ||
return | ||
} | ||
fmt.Println(globals) | ||
return | ||
// main := globals["main"] | ||
// _, err = starlark.Call(thread, main, starlark.Tuple{}, nil) | ||
// if err != nil { | ||
// if er, ok := err.(*starlark.EvalError); ok { | ||
// fmt.Println(er.Backtrace()) | ||
// } | ||
// return | ||
// } | ||
// return | ||
} | ||
|
||
func StarlarkLoad(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (v starlark.Value, err error) { | ||
return | ||
} | ||
|
||
type Build struct { | ||
Name string | ||
Outputs []Output | ||
Builder string | ||
Platform string | ||
Args []string | ||
Environment map[string]string | ||
} | ||
|
||
type Output struct { | ||
Name string | ||
Path string | ||
HashAlgorithm string | ||
Hash string | ||
} | ||
|
||
type typeError struct { | ||
funcName string | ||
argument string | ||
wantedType string | ||
} | ||
|
||
func (te typeError) Error() string { | ||
return fmt.Sprintf("%s() keyword argument '%s' must be of type '%s'", te.funcName, te.argument, te.wantedType) | ||
} | ||
|
||
func newBuildFromKWArgs(kwargs []starlark.Tuple) (build Build, err error) { | ||
te := typeError{ | ||
funcName: "build", | ||
} | ||
for _, kwarg := range kwargs { | ||
key := kwarg.Index(0).(starlark.String).GoString() | ||
value := kwarg.Index(1) | ||
switch key { | ||
case "name": | ||
name, ok := value.(starlark.String) | ||
if !ok { | ||
te.argument = "name" | ||
te.wantedType = "string" | ||
return build, te | ||
} | ||
build.Name = name.GoString() | ||
case "builder": | ||
name, ok := value.(starlark.String) | ||
if !ok { | ||
te.argument = "builder" | ||
te.wantedType = "string" | ||
return build, te | ||
} | ||
build.Builder = name.GoString() | ||
case "args": | ||
case "environment": | ||
build.Environment, err = valueToStringMap(value, "build", "environment") | ||
if err != nil { | ||
return | ||
} | ||
default: | ||
err = errors.Errorf("build() got an unexpected keyword argument '%s'", key) | ||
return | ||
} | ||
} | ||
return build, nil | ||
} | ||
|
||
func valueToStringMap(val starlark.Value, function, param string) (out map[string]string, err error) { | ||
out = map[string]string{} | ||
maybeErr := errors.Errorf( | ||
"%s parameter '%s' expects type 'dict' instead got '%s'", | ||
function, param, val.String()) | ||
if val.Type() != "dict" { | ||
err = maybeErr | ||
return | ||
} | ||
dict, ok := val.(starlark.IterableMapping) | ||
if !ok { | ||
err = maybeErr | ||
return | ||
} | ||
items := dict.Items() | ||
for _, item := range items { | ||
key := item.Index(0) | ||
value := item.Index(1) | ||
ks, ok := key.(starlark.String) | ||
if !ok { | ||
err = errors.Errorf("%s %s expects a dictionary of strings, but got value %s", function, param, key.String()) | ||
return | ||
} | ||
vs, ok := value.(starlark.String) | ||
if !ok { | ||
err = errors.Errorf("%s %s expects a dictionary of strings, but got value %s", function, param, value.String()) | ||
return | ||
} | ||
out[ks.GoString()] = vs.GoString() | ||
} | ||
return | ||
} | ||
|
||
func StarlarkBuild(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (v starlark.Value, err error) { | ||
if args.Len() > 0 { | ||
return nil, errors.New("builtin function build() takes no positional arguments") | ||
} | ||
build, err := newBuildFromKWArgs(kwargs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
tester.Print(build) | ||
return starlark.None, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters