Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: mojom/generators/go/go_generator.go

Issue 2091493002: Switch to the new go generator in the mojo tree. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Update names as suggested. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojom/generators/common/cli.go ('k') | mojom/generators/go/templates/templates.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "flag"
8 "log" 9 "log"
9 "os" 10 "os"
10 "path/filepath" 11 "path/filepath"
11 12
12 "mojom/generators/common" 13 "mojom/generators/common"
13 "mojom/generators/go/templates" 14 "mojom/generators/go/templates"
14 "mojom/generators/go/translator" 15 "mojom/generators/go/translator"
15 ) 16 )
16 17
17 func main() { 18 func main() {
18 log.SetFlags(0) 19 log.SetFlags(0)
19 » config := common.GetCliConfig(os.Args) 20 » flagSet := flag.NewFlagSet("Generator Go Flag Set", flag.ExitOnError)
21 » var noGoSrc bool
22 » flagSet.BoolVar(&noGoSrc, "no-go-src", false, "Do not prepend the output path with go/src.")
23
24 » config := common.GetCliConfigWithFlagSet(os.Args, flagSet)
20 t := translator.NewTranslator(config.FileGraph()) 25 t := translator.NewTranslator(config.FileGraph())
21 » goConfig := goConfig{config, t} 26 » goConfig := goConfig{config, t, noGoSrc}
27 » t.Config = goConfig
22 common.GenerateOutput(WriteGoFile, goConfig) 28 common.GenerateOutput(WriteGoFile, goConfig)
23 } 29 }
24 30
25 type goConfig struct { 31 type goConfig struct {
26 common.GeneratorConfig 32 common.GeneratorConfig
27 translator translator.Translator 33 translator translator.Translator
34 noGoSrc bool
28 } 35 }
29 36
30 func (c goConfig) OutputDir() string { 37 func (c goConfig) OutputDir() string {
31 » return filepath.Join(c.GeneratorConfig.OutputDir(), "go", "src") 38 » if c.noGoSrc {
39 » » return c.GeneratorConfig.OutputDir()
40 » } else {
41 » » return filepath.Join(c.GeneratorConfig.OutputDir(), "go", "src")
42 » }
32 } 43 }
33 44
34 func WriteGoFile(fileName string, config common.GeneratorConfig) { 45 func WriteGoFile(fileName string, config common.GeneratorConfig) {
35 writer := common.OutputWriterByFilePath(fileName, config, ".mojom.go") 46 writer := common.OutputWriterByFilePath(fileName, config, ".mojom.go")
36 goConfig := config.(goConfig) 47 goConfig := config.(goConfig)
37 fileTmpl := goConfig.translator.TranslateMojomFile(fileName) 48 fileTmpl := goConfig.translator.TranslateMojomFile(fileName)
38 writer.WriteString(templates.ExecuteTemplates(fileTmpl)) 49 writer.WriteString(templates.ExecuteTemplates(fileTmpl))
39 } 50 }
OLDNEW
« no previous file with comments | « mojom/generators/common/cli.go ('k') | mojom/generators/go/templates/templates.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698