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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojom/mojom_parser/generators/common/util_test.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/mojom_parser/generators/deps/deps_generator.go
diff --git a/mojom/mojom_parser/generators/deps/deps_generator.go b/mojom/mojom_parser/generators/deps/deps_generator.go
new file mode 100644
index 0000000000000000000000000000000000000000..c4744ab97d806a60d5cb061395f48cd8e0461bc2
--- /dev/null
+++ b/mojom/mojom_parser/generators/deps/deps_generator.go
@@ -0,0 +1,67 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package main
+
+// deps_generator.go implements the main function of the deps generator.
+// The deps generator generates .d files. The syntax is that which is used to
+// specify dependencies in makefiles.
+
+import (
+ "log"
+ "os"
+ "path"
+ "path/filepath"
+
+ "mojom/mojom_parser/generators/common"
+)
+
+func main() {
+ config := common.GetCliConfig(os.Args)
+ common.GenerateOutput(WriteDepsFile, config)
+}
+
+// WriteDepsFile writes a .d file for the specified file.
+func WriteDepsFile(fileName string, config common.GeneratorConfig) {
+ writer := common.OutputWriterByFilePath(fileName, config, ".d")
+ dFileName := fileName[:len(fileName)-len(filepath.Ext(fileName))] + ".d"
+ writer.WriteString(path.Base(dFileName))
+ writer.WriteString(" : ")
+
+ imports := GetTransitiveClosure(fileName, config)
+ for _, imported := range imports {
+ writer.WriteString(imported)
+ writer.WriteString(" ")
+ }
+ writer.WriteString("\n")
+}
+
+// GetTransitiveClosure gets the list of transitive imports starting with
+// rootFile. rootFile itself is not included.
+// The imports are specified as paths relative to the directory in which
+// rootFile is found.
+func GetTransitiveClosure(rootFile string, config common.GeneratorConfig) (result []string) {
+ fileGraph := config.FileGraph()
+ toVisit := []string{rootFile}
+ rootFileDir := path.Dir(rootFile)
+
+ for len(toVisit) > 0 {
+ curFileName := toVisit[len(toVisit)-1]
+ toVisit = toVisit[1:len(toVisit)]
+
+ curFile := fileGraph.Files[curFileName]
+ rel, err := filepath.Rel(rootFileDir, curFileName)
+ if err != nil {
+ log.Fatalln(err.Error())
+ }
+ result = append(result, rel)
+
+ if curFile.Imports != nil {
+ for _, importFileName := range *curFile.Imports {
+ toVisit = append(toVisit, importFileName)
+ }
+ }
+ }
+ return
+}
« 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