Commit 7c2d1115 authored by Oscar Campos's avatar Oscar Campos
Browse files

feat: removed Python generation scriopt and move build to Magefile

parent a00ff223
all: clean generate build
rm gdnative/*.gen.* || true
go clean
go generate
go build -x ./gdnative/...
.PHONY: all
// +build ignore
package main
import (
func main() {
import os
import shlex
import subprocess
LOCAL_PATH = os.path.abspath(os.path.dirname(__file__))
DOC_PATH = os.path.join(LOCAL_PATH, '..', 'doc')
# Check if the "doc" folder is present where we can fetch all of the godot
# documentation to include it as Go documentation as part of class generation.
if not os.getenv('NODOC'):
if os.path.exists(DOC_PATH):
print('Godot documentation found. Pulling the latest changes...')
os.chdir(DOC_PATH)'git pull origin master'))
print('Godot documentation not found. Pulling the latest changes...')
cmds = [
'git init',
'git remote add -f origin', # noqa
'git config core.sparseCheckout true',
'echo "doc/classes" >> {}'.format(
os.path.join(DOC_PATH, '.git', 'info', 'sparse-checkout')
'git pull origin master'
for cmd in cmds:
# clean the gdnative directory
print('Cleaning previous generation...')'rm gdnative/*.gen.*'), capture_output=True)
env = os.environ.copy()
env.update({'API_PATH': os.path.join(LOCAL_PATH, '..')})
cmd = 'go run -v {}'.format(os.path.join(LOCAL_PATH, 'generate', 'main.go')), env=env)
......@@ -2,6 +2,7 @@ module
require ( v1.0.0 // indirect v1.9.0 v0.0.0-20160729104318-956b6baf666a v0.0.0-20160320123332-5dd6f4be3f2a
// +build mage
package main
import (
var ldflags = "-s -w"
var Default = Generate
func init() {
// make sure we use Go 1.11 modules even if the source lives inside GOPATH
os.Setenv("GO111MODULE", "on")
// Generate Go Bindings
func Generate() error {
mg.SerialDeps(RetrieveGodotDocumentation, Clean)
apiPath := getCurrentFilePath()
generateScript := filepath.Join(getCurrentFilePath(), "cmd", "generate", "main.go")
err := sh.RunWith(map[string]string{"API_PATH": apiPath}, "go", "run", "-v", generateScript)
if err != nil {
return fmt.Errorf("could not genearate Go bindings: %w", err)
return Build()
// Clean cleans previous generations
func Clean() error {
log.Println("Cleaning previous generation...")
return sh.Rm("./gdnative/*.gen.*")
// RetrieveGodotDocumentation retrieves latest Godot documentation to attach docstrings
func RetrieveGodotDocumentation() error {
localPath := getCurrentFilePath()
docPath := filepath.Join(localPath, "doc")
_, found := os.Stat(docPath)
if found == nil {
log.Println("Godot documentation found. Pulling latest changes...")
if err := sh.Run("git", "pull", "origin", "master"); err != nil {
return fmt.Errorf("could not pull latest Godot documentation from git: %w", err)
return nil
log.Println("Godot documentation not found. Cloning the repository...")
if err := os.MkdirAll(docPath, 0766); err != nil {
return fmt.Errorf("could not create a new directory on the disk: %w", err)
if err := sh.Run("git", "init"); err != nil {
return fmt.Errorf("could not execute git init: %w", err)
if err := sh.Run("git", "remote", "add", "-f", "origin", ""); err != nil {
return fmt.Errorf("could not set origin remote for documentation: %w", err)
if err := sh.Run("git", "config", "core.sparseCheckout", "true"); err != nil {
return fmt.Errorf("could not activate core.sparseCheckout: %w", err)
sparseCheckoutsConfigFile := filepath.Join(".", ".git", "info", "sparse-checkout")
writeErr := ioutil.WriteFile(sparseCheckoutsConfigFile, []byte("doc/classes"), 0655)
if writeErr != nil {
return fmt.Errorf("could not write .git/info/sparse-checkout file: %w", writeErr)
if err := sh.Run("git", "pull", "origin", "master"); err != nil {
return fmt.Errorf("error while pulling: %w", err)
return nil
// Build builds the library to make sure everything is fine
func Build() error {
return sh.Run("go", "build", "-ldflags", ldflags, "-x", "./gdnative...")
// getCurrentFilePath constructs and returns the current file path on the drive
func getCurrentFilePath() string {
_, filename, _, ok := runtime.Caller(0)
if !ok {
log.Fatal("could not get current file path")
return filepath.Join(filepath.Dir(filename))
package main
// Generate the wrapper
//go:generate ./cmd/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment