-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
92 lines (76 loc) · 2.18 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"fmt"
"log"
"path/filepath"
"github.com/spf13/cobra"
)
// Environment specifies a execution environment for project generators.
type Environment struct {
OutDir string
ProjectFileDir string
Tags []string
}
func generateNinja(manifestFile string, ninjaFile string, tags []string) {
graph, err := parseGraph(manifestFile)
if err != nil {
log.Fatalln("error:", err)
}
env := &Environment{
OutDir: "out",
ProjectFileDir: filepath.Dir(ninjaFile),
Tags: tags,
}
generator := &NinjaGenerator{}
generator.Generate(env, graph)
err = generator.WriteFile(ninjaFile)
if err != nil {
log.Fatalln("error:", err)
}
fmt.Println("Generate", ninjaFile)
}
func generateMSBuild(manifestFile, outputGenDir string) {
graph, err := parseGraph(manifestFile)
if err != nil {
log.Fatalln("error:", err)
}
env := &Environment{
OutDir: "out",
ProjectFileDir: outputGenDir,
}
generator := &MSBuildGenerator{}
generator.Generate(env, graph)
err = generator.WriteFile(env)
if err != nil {
log.Fatalln("error:", err)
}
}
func main() {
var manifestFile string
var outputNinjaFile string
var outputGenDir string
var tags []string
var ninjaCmd = &cobra.Command{
Use: "ninja",
Short: "Generate ninja file",
Long: `Ganerate ninja file.`,
Run: func(cmd *cobra.Command, args []string) {
generateNinja(manifestFile, outputNinjaFile, tags)
},
}
ninjaCmd.Flags().StringArrayVarP(&tags, "tag", "t", tags, "specify tags")
ninjaCmd.Flags().StringVarP(&outputNinjaFile, "file", "f", "build.ninja", "specify a output ninja file")
var msbuildCmd = &cobra.Command{
Use: "msbuild",
Short: "Generate Visual Studio projects",
Long: `Ganerate Visual Studio solution and project files.`,
Run: func(cmd *cobra.Command, args []string) {
generateMSBuild(manifestFile, outputGenDir)
},
}
msbuildCmd.Flags().StringVarP(&outputGenDir, "gen-dir", "g", "out", "specify a directory for generated project files")
var rootCmd = &cobra.Command{Use: "baselard"}
rootCmd.PersistentFlags().StringVarP(&manifestFile, "input", "i", "", "specify a manifest file")
rootCmd.AddCommand(ninjaCmd, msbuildCmd)
rootCmd.Execute()
}