diff --git a/build/linux/ci-common.sh b/build/linux/ci-common.sh index 42cbab27ab..4f12dd13a7 100755 --- a/build/linux/ci-common.sh +++ b/build/linux/ci-common.sh @@ -29,6 +29,7 @@ cd .. # Steps for GitHub Workflows if [[ "$GITHUB_WORKFLOW" ]]; then sudo wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo apt-get update sudo apt-get install clang-$GITHUB_CLANG_VERSION libc++-$GITHUB_CLANG_VERSION-dev libc++abi-$GITHUB_CLANG_VERSION-dev sudo apt-get install mesa-common-dev libxi-dev libxxf86vm-dev diff --git a/libs/utils/CMakeLists.txt b/libs/utils/CMakeLists.txt index 0b4e7b7253..467e936000 100644 --- a/libs/utils/CMakeLists.txt +++ b/libs/utils/CMakeLists.txt @@ -51,7 +51,7 @@ if (LINUX OR ANDROID) list(APPEND SRCS src/linux/Path.cpp) endif() if (APPLE) - list(APPEND SRCS src/darwin/Path.cpp) + list(APPEND SRCS src/darwin/Path.mm) endif() # ================================================================================================== diff --git a/libs/utils/include/utils/Path.h b/libs/utils/include/utils/Path.h index 2107918272..1f498932b5 100644 --- a/libs/utils/include/utils/Path.h +++ b/libs/utils/include/utils/Path.h @@ -239,6 +239,11 @@ public: */ static Path getCurrentExecutable(); + /** + * @return a path representing a directory where temporary files can be stored + */ + static Path getTemporaryDirectory(); + /** * Creates a directory denoted by the given path. * This is not recursive and doesn't create intermediate directories. diff --git a/libs/utils/src/ashmem.cpp b/libs/utils/src/ashmem.cpp index ef3595ead6..8a529f9c56 100644 --- a/libs/utils/src/ashmem.cpp +++ b/libs/utils/src/ashmem.cpp @@ -21,6 +21,8 @@ #include #include +#include + #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) # include # include @@ -133,7 +135,8 @@ error: int ashmem_create_region(const char*, size_t size) { char template_path[512]; - snprintf(template_path, sizeof(template_path), "/tmp/filament-ashmem-%d-XXXXXXXXX", getpid()); + snprintf(template_path, sizeof(template_path), "%s/filament-ashmem-%d-XXXXXXXXX", + Path::getTemporaryDirectory().c_str(), getpid()); int fd = mkstemp(template_path); if (fd == -1) return -1; unlink(template_path); @@ -147,8 +150,8 @@ int ashmem_create_region(const char*, size_t size) { #else int ashmem_create_region(const char*, size_t size) { char template_path[512]; - snprintf(template_path, sizeof(template_path), "/tmp/filament-ashmem-%lu-XXXXXXXXX", - GetCurrentProcessId()); + snprintf(template_path, sizeof(template_path), "%s/filament-ashmem-%lu-XXXXXXXXX", + Path::getTemporaryDirectory().c_str(), GetCurrentProcessId()); const char* tmpPath = _mktemp(template_path); int fd = _open(tmpPath, _O_BINARY); if (fd == -1) return -1; diff --git a/libs/utils/src/darwin/Path.cpp b/libs/utils/src/darwin/Path.mm similarity index 90% rename from libs/utils/src/darwin/Path.cpp rename to libs/utils/src/darwin/Path.mm index e999ec3c65..1e88c76352 100644 --- a/libs/utils/src/darwin/Path.cpp +++ b/libs/utils/src/darwin/Path.mm @@ -1,74 +1,80 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include - -#include -#include - -#include - -namespace utils { - -bool Path::mkdir() const { - return ::mkdir(m_path.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) == 0; -} - -Path Path::getCurrentExecutable() { - // First, need to establish resource path. - char exec_buf[2048]; - Path result; - - uint32_t buffer_size = sizeof(exec_buf); - if (_NSGetExecutablePath(exec_buf, &buffer_size) == 0) { - result.setPath(exec_buf); - } - - return result; -} - -std::vector Path::listContents() const { - // Return an empty vector if the path doesn't exist or is not a directory - if (!isDirectory() || !exists()) { - return {}; - } - - struct dirent* directory; - DIR* dir; - - dir = opendir(c_str()); - if (dir == nullptr) { - // Path does not exist or could not be read - return {}; - } - - std::vector directory_contents; - - while ((directory = readdir(dir)) != nullptr) { - const char* file = directory->d_name; - if (file[0] != '.') { - directory_contents.push_back(concat(directory->d_name)); - } - } - - closedir(dir); - return directory_contents; -} - -} // namespace utils - +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include +#include + +#include + +#include + +namespace utils { + +bool Path::mkdir() const { + return ::mkdir(m_path.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) == 0; +} + +Path Path::getCurrentExecutable() { + // First, need to establish resource path. + char exec_buf[2048]; + Path result; + + uint32_t buffer_size = sizeof(exec_buf); + if (_NSGetExecutablePath(exec_buf, &buffer_size) == 0) { + result.setPath(exec_buf); + } + + return result; +} + +Path Path::getTemporaryDirectory() { + NSString* tempDir = NSTemporaryDirectory(); + return Path([tempDir cStringUsingEncoding:NSUTF8StringEncoding]); +} + +std::vector Path::listContents() const { + // Return an empty vector if the path doesn't exist or is not a directory + if (!isDirectory() || !exists()) { + return {}; + } + + struct dirent* directory; + DIR* dir; + + dir = opendir(c_str()); + if (dir == nullptr) { + // Path does not exist or could not be read + return {}; + } + + std::vector directory_contents; + + while ((directory = readdir(dir)) != nullptr) { + const char* file = directory->d_name; + if (file[0] != '.') { + directory_contents.push_back(concat(directory->d_name)); + } + } + + closedir(dir); + return directory_contents; +} + +} // namespace utils diff --git a/libs/utils/src/linux/Path.cpp b/libs/utils/src/linux/Path.cpp index 7ffaa73af9..5bbc8e7ba0 100644 --- a/libs/utils/src/linux/Path.cpp +++ b/libs/utils/src/linux/Path.cpp @@ -1,72 +1,75 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#include -#include - -namespace utils { - -bool Path::mkdir() const { - return ::mkdir(m_path.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) == 0; -} - -Path Path::getCurrentExecutable() { - // First, need to establish resource path. - char exec_buf[2048]; - Path result; - - uint32_t buffer_size = sizeof(exec_buf)-1; - ssize_t sz = readlink("/proc/self/exe", exec_buf, buffer_size); - if (sz > 0) { - exec_buf[sz] = 0; - result.setPath(exec_buf); - } - - return result; -} - -std::vector Path::listContents() const { - // Return an empty vector if the path doesn't exist or is not a directory - if (!isDirectory() || !exists()) { - return {}; - } - - struct dirent* directory; - DIR* dir; - - dir = opendir(c_str()); - if (dir == nullptr) { - // Path does not exist or could not be read - return {}; - } - - std::vector directory_contents; - - while ((directory = readdir(dir)) != nullptr) { - const char* file = directory->d_name; - if (file[0] != '.') { - directory_contents.push_back(concat(directory->d_name)); - } - } - - closedir(dir); - return directory_contents; -} -} // namespace utils - +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +namespace utils { + +bool Path::mkdir() const { + return ::mkdir(m_path.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) == 0; +} + +Path Path::getCurrentExecutable() { + // First, need to establish resource path. + char exec_buf[2048]; + Path result; + + uint32_t buffer_size = sizeof(exec_buf)-1; + ssize_t sz = readlink("/proc/self/exe", exec_buf, buffer_size); + if (sz > 0) { + exec_buf[sz] = 0; + result.setPath(exec_buf); + } + + return result; +} + +Path Path::getTemporaryDirectory() { + return Path("/tmp/"); +} + +std::vector Path::listContents() const { + // Return an empty vector if the path doesn't exist or is not a directory + if (!isDirectory() || !exists()) { + return {}; + } + + struct dirent* directory; + DIR* dir; + + dir = opendir(c_str()); + if (dir == nullptr) { + // Path does not exist or could not be read + return {}; + } + + std::vector directory_contents; + + while ((directory = readdir(dir)) != nullptr) { + const char* file = directory->d_name; + if (file[0] != '.') { + directory_contents.push_back(concat(directory->d_name)); + } + } + + closedir(dir); + return directory_contents; +} +} // namespace utils diff --git a/libs/utils/src/win32/Path.cpp b/libs/utils/src/win32/Path.cpp index 1975cbc09f..7541302ef8 100644 --- a/libs/utils/src/win32/Path.cpp +++ b/libs/utils/src/win32/Path.cpp @@ -40,6 +40,12 @@ Path Path::getCurrentExecutable() { return result; } +Path Path::getTemporaryDirectory() { + TCHAR lpTempPathBuffer[MAX_PATH]; + DWORD dwRetVal = GetTempPath(MAX_PATH, lpTempPathBuffer); + return Path(lpTempPathBuffer); +} + std::vector Path::listContents() const { // Return an empty vector if the path doesn't exist or is not a directory if (!isDirectory() || !exists()) {