flynn-archive / bake

fast deterministic builds
Other
8 stars 2 forks source link

DSL #3

Closed benbjohnson closed 6 years ago

benbjohnson commented 9 years ago

Overview

The Bakefile language will be built as a simple, Lua DSL. Because Lua does not require parenthesis for methods and table literals can be defined using {...}, we can make a DSL that feels declarative.

The scope of this first cut will simply be to support targets and their execution. For target definition, we'll use a target NAME, { COMMANDS } command at the top level. Inside a target, it can execute commands using the exec CMD command.

Sample

-- GLOBAL VARIABLES
vpkg = "github.com/flynn/flynn/pkg/version"

-- TARGETS
target "host/cli/root_keys.go",  {
    exec "go build -o main.go"
}

target "host/bin/flynn-host", depends("host/cli/root_keys.go"), {
    go(target.name)
}

target "host/bin/flynn-init", {
    go(target.name)
}

target "host/bin/flynn-host.gz", depends("host/bin/flynn-host") {
    exec "gzip -9 --keep bin/flynn-host"
}

target "host/script/install-flynn", depends("host/bin/flynn-host.gz"), {
    exec 'sed "s/{{FLYNN-HOST-CHECKSUM}}/\$(sha512sum bin/flynn-host.gz | cut -d " " -f 1)/g" script/install-flynn.tmpl > ' .. target.name
}

-- FUNCTIONS
function go(output) {
    git = read_git()

    cmd = printf('util/_toolchain/go/bin/go build -o %s', output)
    cmd = cmd .. '-ldflags="'
    cmd = cmd .. string.format('-X %s.commit %s', vpkg, git.commit)
    cmd = cmd .. string.format('-X %s.branch %s', vpkg, git.branch)
    cmd = cmd .. string.format('-X %s.tag %s', vpkg, git.tag)
    cmd = cmd .. string.format('-X %s.dirty %s', vpkg, git.dirty)
    cmd = cmd .. '"'
    cmd = cmd .. string.format('-X %s.tags %s', vpkg, env("GO_BUILD_TAGS"))

    return {
        exec cmd
    }
}
benbjohnson commented 9 years ago

@titanous I added a sample DSL based on Flynn's host/Tupfile. Let me know what you think about the syntax and approach.

titanous commented 9 years ago

This looks great!

benbjohnson commented 9 years ago

Will depends take multiple arguments to declare multiple inputs?

Yes, it'll take 0..n targets that are dependencies.

Will there be some kind of exec argument interpolation? (like Tup's %o, etc)

Yes, I'm debating the interpolation style. The % qualifier means that you only get one character to name the variable (e.g. %o). What about making them like environment variables? e.g. $BAKE_TARGET. Or something with a more template style: e.g. #{TARGET} or {{TARGET}}

go build -o main.go looks wrong

Yep. That was some poor copy-n-pasting. :)

titanous commented 9 years ago

What about making them like environment variables? e.g. $BAKE_TARGET. Or something with a more template style: e.g. #{TARGET} or {{TARGET}}

I like the more explicit style if there are a lot of options. If there are only a small handful, one letter is shorter and fine.