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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
//===-- BuildNode.cpp -----------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "llbuild/BuildSystem/BuildNode.h"
#include "llbuild/Basic/FileInfo.h"
#include "llbuild/Basic/FileSystem.h"
#include "llbuild/BuildSystem/BuildFile.h"
#include "llbuild/BuildSystem/Command.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Twine.h"
using namespace llbuild;
using namespace llbuild::basic;
using namespace llbuild::buildsystem;
bool BuildNode::configureAttribute(const ConfigureContext& ctx, StringRef name,
StringRef value) {
if (name == "type") {
if (value == "plain") {
type = NodeType::Plain;
} else if (value == "directory") {
type = NodeType::Plain;
} else if (value == "directory-structure") {
type = NodeType::DirectoryStructure;
} else if (value == "virtual") {
type = NodeType::Virtual;
} else {
ctx.error("invalid value: '" + value + "' for attribute '"
+ name + "'");
return false;
}
return true;
} else if (name == "is-directory") { // Note: Deprecated in favor of 'type'.
if (value == "true") {
type = NodeType::Directory;
} else if (value == "false") {
if (type == NodeType::Directory)
type = NodeType::Plain;
} else {
ctx.error("invalid value: '" + value + "' for attribute '"
+ name + "'");
return false;
}
return true;
} else if (name == "is-directory-structure") { // Note: Deprecated in favor of 'type'.
if (value == "true") {
type = NodeType::DirectoryStructure;
} else if (value == "false") {
if (type == NodeType::DirectoryStructure)
type = NodeType::Plain;
} else {
ctx.error("invalid value: '" + value + "' for attribute '"
+ name + "'");
return false;
}
return true;
} else if (name == "is-virtual") { // Note: Deprecated in favor of 'type'.
if (value == "true") {
type = NodeType::Virtual;
} else if (value == "false") {
if (type == NodeType::Virtual)
type = NodeType::Plain;
commandTimestamp = false;
} else {
ctx.error("invalid value: '" + value + "' for attribute '"
+ name + "'");
return false;
}
return true;
} else if (name == "is-command-timestamp") {
if (value == "true") {
commandTimestamp = true;
type = NodeType::Virtual;
} else if (value == "false") {
commandTimestamp = false;
} else {
ctx.error("invalid value: '" + value + "' for attribute '"
+ name + "'");
return false;
}
return true;
} else if (name == "is-mutated") {
if (value == "true") {
mutated = true;
} else if (value == "false") {
mutated = false;
} else {
ctx.error("invalid value: '" + value + "' for attribute '"
+ name + "'");
return false;
}
return true;
} else if (name == "content-exclusion-patterns") {
exclusionPatterns = basic::StringList(value);
return true;
}
// We don't support any other custom attributes.
ctx.error("unexpected attribute: '" + name + "'");
return false;
}
bool BuildNode::configureAttribute(const ConfigureContext& ctx, StringRef name,
ArrayRef<StringRef> values) {
if (name == "content-exclusion-patterns") {
exclusionPatterns = basic::StringList(values);
return true;
} else if (name == "must-scan-after-paths") {
mustScanAfterPaths = basic::StringList(values).getValues();
return true;
}
// We don't support any other custom attributes.
ctx.error("unexpected attribute: '" + name + "'");
return false;
}
bool BuildNode::configureAttribute(
const ConfigureContext& ctx, StringRef name,
ArrayRef<std::pair<StringRef, StringRef>> values) {
// We don't support any other custom attributes.
ctx.error("unexpected attribute: '" + name + "'");
return false;
}
FileInfo BuildNode::getFileInfo(basic::FileSystem& fileSystem) const {
assert(!isVirtual());
// Drop the trailing slash
// otherwise non-directory paths that end with "/" will be reported as missing
StringRef path = getName();
if (path.endswith("/") && path != "/") {
path = path.substr(0, path.size() - 1);
}
return fileSystem.getFileInfo(path);
}
FileInfo BuildNode::getLinkInfo(basic::FileSystem& fileSystem) const {
assert(!isVirtual());
return fileSystem.getLinkInfo(getName());
}
basic::CommandSignature BuildNode::getSignature() const {
basic::CommandSignature sig;
sig.combine(static_cast<unsigned int>(type));
// We include the name of all producer rules in the signature to ensure that
// we properly pick up changes in build graph structure. For example, a node
// that was previously a plain input that has changed to become a produced
// node.
for (auto* producer : getProducers()) {
sig.combine(producer->getName());
}
return sig;
}
FileInfo StatNode::getFileInfo(basic::FileSystem& fileSystem) const {
return fileSystem.getFileInfo(name);
}
FileInfo StatNode::getLinkInfo(basic::FileSystem& fileSystem) const {
return fileSystem.getLinkInfo(name);
}
|