Skip to content

Commit c8605cd

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Fix headers search paths for nlohmann json in Core ML. (#3614)
Summary: . Differential Revision: D57368772
1 parent aaa2f2e commit c8605cd

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

backends/apple/coreml/runtime/test/DatabaseTests.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#import <XCTest/XCTest.h>
99

1010
#import <database.hpp>
11-
#import <json.hpp>
11+
#import <nlohmann/json.hpp>
1212

1313
@interface DatabaseTests : XCTestCase
1414

@@ -58,7 +58,7 @@ - (void)testDatabaseQuery {
5858
XCTAssertTrue(insertStatement->bind_name("$value", std::string("1"), error));
5959
XCTAssertTrue(insertStatement->execute(error));
6060
XCTAssertTrue(database->get_row_count("TEST", error) == 1);
61-
61+
6262
auto query = database->prepare_statement("SELECT * FROM TEST", error);
6363
XCTAssertTrue(query != nullptr);
6464
XCTAssertTrue(query->step(error));

backends/apple/coreml/runtime/test/InMemoryFileSystemTests.mm

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#import <inmemory_filesystem_utils.hpp>
1515
#import <memory_stream.hpp>
16-
#import <json.hpp>
16+
#import <nlohmann/json.hpp>
1717
#import <json_util.hpp>
1818

1919
using json = nlohmann::json;
@@ -25,11 +25,11 @@
2525
inline Content(std::string identifier, std::string value) noexcept
2626
:identifier(std::move(identifier)), value(std::move(value))
2727
{}
28-
28+
2929
inline Content() noexcept
3030
:identifier(""), value("")
3131
{}
32-
32+
3333
std::string identifier;
3434
std::string value;
3535
};
@@ -80,7 +80,7 @@ T from_memory_buffer(const std::shared_ptr<MemoryBuffer>& buffer) {
8080
for (size_t i = 0; i < length; ++i) {
8181
result += chars[rand() % (sizeof(chars) - 1)];
8282
}
83-
83+
8484
return result;
8585
}
8686

@@ -178,12 +178,12 @@ - (void)testWriteItemAtPath {
178178
Content content("abc", "xyz");
179179
std::shared_ptr<MemoryBuffer> buffer = to_memory_buffer(content);
180180
std::error_code error;
181-
181+
182182
XCTAssertTrue(fs.make_directory({"dir1"}, InMemoryFileSystem::Attributes(), false, error));
183183
XCTAssertTrue(fs.make_file({"dir1", "content.json"}, buffer, InMemoryFileSystem::Attributes(), false /*overwrite*/, error));
184184
XCTAssertTrue(fs.make_directory({"dir1", "dir2"}, InMemoryFileSystem::Attributes(), false, error));
185185
XCTAssertTrue(fs.make_file({"dir1", "dir2", "content.json"}, buffer, InMemoryFileSystem::Attributes(), false /*overwrite*/, error));
186-
186+
187187
NSURL *dirURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()] URLByAppendingPathComponent:[NSUUID UUID].UUIDString];
188188
NSFileManager *fm = [[NSFileManager alloc] init];
189189
NSError *localError = nil;
@@ -220,7 +220,7 @@ - (void)testCreationFromFileSystem {
220220
NSData *data = [NSData dataWithBytesNoCopy:buffer->data() length:buffer->size() freeWhenDone:NO];
221221
XCTAssertTrue([data writeToURL:[dirURL URLByAppendingPathComponent:@"dir1/content.json"] atomically:YES]);
222222
XCTAssertTrue([data writeToURL:[dirURL URLByAppendingPathComponent:@"dir2/content.json"] atomically:YES]);
223-
223+
224224
std::filesystem::path dirPath(dirURL.path.UTF8String);
225225
std::error_code error;
226226
auto fs = InMemoryFileSystem::make_from_directory(dirPath,
@@ -256,31 +256,31 @@ - (void)_testSerdeWithConfig:(SerdeVerificationConfig)config {
256256
}
257257
XCTAssertTrue(fs.write_item_to_disk({}, dirURL.path.UTF8String, true, error));
258258
}
259-
259+
260260
// Verify serialization.
261261
std::shared_ptr<MemoryBuffer> buffer = nullptr;
262262
{
263263
std::error_code error;
264264
auto fs = InMemoryFileSystem::make_from_directory(dirURL.path.UTF8String,
265265
config.file_load_option,
266266
error);
267-
267+
268268
XCTAssertTrue(fs != nullptr);
269269
size_t length = inmemoryfs::get_buffer_size_for_serialization(*fs, {}, config.alignment);
270270
switch (config.file_load_option) {
271271
case InMemoryFileSystem::FileLoadOption::LazyMMap: {
272272
buffer = MemoryBuffer::make_using_mmap(length);
273273
break;
274274
}
275-
275+
276276
default:
277277
buffer = MemoryBuffer::make_using_malloc(length);
278278
break;
279279
}
280-
280+
281281
XCTAssertTrue(inmemoryfs::serialize(*fs, {}, config.alignment, buffer->data(), error));
282282
}
283-
283+
284284
// Verify de-serialization.
285285
{
286286
auto fs = inmemoryfs::make_from_buffer(buffer);
@@ -290,7 +290,7 @@ - (void)_testSerdeWithConfig:(SerdeVerificationConfig)config {
290290
XCTAssertEqual(from_memory_buffer<Content>(fs->get_file_content({"test", "dir", content.identifier}, error)), content);
291291
}
292292
}
293-
293+
294294
[fm removeItemAtURL:dirURL error:nil];
295295
}
296296

@@ -332,7 +332,7 @@ - (void)testSerde {
332332
.file_base_length = 100,
333333
.alignment = 2 * (size_t)getpagesize(),
334334
});
335-
335+
336336
for (const auto& config : configs) {
337337
[self _testSerdeWithConfig:config];
338338
}
@@ -349,16 +349,16 @@ - (void)testReadJSONObject {
349349
auto j = json::parse(object.value().begin(), object.value().end());
350350
XCTAssertEqual(j["x"], 1, "The value must match");
351351
}
352-
352+
353353
{
354354
std::stringstream ss;
355355
std::string fragment("{\"x\" : 1");
356356
ss << fragment;
357357
auto object = executorchcoreml::json::read_object_from_stream(ss);
358358
XCTAssertFalse(object.has_value(), "There is no closing brace, `read_json_object` must return nullopt");
359359
}
360-
361-
360+
361+
362362
{
363363
std::stringstream ss;
364364
std::string fragment("{\"x\" : \"\\\"1\"}xyz");
@@ -369,7 +369,7 @@ - (void)testReadJSONObject {
369369
std::string value = j["x"];
370370
XCTAssertEqual(value, std::string("\"1"), "The value must match");
371371
}
372-
372+
373373
{
374374
std::stringstream ss;
375375
std::string fragment("{sdhalskjks}");
@@ -384,7 +384,7 @@ - (void)testReadJSONObject {
384384
}
385385
XCTAssertNotEqual(eptr, nullptr, "Parsing invalid json object must throw an exception");
386386
}
387-
387+
388388
}
389389

390390
@end

backends/apple/coreml/runtime/test/KeyValueStoreTests.mm

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <XCTest/XCTest.h>
1010

1111
#import <json_key_value_store.hpp>
12-
#import <json.hpp>
12+
#import <nlohmann/json.hpp>
1313

1414
namespace {
1515
using json = nlohmann::json;
@@ -24,24 +24,24 @@
2424
inline Entry(std::string identifier, size_t count) noexcept
2525
:identifier(std::move(identifier)), count(count)
2626
{}
27-
27+
2828
inline Entry() noexcept
2929
:identifier(""), count(0)
3030
{}
31-
31+
3232
inline std::string to_json_string() const noexcept {
3333
json j;
3434
to_json(j, *this);
3535
std::stringstream ss;
3636
ss << j;
3737
return ss.str();
3838
}
39-
39+
4040
inline void from_json_string(const std::string& json_string) noexcept {
4141
auto j = json::parse(json_string);
4242
from_json(j, *this);
4343
}
44-
44+
4545
std::string identifier;
4646
size_t count;
4747
};
@@ -110,12 +110,12 @@ - (void)testJSONKeyValueStore {
110110
std::error_code error;
111111
auto database = Database::make_inmemory(Database::SynchronousMode::Normal, 100, error);
112112
auto store = JSONKeyValueStore<int, Entry>::make(std::move(database), "test", error);
113-
113+
114114
XCTAssertTrue(store->put(1, Entry("1", 1), error));
115115
auto entry1 = store->get(1, error);
116116
XCTAssertTrue(entry1.value().count == 1);
117117
XCTAssertTrue(entry1.value().identifier == "1");
118-
118+
119119
XCTAssertTrue(store->put(2, Entry("2", 2), error));
120120
auto entry2 = store->get(2, error);
121121
XCTAssertTrue(entry2.value().count == 2);
@@ -134,7 +134,7 @@ - (void)testKVStoreTransactionCommit {
134134
// Commit the transaction.
135135
return true;
136136
}, Database::TransactionBehavior::Immediate, error));
137-
137+
138138
XCTAssertTrue(store->size(error) == 2);
139139
}
140140

@@ -150,7 +150,7 @@ - (void)testKVStoreTransactionRollback {
150150
// Rollback the transaction.
151151
return false;
152152
}, Database::TransactionBehavior::Immediate, error));
153-
153+
154154
XCTAssertTrue(store->size(error) == 0);
155155
}
156156

@@ -173,7 +173,7 @@ - (void)testKVStoreGetKeysSortedByAccessTime {
173173
// 1 is accessed first then 2 and then 3
174174
XCTAssertTrue(keys == (std::vector<int>{1, 2, 3}));
175175
}
176-
176+
177177
{
178178
std::vector<int> keys;
179179
XCTAssertTrue(store->get_keys_sorted_by_access_time([&keys](int key) {
@@ -210,7 +210,7 @@ - (void)testKVStoreGetKeysSortedByAccessCount {
210210
// 3 is accessed 1 time, 2 is accessed 2 times, and 1 is accessed 3 times.
211211
XCTAssertTrue(keys == (std::vector<int>{3, 2, 1}));
212212
}
213-
213+
214214
{
215215
std::vector<int> keys;
216216
XCTAssertTrue(store->get_keys_sorted_by_access_count([&keys](int key) {

0 commit comments

Comments
 (0)