Skip to content

Commit 0e8334b

Browse files
committed
[libllbuild] Add support for getting command descriptions.
1 parent 6a4af8e commit 0e8334b

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

examples/c-api/buildsystem/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2015 - 2016 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -34,9 +34,12 @@ static const char* basename(const char* path) {
3434

3535
static void command_started(void* context,
3636
llb_buildsystem_command_t* command) {
37+
char* description = llb_buildsystem_command_get_description(command);
3738
llb_data_t name;
3839
llb_buildsystem_command_get_name(command, &name);
39-
printf("%s: %.*s\n", __FUNCTION__, (int)name.length, name.data);
40+
printf("%s: %.*s -- %s\n", __FUNCTION__, (int)name.length, name.data,
41+
description);
42+
free(description);
4043
}
4144

4245
static void command_finished(void* context,

products/libllbuild/BuildSystem-C-API.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2015 - 2016 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -17,6 +17,7 @@
1717
#include "llbuild/BuildSystem/BuildSystemFrontend.h"
1818
#include "llbuild/Core/BuildEngine.h"
1919

20+
#include "llvm/ADT/SmallString.h"
2021
#include "llvm/Support/SourceMgr.h"
2122

2223
#include <cassert>
@@ -158,3 +159,21 @@ void llb_buildsystem_command_get_name(llb_buildsystem_command_t* command_p,
158159
key_out->length = name.size();
159160
key_out->data = (const uint8_t*) name.data();
160161
}
162+
163+
char* llb_buildsystem_command_get_description(
164+
llb_buildsystem_command_t* command_p) {
165+
auto command = (Command*) command_p;
166+
167+
SmallString<256> result;
168+
command->getShortDescription(result);
169+
return strdup(result.c_str());
170+
}
171+
172+
char* llb_buildsystem_command_get_verbose_description(
173+
llb_buildsystem_command_t* command_p) {
174+
auto command = (Command*) command_p;
175+
176+
SmallString<256> result;
177+
command->getVerboseDescription(result);
178+
return strdup(result.c_str());
179+
}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2015 - 2016 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -99,6 +99,25 @@ LLBUILD_EXPORT void
9999
llb_buildsystem_command_get_name(llb_buildsystem_command_t* command,
100100
llb_data_t* key_out);
101101

102+
/// Get the description for the given command.
103+
///
104+
/// \returns The command description, as a new C string. The client is
105+
/// resonpsible for calling \see free() on the result.
106+
//
107+
// FIXME: This API most likely doesn't belong.
108+
LLBUILD_EXPORT char*
109+
llb_buildsystem_command_get_description(llb_buildsystem_command_t* command);
110+
111+
/// Get the verbose description for the given command.
112+
///
113+
/// \returns The verbose command description, as a new C string. The client is
114+
/// resonpsible for calling \see free() on the result.
115+
//
116+
// FIXME: This API most likely doesn't belong.
117+
LLBUILD_EXPORT char*
118+
llb_buildsystem_command_get_verbose_description(
119+
llb_buildsystem_command_t* command);
120+
102121
/// @}
103122

104123
#endif

tests/Examples/buildsystem-capi.llbuild

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Check that the BuildSystem C API example builds and runs correctly.
22
#
3-
# RUN: cc -o %t.exe %{srcroot}/examples/c-api/buildsystem/main.c -I %{srcroot}/products/libllbuild/public-api -lllbuild -L %{llbuild-lib-dir}
3+
# RUN: cc -o %t.exe %{srcroot}/examples/c-api/buildsystem/main.c -I %{srcroot}/products/libllbuild/public-api -lllbuild -L %{llbuild-lib-dir} -Werror
44
# RUN: env LD_LIBRARY_PATH=%{llbuild-lib-dir} %t.exe %s > %t.out
55
# RUN: %{FileCheck} %s --input-file %t.out
66
#
7-
# CHECK: command_started: <hello>
7+
# CHECK: command_started: <hello> -- HELLO
88
# CHECK: command_finished: <hello>
99
# CHECK: command_started: <all>
1010
# CHECK: command_finished: <all>
@@ -26,3 +26,4 @@ commands:
2626
tool: shell
2727
args: ["echo", "Hello, world!"]
2828
outputs: ["<hello>"]
29+
description: HELLO

0 commit comments

Comments
 (0)