Shinichiro Hamaji | b69bf8a | 2015-06-10 14:52:06 +0900 | [diff] [blame^] | 1 | // 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 Hamaji | 1eb7111 | 2015-04-29 02:08:52 +0900 | [diff] [blame] | 15 | package main |
| 16 | |
| 17 | import "fmt" |
| 18 | |
| 19 | func 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 Hamaji | 8e4dd9d | 2015-05-15 00:04:44 +0900 | [diff] [blame] | 30 | showDeps(d, indent+1, seen) |
Shinichiro Hamaji | 1eb7111 | 2015-04-29 02:08:52 +0900 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | |
| 34 | func 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 | |
| 61 | func 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 Hamaji | 34715d2 | 2015-05-29 15:26:37 +0900 | [diff] [blame] | 70 | func 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 Hamaji | 7e3ec86 | 2015-04-29 02:11:55 +0900 | [diff] [blame] | 78 | if q == "$*" { |
Shinichiro Hamaji | 34715d2 | 2015-05-29 15:26:37 +0900 | [diff] [blame] | 79 | for k, v := range g.vars { |
Shinichiro Hamaji | 7e3ec86 | 2015-04-29 02:11:55 +0900 | [diff] [blame] | 80 | fmt.Printf("%s=%s\n", k, v.String()) |
| 81 | } |
| 82 | return |
| 83 | } |
| 84 | |
Shinichiro Hamaji | 1eb7111 | 2015-04-29 02:08:52 +0900 | [diff] [blame] | 85 | if q == "*" { |
Shinichiro Hamaji | 34715d2 | 2015-05-29 15:26:37 +0900 | [diff] [blame] | 86 | for _, n := range g.nodes { |
Shinichiro Hamaji | 1eb7111 | 2015-04-29 02:08:52 +0900 | [diff] [blame] | 87 | fmt.Printf("%s\n", n.Output) |
| 88 | } |
| 89 | return |
| 90 | } |
Shinichiro Hamaji | 34715d2 | 2015-05-29 15:26:37 +0900 | [diff] [blame] | 91 | HandleNodeQuery(q, g.nodes) |
Shinichiro Hamaji | 1eb7111 | 2015-04-29 02:08:52 +0900 | [diff] [blame] | 92 | } |