Shinichiro Hamaji | 1eb7111 | 2015-04-29 02:08:52 +0900 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import "fmt" |
| 4 | |
| 5 | func showDeps(n *DepNode, indent int, seen map[string]int) { |
| 6 | id, present := seen[n.Output] |
| 7 | if !present { |
| 8 | id = len(seen) |
| 9 | seen[n.Output] = id |
| 10 | } |
| 11 | fmt.Printf("%*c%s (%d)\n", indent, ' ', n.Output, id) |
| 12 | if present { |
| 13 | return |
| 14 | } |
| 15 | for _, d := range n.Deps { |
Shinichiro Hamaji | 8e4dd9d | 2015-05-15 00:04:44 +0900 | [diff] [blame] | 16 | showDeps(d, indent+1, seen) |
Shinichiro Hamaji | 1eb7111 | 2015-04-29 02:08:52 +0900 | [diff] [blame] | 17 | } |
| 18 | } |
| 19 | |
| 20 | func showNode(n *DepNode) { |
| 21 | fmt.Printf("%s:", n.Output) |
| 22 | for _, i := range n.ActualInputs { |
| 23 | fmt.Printf(" %s", i) |
| 24 | } |
| 25 | fmt.Printf("\n") |
| 26 | for _, c := range n.Cmds { |
| 27 | fmt.Printf("\t%s\n", c) |
| 28 | } |
| 29 | for k, v := range n.TargetSpecificVars { |
| 30 | fmt.Printf("%s: %s=%s\n", n.Output, k, v.String()) |
| 31 | } |
| 32 | |
| 33 | fmt.Printf("\n") |
| 34 | fmt.Printf("location: %s:%d\n", n.Filename, n.Lineno) |
| 35 | if n.IsOrderOnly { |
| 36 | fmt.Printf("order-only: true\n") |
| 37 | } |
| 38 | if n.IsPhony { |
| 39 | fmt.Printf("phony: true\n") |
| 40 | } |
| 41 | |
| 42 | seen := make(map[string]int) |
| 43 | fmt.Printf("dependencies:\n") |
| 44 | showDeps(n, 1, seen) |
| 45 | } |
| 46 | |
| 47 | func HandleNodeQuery(q string, nodes []*DepNode) { |
| 48 | for _, n := range nodes { |
| 49 | if n.Output == q { |
| 50 | showNode(n) |
| 51 | break |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
Shinichiro Hamaji | 34715d2 | 2015-05-29 15:26:37 +0900 | [diff] [blame] | 56 | func HandleQuery(q string, g *DepGraph) { |
| 57 | if q == "$MAKEFILE_LIST" { |
| 58 | for _, mk := range g.readMks { |
| 59 | fmt.Printf("%s: state=%d\n", mk.Filename, mk.State) |
| 60 | } |
| 61 | return |
| 62 | } |
| 63 | |
Shinichiro Hamaji | 7e3ec86 | 2015-04-29 02:11:55 +0900 | [diff] [blame] | 64 | if q == "$*" { |
Shinichiro Hamaji | 34715d2 | 2015-05-29 15:26:37 +0900 | [diff] [blame] | 65 | for k, v := range g.vars { |
Shinichiro Hamaji | 7e3ec86 | 2015-04-29 02:11:55 +0900 | [diff] [blame] | 66 | fmt.Printf("%s=%s\n", k, v.String()) |
| 67 | } |
| 68 | return |
| 69 | } |
| 70 | |
Shinichiro Hamaji | 1eb7111 | 2015-04-29 02:08:52 +0900 | [diff] [blame] | 71 | if q == "*" { |
Shinichiro Hamaji | 34715d2 | 2015-05-29 15:26:37 +0900 | [diff] [blame] | 72 | for _, n := range g.nodes { |
Shinichiro Hamaji | 1eb7111 | 2015-04-29 02:08:52 +0900 | [diff] [blame] | 73 | fmt.Printf("%s\n", n.Output) |
| 74 | } |
| 75 | return |
| 76 | } |
Shinichiro Hamaji | 34715d2 | 2015-05-29 15:26:37 +0900 | [diff] [blame] | 77 | HandleNodeQuery(q, g.nodes) |
Shinichiro Hamaji | 1eb7111 | 2015-04-29 02:08:52 +0900 | [diff] [blame] | 78 | } |