blob: 7a09ff9001ee21e291f0c04c567e8879fffb9486 [file] [log] [blame]
Shinichiro Hamajib69bf8a2015-06-10 14:52:06 +09001// Copyright 2015 Google Inc. All rights reserved
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Shinichiro Hamaji1eb71112015-04-29 02:08:52 +090015package main
16
17import "fmt"
18
19func showDeps(n *DepNode, indent int, seen map[string]int) {
20 id, present := seen[n.Output]
21 if !present {
22 id = len(seen)
23 seen[n.Output] = id
24 }
25 fmt.Printf("%*c%s (%d)\n", indent, ' ', n.Output, id)
26 if present {
27 return
28 }
29 for _, d := range n.Deps {
Shinichiro Hamaji8e4dd9d2015-05-15 00:04:44 +090030 showDeps(d, indent+1, seen)
Shinichiro Hamaji1eb71112015-04-29 02:08:52 +090031 }
32}
33
34func showNode(n *DepNode) {
35 fmt.Printf("%s:", n.Output)
36 for _, i := range n.ActualInputs {
37 fmt.Printf(" %s", i)
38 }
39 fmt.Printf("\n")
40 for _, c := range n.Cmds {
41 fmt.Printf("\t%s\n", c)
42 }
43 for k, v := range n.TargetSpecificVars {
44 fmt.Printf("%s: %s=%s\n", n.Output, k, v.String())
45 }
46
47 fmt.Printf("\n")
48 fmt.Printf("location: %s:%d\n", n.Filename, n.Lineno)
49 if n.IsOrderOnly {
50 fmt.Printf("order-only: true\n")
51 }
52 if n.IsPhony {
53 fmt.Printf("phony: true\n")
54 }
55
56 seen := make(map[string]int)
57 fmt.Printf("dependencies:\n")
58 showDeps(n, 1, seen)
59}
60
61func HandleNodeQuery(q string, nodes []*DepNode) {
62 for _, n := range nodes {
63 if n.Output == q {
64 showNode(n)
65 break
66 }
67 }
68}
69
Shinichiro Hamaji34715d22015-05-29 15:26:37 +090070func HandleQuery(q string, g *DepGraph) {
71 if q == "$MAKEFILE_LIST" {
72 for _, mk := range g.readMks {
73 fmt.Printf("%s: state=%d\n", mk.Filename, mk.State)
74 }
75 return
76 }
77
Shinichiro Hamaji7e3ec862015-04-29 02:11:55 +090078 if q == "$*" {
Shinichiro Hamaji34715d22015-05-29 15:26:37 +090079 for k, v := range g.vars {
Shinichiro Hamaji7e3ec862015-04-29 02:11:55 +090080 fmt.Printf("%s=%s\n", k, v.String())
81 }
82 return
83 }
84
Shinichiro Hamaji1eb71112015-04-29 02:08:52 +090085 if q == "*" {
Shinichiro Hamaji34715d22015-05-29 15:26:37 +090086 for _, n := range g.nodes {
Shinichiro Hamaji1eb71112015-04-29 02:08:52 +090087 fmt.Printf("%s\n", n.Output)
88 }
89 return
90 }
Shinichiro Hamaji34715d22015-05-29 15:26:37 +090091 HandleNodeQuery(q, g.nodes)
Shinichiro Hamaji1eb71112015-04-29 02:08:52 +090092}