blob: 31053cadb3fbf1f8dd8bd3cbda248704de71e79f [file] [log] [blame]
Shinichiro Hamaji1eb71112015-04-29 02:08:52 +09001package main
2
3import "fmt"
4
5func 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 Hamaji8e4dd9d2015-05-15 00:04:44 +090016 showDeps(d, indent+1, seen)
Shinichiro Hamaji1eb71112015-04-29 02:08:52 +090017 }
18}
19
20func 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
47func 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 Hamaji34715d22015-05-29 15:26:37 +090056func 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 Hamaji7e3ec862015-04-29 02:11:55 +090064 if q == "$*" {
Shinichiro Hamaji34715d22015-05-29 15:26:37 +090065 for k, v := range g.vars {
Shinichiro Hamaji7e3ec862015-04-29 02:11:55 +090066 fmt.Printf("%s=%s\n", k, v.String())
67 }
68 return
69 }
70
Shinichiro Hamaji1eb71112015-04-29 02:08:52 +090071 if q == "*" {
Shinichiro Hamaji34715d22015-05-29 15:26:37 +090072 for _, n := range g.nodes {
Shinichiro Hamaji1eb71112015-04-29 02:08:52 +090073 fmt.Printf("%s\n", n.Output)
74 }
75 return
76 }
Shinichiro Hamaji34715d22015-05-29 15:26:37 +090077 HandleNodeQuery(q, g.nodes)
Shinichiro Hamaji1eb71112015-04-29 02:08:52 +090078}