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

Side by Side Diff: mojom/mojom_parser/generators/deps/deps_generator.go

Issue 1737143003: A mojom .d generator. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Update sha1. Created 4 years, 9 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/mojom_parser/generators/common/util_test.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package main
6
7 // deps_generator.go implements the main function of the deps generator.
8 // The deps generator generates .d files. The syntax is that which is used to
9 // specify dependencies in makefiles.
10
11 import (
12 "log"
13 "os"
14 "path"
15 "path/filepath"
16
17 "mojom/mojom_parser/generators/common"
18 )
19
20 func main() {
21 config := common.GetCliConfig(os.Args)
22 common.GenerateOutput(WriteDepsFile, config)
23 }
24
25 // WriteDepsFile writes a .d file for the specified file.
26 func WriteDepsFile(fileName string, config common.GeneratorConfig) {
27 writer := common.OutputWriterByFilePath(fileName, config, ".d")
28 dFileName := fileName[:len(fileName)-len(filepath.Ext(fileName))] + ".d"
29 writer.WriteString(path.Base(dFileName))
30 writer.WriteString(" : ")
31
32 imports := GetTransitiveClosure(fileName, config)
33 for _, imported := range imports {
34 writer.WriteString(imported)
35 writer.WriteString(" ")
36 }
37 writer.WriteString("\n")
38 }
39
40 // GetTransitiveClosure gets the list of transitive imports starting with
41 // rootFile. rootFile itself is not included.
42 // The imports are specified as paths relative to the directory in which
43 // rootFile is found.
44 func GetTransitiveClosure(rootFile string, config common.GeneratorConfig) (resul t []string) {
45 fileGraph := config.FileGraph()
46 toVisit := []string{rootFile}
47 rootFileDir := path.Dir(rootFile)
48
49 for len(toVisit) > 0 {
50 curFileName := toVisit[len(toVisit)-1]
51 toVisit = toVisit[1:len(toVisit)]
52
53 curFile := fileGraph.Files[curFileName]
54 rel, err := filepath.Rel(rootFileDir, curFileName)
55 if err != nil {
56 log.Fatalln(err.Error())
57 }
58 result = append(result, rel)
59
60 if curFile.Imports != nil {
61 for _, importFileName := range *curFile.Imports {
62 toVisit = append(toVisit, importFileName)
63 }
64 }
65 }
66 return
67 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/generators/common/util_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698