Skip to content

Commit

Permalink
generating lua bindings - still failing
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Courtine <[email protected]>
  • Loading branch information
michakfromparis committed Jan 14, 2019
1 parent 47f6173 commit b9bf57d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 41 deletions.
2 changes: 1 addition & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func build(cmd *cobra.Command, args []string) {
platform.SetEnabledPlatforms(enabledPlatforms)
configuration.SetEnabledConfigurations(enabledConfigurations)
sparks.Init()
sparks.Build(args[0])
sparks.Build(args[0], config.OutputDirectory)
sparks.Shutdown()
}

Expand Down
13 changes: 10 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package cmd

import (
log "github.com/Sirupsen/logrus"
"github.com/michaKFromParis/sparks/config"
"github.com/michaKFromParis/sparks/logger"
"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "sparks",
Short: "command line interface to the sparks framework",
PersistentPreRun: PreRunAllCommands,
Use: "sparks",
Short: "command line interface to the sparks framework",
Long: `
Sparks command line interface`,
}
Expand All @@ -22,6 +25,10 @@ func Init() {
init_build()
}

func PreRunAllCommands(cmd *cobra.Command, args []string) {
logger.Init()
}

func Execute() error {
rootCmd.SilenceErrors = true
if err := rootCmd.Execute(); err != nil {
Expand All @@ -33,5 +40,5 @@ func Execute() error {
func init_root() {
log.Trace("root init")
rootCmd.Flags().SortFlags = false
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose log level. One of (panic, fatal, error, warning, debug, trace)")
rootCmd.PersistentFlags().BoolVarP(&config.Verbose, "verbose", "v", false, "verbose log level. One of (panic, fatal, error, warning, debug, trace)")
}
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
var SourceDirectory string
var OutputDirectory string
var SDKDirectory string
var SDKName string
var ProductName string
var Debug = false
var Release = false
Expand All @@ -22,7 +23,8 @@ var Verbose = false

func Init() error {
log.Info("initializing config")
ProductName = "Sparks"
SDKName = "Sparks"
ProductName = "SparksPlayer"

var err error
if SourceDirectory, err = utils.Pwd(); err != nil {
Expand Down
8 changes: 7 additions & 1 deletion logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ func Init() {
FieldsOrder: []string{"component", "category"},
TimestampFormat: "15:04:05",
})
log.SetLevel(log.TraceLevel)
log.SetOutput(os.Stdout)

log.SetLevel(log.TraceLevel)

// if config.Verbose {
// log.SetLevel(log.TraceLevel)
// } else {
// log.SetLevel(log.InfoLevel)
// }
log.Infof("initialized logger at level %s", log.GetLevel().String())
// log.Trace("Trace Sample")
// log.Debug("Debug Sample")
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"github.com/michaKFromParis/sparks/cmd"
"github.com/michaKFromParis/sparks/configuration"
"github.com/michaKFromParis/sparks/errx"
"github.com/michaKFromParis/sparks/logger"
"github.com/michaKFromParis/sparks/platform"
)

func main() {
logger.Init()
// logger.Init()
platform.RegisterPlatforms()
configuration.RegisterConfigurations()
cmd.Init()
Expand Down
6 changes: 3 additions & 3 deletions sparks/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ type Product struct {
func (p *Product) Load() error {
filename := p.findSparksFile()
log.Debug("loading product from " + filename)
yamlFile, err := ioutil.ReadFile(filename)
bytes, err := ioutil.ReadFile(filename)
if err != nil {
errx.Fatalf(err, "Could not read: "+filename)
}
err = yaml.Unmarshal(yamlFile, p)
err = yaml.Unmarshal(bytes, p)
if err != nil {
errx.Fatalf(err, "yaml reader: "+filename)
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func (p *Product) findSparksFile() string {
}
}
if p.sparksFilename == "" {
errx.Error("Could not find a .sparks file at " + config.SourceDirectory)
errx.Fatalf(nil, "could not find a .sparks file at "+config.SourceDirectory)
}
return p.sparksFilename
}
Expand Down
89 changes: 59 additions & 30 deletions sparks/sparks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sparks

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -32,6 +33,47 @@ func Save() {
log.Info("sparks save")
CurrentProduct.Save()
}

func Build(sourceDirectory string, outputDirectory string) {
log.Info("sparks build " + sourceDirectory)
checkParameters(sourceDirectory, outputDirectory)
Load()
createBuildDirectoryStructure()
sparksSourceDirectory := filepath.Join(config.SDKDirectory, "src", config.SDKName)
generateLuaBindings(sparksSourceDirectory, config.SDKName)
// utils.Sed(filename, regex, newContent)
generateLuaBindings(sparksSourceDirectory, "SparksNetworksLua")
generateLuaBindings(sparksSourceDirectory, config.ProductName)

for _, platformName := range PlatformNames {
platform := Platforms[platformName]
if platform != nil && platform.Enabled() {
for _, configurationName := range ConfigurationNames {
configuration := Configurations[configurationName]
if configuration != nil && configuration.Enabled() {
Load()
platform.Build(configuration)
}
}
}
}
}

func checkParameters(sourceDirectory string, outputDirectory string) { // TODO Check output here
file, err := os.Stat(sourceDirectory)
if err != nil {
errx.Fatalf(err, "could not stat source directory: "+sourceDirectory)
}
if !file.IsDir() {
errx.Fatalf(err, "source directory is not a directory: "+sourceDirectory)
}
config.SourceDirectory = sourceDirectory
config.OutputDirectory = outputDirectory
config.SDKDirectory = sourceDirectory
log.Debugf("SDK Directory: %s", config.SDKDirectory)
log.Debugf("Source Directory: %s", config.SourceDirectory)
}

func createBuildDirectoryStructure() {
log.Trace("creating build/bin, build/lib, build/projects")
var binPath = filepath.Join(config.OutputDirectory, "bin")
Expand All @@ -48,45 +90,32 @@ func createBuildDirectoryStructure() {
}
}

func generateLuaBindings() {
func generateLuaBindings(sourceDirectory string, packageName string) {

log.Info("generating lua bindings for " + packageName)
toluapp := filepath.Join(config.SDKDirectory, "dependencies", "toluapp", "bin")

os, _ := utils.GetOs()
switch os {
case utils.Osx:
toluapp = filepath.Join(toluapp, "toluapp_osx")
case utils.Linux:
toluapp = filepath.Join(toluapp, "toluapp_osx")
case utils.Windows:
toluapp = filepath.Join(toluapp, "tolua++")
case utils.Windows:
toluapp = filepath.Join(toluapp, "toluapp_script.exe")
}
utils.Execute(toluapp)
}

func Build(sourceDirectory string) {
log.Info("sparks build " + sourceDirectory)
file, err := os.Stat(sourceDirectory)
toluaHooksPath := filepath.Join(config.SDKDirectory, "src", "Sparks", "tolua.hooks.lua")
dofileWithCorrectPath := fmt.Sprintf("dofile(\"%s\")%s", toluaHooksPath, utils.LineBreak)
reflectionFile := filepath.Join(sourceDirectory, packageName+".Reflection.lua")
utils.Sed(reflectionFile, "dofile\\(.*\\)", dofileWithCorrectPath)
packagePath := filepath.Join(sourceDirectory, packageName)
out, err := utils.Execute(
toluapp, "-L", packagePath+".Reflection.lua",
"-n", packageName,
"-o", packagePath+".tolua.cpp",
"-H", packagePath+".tolua.h",
packagePath+".pkg")
if err != nil {
errx.Fatalf(err, "could not stat source directory: "+sourceDirectory)
}
if !file.IsDir() {
errx.Fatalf(err, "source directory is not a directory: "+sourceDirectory)
}
config.SourceDirectory = sourceDirectory
config.SDKDirectory = sourceDirectory
Load()
createBuildDirectoryStructure()
generateLuaBindings()
for _, platformName := range PlatformNames {
platform := Platforms[platformName]
if platform != nil && platform.Enabled() {
for _, configurationName := range ConfigurationNames {
configuration := Configurations[configurationName]
if configuration != nil && configuration.Enabled() {
Load()
platform.Build(configuration)
}
}
}
errx.Fatalf(err, "tolua++ execution failed: "+out)
}
}

0 comments on commit b9bf57d

Please sign in to comment.