From adacaef799455013bf00b85a43237ac8d9471ade Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Mon, 6 Feb 2017 09:26:14 -0500 Subject: [PATCH] iOS: cd into Documents folder at startup CQ_INCLUDE_TRYBOTS=skia.primary:Test-iOS-Clang-iPadMini4-GPU-GX6450-arm-Release Change-Id: I7beadad742bc9444491c7a315a827297a636d70d Reviewed-on: https://skia-review.googlesource.com/8049 Reviewed-by: Mike Klein Commit-Queue: Mike Klein --- BUILD.gn | 5 +++++ bench/nanobench.cpp | 4 ++++ dm/DM.cpp | 4 ++++ tools/ios_utils.h | 23 +++++++++++++++++++++++ tools/ios_utils.m | 19 +++++++++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 tools/ios_utils.h create mode 100644 tools/ios_utils.m diff --git a/BUILD.gn b/BUILD.gn index 25b68b4..c19b3bd 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -910,6 +910,11 @@ if (skia_enable_tools) { "tools/sk_tool_utils_font.cpp", "tools/timer/Timer.cpp", ] + libs = [] + if (is_ios) { + sources += [ "tools/ios_utils.m" ] + libs += [ "Foundation.framework" ] + } deps = [ ":common_flags", ":flags", diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index c2afca6..4e1da2b 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -23,6 +23,7 @@ #include "SKPAnimationBench.h" #include "SKPBench.h" #include "Stats.h" +#include "ios_utils.h" #include "SkAndroidCodec.h" #include "SkAutoMalloc.h" @@ -1096,6 +1097,9 @@ static void start_keepalive() { int nanobench_main(); int nanobench_main() { +#if defined(SK_BUILD_FOR_IOS) + cd_Documents(); +#endif SetupCrashHandler(); SkAutoGraphics ag; SkTaskGroup::Enabler enabled(FLAGS_threads); diff --git a/dm/DM.cpp b/dm/DM.cpp index 6dc1bd9..e371bbc 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -32,6 +32,7 @@ #include "SkThreadUtils.h" #include "Test.h" #include "Timer.h" +#include "ios_utils.h" #include "picture_utils.h" #include "sk_tool_utils.h" #include "SkScan.h" @@ -1284,6 +1285,9 @@ extern sk_sp (*gCreateTypefaceDelegate)(const char [], SkFontStyle ) int dm_main(); int dm_main() { +#if defined(SK_BUILD_FOR_IOS) + cd_Documents(); +#endif setbuf(stdout, nullptr); setup_crash_handler(); diff --git a/tools/ios_utils.h b/tools/ios_utils.h new file mode 100644 index 0000000..0287dc1 --- /dev/null +++ b/tools/ios_utils.h @@ -0,0 +1,23 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef ios_util_DEFINED +#define ios_util_DEFINED + +#if defined(__cplusplus) +extern "C" { +#endif + + // cd into the current app's Documents/ directory. + // (This is the only directory we can easily read and write.) + void cd_Documents(); + +#if defined(__cplusplus) +} +#endif + +#endif//ios_util_DEFINED diff --git a/tools/ios_utils.m b/tools/ios_utils.m new file mode 100644 index 0000000..b88ab5b --- /dev/null +++ b/tools/ios_utils.m @@ -0,0 +1,19 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#import +#include "ios_utils.h" +#include + +void cd_Documents() { + @autoreleasepool { + NSURL* dir = [[[NSFileManager defaultManager] + URLsForDirectory:NSDocumentDirectory + inDomains:NSUserDomainMask] lastObject]; + chdir([dir.path UTF8String]); + } +} -- 2.7.4