Skip to content

Commit 8f8cef3

Browse files
authored
Merge pull request swiftlang#51 from ddunbar/mkdir-must-follow
[BuildSystem] Allow inputs for Mkdir/Symlink.
2 parents b90c30c + c3f7e57 commit 8f8cef3

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

docs/buildsystem.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ tracking. This tool should be used when clients only care about the existence of
307307
the directory, not any other aspects of it. In particular, it ignores changes to
308308
the directory timestamp when consider whether to run.
309309

310-
No attributes are supported other than the common keys. No inputs may be
311-
declared, and the sole output should be the node for the path to create.
310+
No attributes are supported other than the common keys. The sole output should
311+
be the node for the path to create. Arbitrary inputs can be declared, but they
312+
will only be used to establish the order in which the command is run.
312313

313314
Symlink Tool
314315
------------
@@ -325,6 +326,10 @@ it will retrieve the status information of the target, not the link itself. This
325326
may lead to unnecessary recreation of the link (and triggering of subsequent
326327
work).
327328

329+
The sole output should be the node for the path to create. Arbitrary inputs can
330+
be declared, but they will only be used to establish the order in which the
331+
command is run.
332+
328333
.. note::
329334

330335
The issue here may be encountered by any other tool which needs to create

lib/BuildSystem/BuildSystem.cpp

+46-4
Original file line numberDiff line numberDiff line change
@@ -1403,8 +1403,17 @@ class MkdirCommand : public Command {
14031403
// FIXME: This seems wasteful.
14041404
std::string description;
14051405

1406+
/// Declared command inputs, used only for ordering purposes.
1407+
std::vector<BuildNode*> inputs;
1408+
14061409
virtual uint64_t getSignature() {
1407-
return basic::hashString(output->getName());
1410+
// FIXME: Use a more appropriate hashing infrastructure.
1411+
using llvm::hash_combine;
1412+
llvm::hash_code code = hash_value(output->getName());
1413+
for (const auto* input: inputs) {
1414+
code = hash_combine(code, input->getName());
1415+
}
1416+
return size_t(code);
14081417
}
14091418

14101419
virtual void configureDescription(const ConfigureContext&,
@@ -1429,7 +1438,10 @@ class MkdirCommand : public Command {
14291438

14301439
virtual void configureInputs(const ConfigureContext& ctx,
14311440
const std::vector<Node*>& value) override {
1432-
ctx.error("unexpected explicit input: '" + value[0]->getName() + "'");
1441+
inputs.reserve(value.size());
1442+
for (auto* node: value) {
1443+
inputs.emplace_back(static_cast<BuildNode*>(node));
1444+
}
14331445
}
14341446

14351447
virtual void configureOutputs(const ConfigureContext& ctx,
@@ -1511,6 +1523,15 @@ class MkdirCommand : public Command {
15111523

15121524
// Eventually we would like to use the system itself to manage recursive
15131525
// directory creation.
1526+
1527+
// The command itself takes no inputs, so just treat any declared inputs as
1528+
// "must follow" directives.
1529+
//
1530+
// FIXME: We should make this explicit once we have actual support for must
1531+
// follow inputs.
1532+
for (auto it = inputs.begin(), ie = inputs.end(); it != ie; ++it) {
1533+
bsci.taskMustFollow(task, BuildKey::makeNode(*it));
1534+
}
15141535
}
15151536

15161537
virtual void providePriorValue(BuildSystemCommandInterface&, core::Task*,
@@ -1613,11 +1634,20 @@ class SymlinkCommand : public Command {
16131634
/// The command description.
16141635
std::string description;
16151636

1637+
/// Declared command inputs, used only for ordering purposes.
1638+
std::vector<BuildNode*> inputs;
1639+
16161640
/// The contents to write at the output path.
16171641
std::string contents;
16181642

16191643
virtual uint64_t getSignature() {
1620-
return basic::hashString(output->getName()) ^ basic::hashString(contents);
1644+
using llvm::hash_combine;
1645+
llvm::hash_code code = hash_value(output->getName());
1646+
code = hash_combine(code, contents);
1647+
for (const auto* input: inputs) {
1648+
code = hash_combine(code, input->getName());
1649+
}
1650+
return size_t(code);
16211651
}
16221652

16231653
virtual void configureDescription(const ConfigureContext&,
@@ -1642,7 +1672,10 @@ class SymlinkCommand : public Command {
16421672

16431673
virtual void configureInputs(const ConfigureContext& ctx,
16441674
const std::vector<Node*>& value) override {
1645-
ctx.error("unexpected explicit input: '" + value[0]->getName() + "'");
1675+
inputs.reserve(value.size());
1676+
for (auto* node: value) {
1677+
inputs.emplace_back(static_cast<BuildNode*>(node));
1678+
}
16461679
}
16471680

16481681
virtual void configureOutputs(const ConfigureContext& ctx,
@@ -1715,6 +1748,15 @@ class SymlinkCommand : public Command {
17151748
core::Task* task) override {
17161749
// Notify the client the command is preparing to run.
17171750
bsci.getDelegate().commandPreparing(this);
1751+
1752+
// The command itself takes no inputs, so just treat any declared inputs as
1753+
// "must follow" directives.
1754+
//
1755+
// FIXME: We should make this explicit once we have actual support for must
1756+
// follow inputs.
1757+
for (auto it = inputs.begin(), ie = inputs.end(); it != ie; ++it) {
1758+
bsci.taskMustFollow(task, BuildKey::makeNode(*it));
1759+
}
17181760
}
17191761

17201762
virtual void providePriorValue(BuildSystemCommandInterface&, core::Task*,

tests/BuildSystem/Build/mkdir.llbuild

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# RUN: %{llbuild} buildsystem build --serial --chdir %t.build > %t.out
77
# RUN: %{FileCheck} --input-file=%t.out %s
88
#
9+
# CHECK: ECHO
910
# CHECK: MKDIR
1011
# CHECK: MUTATE
1112

@@ -43,9 +44,15 @@ commands:
4344
tool: phony
4445
inputs: ["subdir/subdir2/thing.txt"]
4546
outputs: ["<all>"]
47+
C.echo:
48+
tool: shell
49+
description: ECHO
50+
outputs: ["<echo>"]
51+
args: echo hi
4652
C.mkdir:
4753
tool: mkdir
4854
description: MKDIR
55+
inputs: ["<echo>"]
4956
outputs: ["subdir/subdir2"]
5057
C.mutate:
5158
tool: shell

0 commit comments

Comments
 (0)