summaryrefslogtreecommitdiffstats
path: root/tools/gn/builder_record.cc
blob: 066b1ea8030cb2cfdd3a207897936d4b44a1073e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2013 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.

#include "tools/gn/builder_record.h"

#include "tools/gn/item.h"

BuilderRecord::BuilderRecord(ItemType type, const Label& label)
    : type_(type),
      label_(label),
      originally_referenced_from_(NULL),
      should_generate_(false),
      resolved_(false) {
}

BuilderRecord::~BuilderRecord() {
}

// static
const char* BuilderRecord::GetNameForType(ItemType type) {
  switch (type) {
    case ITEM_TARGET:
      return "target";
    case ITEM_CONFIG:
      return "config";
    case ITEM_TOOLCHAIN:
      return "toolchain";
    case ITEM_UNKNOWN:
    default:
      return "unknown";
  }
}

// static
bool BuilderRecord::IsItemOfType(const Item* item, ItemType type) {
  switch (type) {
    case ITEM_TARGET:
      return !!item->AsTarget();
    case ITEM_CONFIG:
      return !!item->AsConfig();
    case ITEM_TOOLCHAIN:
      return !!item->AsToolchain();
    case ITEM_UNKNOWN:
    default:
      return false;
  }
}

// static
BuilderRecord::ItemType BuilderRecord::TypeOfItem(const Item* item) {
  if (item->AsTarget())
    return ITEM_TARGET;
  if (item->AsConfig())
    return ITEM_CONFIG;
  if (item->AsToolchain())
    return ITEM_TOOLCHAIN;

  NOTREACHED();
  return ITEM_UNKNOWN;
}

void BuilderRecord::AddDep(BuilderRecord* record) {
  all_deps_.insert(record);
  if (!record->resolved()) {
    unresolved_deps_.insert(record);
    record->waiting_on_resolution_.insert(this);
  }
}