mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add fml::paths::GetExecutableDirectoryPath. (flutter/engine#3508)
This commit is contained in:
parent
458075d867
commit
52bf72fb46
@ -12,6 +12,7 @@ source_set("fml") {
|
||||
"message_loop.h",
|
||||
"message_loop_impl.cc",
|
||||
"message_loop_impl.h",
|
||||
"paths.h",
|
||||
"task_runner.cc",
|
||||
"task_runner.h",
|
||||
"thread.cc",
|
||||
@ -43,6 +44,7 @@ source_set("fml") {
|
||||
"platform/darwin/message_loop_darwin.mm",
|
||||
"platform/darwin/nsstring_utils.h",
|
||||
"platform/darwin/nsstring_utils.mm",
|
||||
"platform/darwin/paths_darwin.mm",
|
||||
"platform/darwin/resource_mapping_darwin.h",
|
||||
"platform/darwin/resource_mapping_darwin.mm",
|
||||
"platform/darwin/scoped_block.h",
|
||||
@ -62,6 +64,7 @@ source_set("fml") {
|
||||
"platform/android/jni_weak_ref.h",
|
||||
"platform/android/message_loop_android.cc",
|
||||
"platform/android/message_loop_android.h",
|
||||
"platform/android/paths_android.cc",
|
||||
"platform/android/scoped_java_ref.cc",
|
||||
"platform/android/scoped_java_ref.h",
|
||||
]
|
||||
@ -83,6 +86,7 @@ source_set("fml") {
|
||||
sources += [
|
||||
"platform/linux/message_loop_linux.cc",
|
||||
"platform/linux/message_loop_linux.h",
|
||||
"platform/linux/paths_linux.cc",
|
||||
"platform/linux/timerfd.cc",
|
||||
"platform/linux/timerfd.h",
|
||||
]
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include <mutex>
|
||||
|
||||
#include "flutter/fml/mapping.h"
|
||||
#include "flutter/fml/paths.h"
|
||||
#include "lib/ftl/build_config.h"
|
||||
#include "lib/ftl/logging.h"
|
||||
#include "third_party/icu/source/common/unicode/udata.h"
|
||||
@ -44,7 +45,16 @@ class ICUContext {
|
||||
|
||||
// Check if the mapping can by directly accessed via a file path. In this
|
||||
// case, the data file needs to be next to the executable.
|
||||
auto file = std::make_unique<FileMapping>(kIcuDataFileName);
|
||||
auto directory = fml::paths::GetExecutableDirectoryPath();
|
||||
|
||||
if (!directory.first) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME(chinmaygarde): There is no Path::Join in FTL. So a non-portable
|
||||
// version is used here. Patch FTL and update.
|
||||
auto file = std::make_unique<FileMapping>(directory.second + "/" +
|
||||
kIcuDataFileName);
|
||||
if (file->GetSize() != 0) {
|
||||
mapping_ = std::move(file);
|
||||
return true;
|
||||
|
||||
19
engine/src/flutter/fml/paths.h
Normal file
19
engine/src/flutter/fml/paths.h
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_FML_PATHS_H_
|
||||
#define FLUTTER_FML_PATHS_H_
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath();
|
||||
|
||||
} // namespace paths
|
||||
} // namespace fml
|
||||
|
||||
#endif // FLUTTER_FML_PATHS_H_
|
||||
15
engine/src/flutter/fml/platform/android/paths_android.cc
Normal file
15
engine/src/flutter/fml/platform/android/paths_android.cc
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/fml/paths.h"
|
||||
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
return {false, ""};
|
||||
}
|
||||
|
||||
} // namespace paths
|
||||
} // namespace fml
|
||||
20
engine/src/flutter/fml/platform/darwin/paths_darwin.mm
Normal file
20
engine/src/flutter/fml/platform/darwin/paths_darwin.mm
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/fml/paths.h"
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
#include "lib/ftl/files/path.h"
|
||||
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
return {true, files::GetDirectoryName(
|
||||
[NSBundle mainBundle].executablePath.UTF8String)};
|
||||
}
|
||||
|
||||
} // namespace paths
|
||||
} // namespace fml
|
||||
25
engine/src/flutter/fml/platform/linux/paths_linux.cc
Normal file
25
engine/src/flutter/fml/platform/linux/paths_linux.cc
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/fml/paths.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lib/ftl/files/path.h"
|
||||
|
||||
namespace fml {
|
||||
namespace paths {
|
||||
|
||||
std::pair<bool, std::string> GetExecutableDirectoryPath() {
|
||||
const int path_size = 255;
|
||||
char path[path_size] = {0};
|
||||
auto read_size = ::readlink("/proc/self/exe", path, path_size);
|
||||
if (read_size == -1) {
|
||||
return {false, ""};
|
||||
}
|
||||
return {true, files::GetDirectoryName(std::string{path, read_size})};
|
||||
}
|
||||
|
||||
} // namespace paths
|
||||
} // namespace fml
|
||||
Loading…
x
Reference in New Issue
Block a user