Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.") | |
|
vardhan
2016/06/24 01:36:07
the solution i had in mind for this was to have a
vardhan
2016/06/24 01:42:19
wait, i misunderstood this flag for something else
azani
2016/06/24 19:21:21
Yes, because the output dir is the same for all th
| |
| 23 | |
| 24 » config := common.GetCustomCliConfig(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} |
| 22 common.GenerateOutput(WriteGoFile, goConfig) | 27 common.GenerateOutput(WriteGoFile, goConfig) |
| 23 } | 28 } |
| 24 | 29 |
| 25 type goConfig struct { | 30 type goConfig struct { |
| 26 common.GeneratorConfig | 31 common.GeneratorConfig |
| 27 translator translator.Translator | 32 translator translator.Translator |
| 33 noGoSrc bool | |
| 28 } | 34 } |
| 29 | 35 |
| 30 func (c goConfig) OutputDir() string { | 36 func (c goConfig) OutputDir() string { |
| 31 » return filepath.Join(c.GeneratorConfig.OutputDir(), "go", "src") | 37 » if c.noGoSrc { |
| 38 » » return c.GeneratorConfig.OutputDir() | |
| 39 » } else { | |
| 40 » » return filepath.Join(c.GeneratorConfig.OutputDir(), "go", "src") | |
| 41 » } | |
| 32 } | 42 } |
| 33 | 43 |
| 34 func WriteGoFile(fileName string, config common.GeneratorConfig) { | 44 func WriteGoFile(fileName string, config common.GeneratorConfig) { |
| 35 writer := common.OutputWriterByFilePath(fileName, config, ".mojom.go") | 45 writer := common.OutputWriterByFilePath(fileName, config, ".mojom.go") |
| 36 goConfig := config.(goConfig) | 46 goConfig := config.(goConfig) |
| 37 fileTmpl := goConfig.translator.TranslateMojomFile(fileName) | 47 fileTmpl := goConfig.translator.TranslateMojomFile(fileName) |
| 38 writer.WriteString(templates.ExecuteTemplates(fileTmpl)) | 48 writer.WriteString(templates.ExecuteTemplates(fileTmpl)) |
| 39 } | 49 } |
| OLD | NEW |