Skip to content

Commit c3c2761

Browse files
authored
Merge pull request swiftlang#50 from ddunbar/libllbuild-get-signature
[libllbuild] Allow clients to supply custom command signatures.
2 parents 329ef74 + eee39bb commit c3c2761

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

examples/c-api/buildsystem/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static llb_buildsystem_command_t*
5252
fancy_tool_create_command(void *context, const llb_data_t* name) {
5353
llb_buildsystem_external_command_delegate_t delegate;
5454
delegate.context = NULL;
55+
delegate.get_signature = NULL;
5556
delegate.execute_command = fancy_command_execute_command;
5657
return llb_buildsystem_external_command_create(name, delegate);
5758
}

products/libllbuild/BuildSystem-C-API.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llbuild/BuildSystem/ExternalCommand.h"
2121
#include "llbuild/Core/BuildEngine.h"
2222

23+
#include "llvm/ADT/Hashing.h"
2324
#include "llvm/ADT/SmallString.h"
2425
#include "llvm/Support/SourceMgr.h"
2526
#include "llvm/Support/raw_ostream.h"
@@ -409,6 +410,24 @@ class CAPIExternalCommand : public ExternalCommand {
409410
// FIXME: Provide client control.
410411
llvm::raw_svector_ostream(result) << getName();
411412
}
413+
414+
virtual uint64_t getSignature() override {
415+
// FIXME: Use a more appropriate hashing infrastructure.
416+
using llvm::hash_combine;
417+
llvm::hash_code code = ExternalCommand::getSignature();
418+
if (cAPIDelegate.get_signature) {
419+
llb_data_t data;
420+
cAPIDelegate.get_signature(cAPIDelegate.context, (llb_buildsystem_command_t*)this,
421+
&data);
422+
code = hash_combine(code, StringRef((const char*)data.data, data.length));
423+
424+
// Release the client memory.
425+
//
426+
// FIXME: This is gross, come up with a general purpose solution.
427+
free((char*)data.data);
428+
}
429+
return size_t(code);
430+
}
412431
};
413432

414433
}

products/libllbuild/public-api/llbuild/buildsystem.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,19 @@ typedef struct llb_buildsystem_external_command_delegate_t_ {
371371
/// User context pointer.
372372
void* context;
373373

374+
/// Called to get a signature which represents the internal state of the
375+
/// command which is not tracked by any other attribute visible to the build
376+
/// system (for example, a declared input or output). This signature is
377+
/// compared with previous executions of the command when determining whether
378+
/// or not it needs to rerun.
379+
///
380+
/// The contents *MUST* be returned in a new buffer allocated with \see
381+
/// malloc().
382+
//
383+
// FIXME: We need to use a better data type than a uint64_t here.
384+
void (*get_signature)(void* context, llb_buildsystem_command_t* command,
385+
llb_data_t* data_out);
386+
374387
/// Called by the build system's execution queue after the command's inputs
375388
/// are available and the execution queue is ready to schedule the command.
376389
///

0 commit comments

Comments
 (0)