Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into seek-latency-metrics
Browse files Browse the repository at this point in the history
Change-Id: I4b1dc77751492846342a1c724f39f1b259d0eaae
  • Loading branch information
at-ninja committed Apr 1, 2024
2 parents 81d9e33 + 19a7161 commit d5ffbd7
Show file tree
Hide file tree
Showing 85 changed files with 887 additions and 160 deletions.
5 changes: 4 additions & 1 deletion base/files/file_util_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "base/files/file_util.h"

#include <sys/stat.h>

#include <stack>
#include <string>

Expand Down Expand Up @@ -231,7 +233,8 @@ bool CopyFile(const FilePath &from_path, const FilePath &to_path) {

bool PathExists(const FilePath &path) {
AssertBlockingAllowed();
return SbFileExists(path.value().c_str());
struct stat file_info;
return stat(path.value().c_str(), &file_info) == 0;
}

bool PathIsWritable(const FilePath &path) {
Expand Down
5 changes: 4 additions & 1 deletion cobalt/browser/splash_screen_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "cobalt/browser/splash_screen_cache.h"

#include <sys/stat.h>

#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -101,7 +103,8 @@ bool SplashScreenCache::IsSplashScreenCached() const {
if (!key) return false;
std::string full_path =
std::string(path.data()) + kSbFileSepString + key.value();
return SbFileExists(full_path.c_str());
struct stat file_info;
return stat(full_path.c_str(), &file_info) == 0;
}

int SplashScreenCache::ReadCachedSplashScreen(
Expand Down
5 changes: 5 additions & 0 deletions cobalt/browser/user_agent_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@

#include "cobalt/browser/user_agent_string.h"

#include <string.h>
#include <sys/stat.h>

#include <cstddef>
#include <vector>

#include "base/command_line.h"
#include "base/strings/stringprintf.h"
#include "cobalt/browser/switches.h"
#include "starboard/common/log.h"
#include "starboard/common/string.h"
#include "starboard/log.h"
#include "starboard/system.h"

namespace cobalt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Book: /youtube/cobalt/_book.yaml
| :--- |
| **`SB_C_FORCE_INLINE`**<br><br>The platform's annotation for forcing a C function to be inlined.<br><br>The default value in the Stub implementation is <br>`__inline__ __attribute__((always_inline))` |
| **`SB_C_INLINE`**<br><br>The platform's annotation for marking a C function as suggested to be inlined.<br><br>The default value in the Stub implementation is `inline` |
| **`SB_C_NOINLINE`**<br><br>The platform's annotation for marking a C function as forcibly not inlined.<br><br>The default value in the Stub implementation is `__attribute__((noinline))` |
| **`SB_EXPORT_PLATFORM`**<br><br>The platform's annotation for marking a symbol as exported outside of the current shared library.<br><br>The default value in the Stub implementation is <br>`__attribute__((visibility("default")))` |
| **`SB_IMPORT_PLATFORM`**<br><br>The platform's annotation for marking a symbol as imported from outside of the current linking unit. |

Expand Down
8 changes: 5 additions & 3 deletions cobalt/updater/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "cobalt/updater/utils.h"

#include <sys/stat.h>

#include <memory>
#include <vector>

Expand Down Expand Up @@ -100,10 +102,10 @@ const std::string GetEvergreenFileType(const std::string& installation_path) {
{installation_path, kSbFileSepString, kCompressedLibraryPath});
std::string uncompressed_library_path = base::StrCat(
{installation_path, kSbFileSepString, kUncompressedLibraryPath});

if (SbFileExists(compressed_library_path.c_str())) {
struct stat file_info;
if (stat(compressed_library_path.c_str(), &file_info) == 0) {
return "Compressed";
} else if (SbFileExists(uncompressed_library_path.c_str())) {
} else if (stat(uncompressed_library_path.c_str(), &file_info) == 0) {
return "Uncompressed";
} else {
LOG(ERROR) << "Failed to get Evergreen file type. Defaulting to "
Expand Down
26 changes: 15 additions & 11 deletions components/update_client/cobalt_slot_management.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "components/update_client/cobalt_slot_management.h"

#include <sys/stat.h>

#include <algorithm>
#include <vector>

Expand All @@ -33,11 +35,11 @@ bool CheckBadFileExists(const char* installation_path, const char* app_key) {
std::string bad_app_key_file_path =
starboard::loader_app::GetBadAppKeyFilePath(installation_path, app_key);
SB_DCHECK(!bad_app_key_file_path.empty());
struct stat file_info;
bool file_exists = stat(bad_app_key_file_path.c_str(), &file_info) == 0;
LOG(INFO) << "bad_app_key_file_path: " << bad_app_key_file_path;
LOG(INFO) << "bad_app_key_file_path SbFileExists: "
<< SbFileExists(bad_app_key_file_path.c_str());
return !bad_app_key_file_path.empty() &&
SbFileExists(bad_app_key_file_path.c_str());
LOG(INFO) << "bad_app_key_file_path FileExists: " << file_exists;
return !bad_app_key_file_path.empty() && file_exists;
}

uint64_t ComputeSlotSize(
Expand Down Expand Up @@ -324,18 +326,20 @@ bool CobaltQuickUpdate(
std::string good_app_key_file_path =
starboard::loader_app::GetGoodAppKeyFilePath(
installation_dir.value().c_str(), app_key);
struct stat file_info;
if (!installed_version.IsValid()) {
LOG(WARNING) << "CobaltQuickInstallation: invalid version ";
continue;
} else if (slot_candidate_version < installed_version &&
current_version < installed_version &&
(i == 0 || !DrainFileIsAnotherAppDraining(
installation_dir.value().c_str(), app_key) &&
!CheckBadFileExists(
installation_dir.value().c_str(), app_key) &&
!SbFileExists(good_app_key_file_path.c_str()) &&
starboard::loader_app::AnyGoodAppKeyFile(
installation_dir.value().c_str()))) {
(i == 0 ||
!DrainFileIsAnotherAppDraining(installation_dir.value().c_str(),
app_key) &&
!CheckBadFileExists(installation_dir.value().c_str(),
app_key) &&
stat(good_app_key_file_path.c_str(), &file_info) != 0 &&
starboard::loader_app::AnyGoodAppKeyFile(
installation_dir.value().c_str()))) {
// Found a slot with newer version than the current version. It's either
// the system image slot, or a writeable installation slot that's not
// draining, and no bad file of current app exists, and a good file
Expand Down
7 changes: 5 additions & 2 deletions components/update_client/cobalt_slot_management_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "components/update_client/cobalt_slot_management.h"

#include <sys/stat.h>

#include <algorithm>
#include <vector>

Expand Down Expand Up @@ -238,9 +240,10 @@ TEST_F(CobaltSlotManagementTest, CobaltFinishInstallation) {
ASSERT_EQ(IM_SUCCESS, ImRollForwardIfNeeded());

ASSERT_EQ(2, ImGetCurrentInstallationIndex());
ASSERT_FALSE(SbFileExists(good_file_path.c_str()));
struct stat file_info;
ASSERT_FALSE(stat(good_file_path.c_str(), &file_info) == 0);
ASSERT_TRUE(CobaltFinishInstallation(api_, 1, slot_path, kTestAppKey1));
ASSERT_TRUE(SbFileExists(good_file_path.c_str()));
ASSERT_TRUE(stat(good_file_path.c_str(), &file_info) == 0);
ASSERT_EQ(IM_SUCCESS, ImRollForwardIfNeeded());
ASSERT_EQ(1, ImGetCurrentInstallationIndex());
}
Expand Down
12 changes: 12 additions & 0 deletions docker/linux/base/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ RUN cd /tmp \
&& echo ${COBALT_CLANG_VER} >> ${COBALT_CLANG_TC_HOME}/cr_build_revision \
&& rm clang-llvmorg-${COBALT_CLANG_VER}.tgz

# === Install Clang 16 toolchain for all Linux-hosted builds
ARG CLANG_16_TC_HOME=${TC_ROOT}/x86_64-linux-gnu-clang-chromium-16-init-17653-g39da55e8-2
ARG CLANG_16_BASE_URL=https://commondatastorage.googleapis.com/chromium-browser-clang

RUN cd /tmp \
&& mkdir -p ${CLANG_16_TC_HOME} \
&& curl --silent -O -J \
${CLANG_16_BASE_URL}/Linux_x64/clang-llvmorg-16-init-17653-g39da55e8-2.tgz \
&& tar xf clang-llvmorg-16-init-17653-g39da55e8-2.tgz -C ${CLANG_16_TC_HOME} \
&& echo 16-init-17653-g39da55e8-2 >> ${CLANG_16_TC_HOME}/cr_build_revision \
&& rm clang-llvmorg-16-init-17653-g39da55e8-2.tgz

RUN git config --global --add safe.directory /code

WORKDIR /code
Expand Down
8 changes: 8 additions & 0 deletions starboard/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ since the version previous to it.

## Version 16

## Removed `SB_C_NOINLINE`
This is only used for testing, a similar header is now found under
`starboard/shared/testing/no_inline.h`

## Deprecated `OnScreenKeyboard`
OnScreenKeyboard Starboard API has been deprecated, an extension in
`starboard/extension/on_screen_keyboard.h` is available instead. The removal
Expand Down Expand Up @@ -66,6 +70,10 @@ Build configurations for `SB_HAS_STD_UNORDERED_HASH`, `SB_HAS_LONG_LONG_HASH`,
The standard API `getaddrinfo` and `freeaddrinfo`, can be used from
<netdb.h>.

### Added standard POSIX file stat API and deprecated SbFileExists.
The file API SbFileExists has been deprecated and the standard API `stat` can
be used from `sys/stat.h` instead.

### Added standard POSIX socket send/recv APIs.
The standard API `send`, `sendto`, `recv`, `recvfrom`, can be used from <sys/socket.h> and
`fcntl` can be used from <fcntl.h>, to set socket to non-blocking.
Expand Down
1 change: 1 addition & 0 deletions starboard/android/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ static_library("starboard_platform") {
"player_set_max_video_input_size.cc",
"player_set_max_video_input_size.h",
"player_set_playback_rate.cc",
"posix_emu/stat.cc",
"sanitizer_options.cc",
"socket_get_interface_address.cc",
"speech_synthesis_cancel.cc",
Expand Down
5 changes: 4 additions & 1 deletion starboard/android/shared/android_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <sys/stat.h>

#include "game-activity/GameActivity.h"
#include "starboard/android/shared/application_android.h"
#include "starboard/android/shared/jni_env_ext.h"
Expand Down Expand Up @@ -165,7 +167,8 @@ std::string ExtractCertificatesToFileSystem() {
apk_path.append(std::string(kSbFileSepString) + "app" + kSbFileSepString +
"cobalt" + kSbFileSepString + "content" + kSbFileSepString +
"ssl" + kSbFileSepString + "certs");
if (!SbFileExists(apk_path.c_str())) {
struct stat info;
if (stat(apk_path.c_str(), &info) != 0) {
SB_LOG(WARNING) << "CA certificates directory not found in APK";
return "";
}
Expand Down
4 changes: 0 additions & 4 deletions starboard/android/shared/configuration_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
// inlined.
#define SB_C_INLINE inline

// The platform's annotation for marking a C function as forcibly not
// inlined.
#define SB_C_NOINLINE __attribute__((noinline))

// The platform's annotation for marking a symbol as exported outside of the
// current shared library.
#define SB_EXPORT_PLATFORM __attribute__((visibility("default")))
Expand Down
2 changes: 2 additions & 0 deletions starboard/android/shared/file_exists.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16
#include "starboard/file.h"

bool SbFileExists(const char* path) {
return SbFileCanOpen(path, kSbFileRead);
}
#endif
3 changes: 3 additions & 0 deletions starboard/android/shared/platform_configuration/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ config("platform_configuration") {
# Wrapper synchronizes punch-out video bounds with the UI frame.
"-Wl,--wrap=eglSwapBuffers",
]
if (!is_native_target_build) {
ldflags += [ "-Wl,--wrap=stat" ]
}
}

config("size") {
Expand Down
88 changes: 88 additions & 0 deletions starboard/android/shared/posix_emu/stat.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright 2024 The Cobalt Authors. All Rights Reserved.
//
// 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 <sys/stat.h>

#include <android/asset_manager.h>

#include "starboard/android/shared/directory_internal.h"
#include "starboard/android/shared/file_internal.h"
#include "starboard/directory.h"

using starboard::android::shared::IsAndroidAssetPath;
using starboard::android::shared::OpenAndroidAsset;

///////////////////////////////////////////////////////////////////////////////
// Implementations below exposed externally in pure C for emulation.
///////////////////////////////////////////////////////////////////////////////

extern "C" {
int __real_stat(const char* path, struct stat* info);

// Reverse implementation of TimeTToWindowsUsec and PosixTimeToWindowsTime for
// backwards compatibility TimeTToWindowsUsec converts to microseconds
// (*1000000) and then calls PosixTimeToWindowsTime PosixTimeToWindows time adds
// number of microseconds since Jan 1, 1601 (UTC) until Jan 1, 1970 (UTC)
static SB_C_FORCE_INLINE time_t WindowsUsecToTimeTAndroid(int64_t time) {
int64_t posix_time = time - 11644473600000000ULL;
posix_time = posix_time / 1000000;
return posix_time;
}

static void MapSbFileInfoToStat(SbFileInfo* file_info, struct stat* stat_info) {
stat_info->st_mode = 0;
if (file_info->is_directory) {
stat_info->st_mode = S_IFDIR;
} else if (file_info->is_symbolic_link) {
stat_info->st_mode = S_IFLNK;
}

stat_info->st_ctime = WindowsUsecToTimeTAndroid(file_info->creation_time);
stat_info->st_atime = WindowsUsecToTimeTAndroid(file_info->last_accessed);
stat_info->st_mtime = WindowsUsecToTimeTAndroid(file_info->last_modified);
stat_info->st_size = file_info->size;
}

// This needs to be exported to ensure shared_library targets include it.
int __wrap_stat(const char* path, struct stat* info) {
// SbFileExists(path) implementation for Android
if (!IsAndroidAssetPath(path)) {
return __real_stat(path, info); // Using system level stat call
}

SbFile file = SbFileOpen(path, kSbFileRead | kSbFileOpenOnly, NULL, NULL);
SbFileInfo out_info;
if (file) {
bool result = SbFileGetInfo(file, &out_info);
MapSbFileInfoToStat(&out_info, info);
SbFileClose(file);
return 0;
}

// Values from SbFileGetPathInfo
SbDirectory directory = SbDirectoryOpen(path, NULL);
if (directory && directory->asset_dir) {
info->st_mode = S_IFDIR;
info->st_ctime = 0;
info->st_atime = 0;
info->st_mtime = 0;
info->st_size = 0;
SbDirectoryClose(directory);
return 0;
}

return -1;
}

} // extern "C"
4 changes: 4 additions & 0 deletions starboard/android/shared/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
'SbDirectoryGetNextTest.SunnyDayStaticContent',
'SbDirectoryOpenTest.SunnyDayStaticContent',
'SbFileGetPathInfoTest.WorksOnStaticContentDirectories',
'PosixDirectoryCanOpenTest.SunnyDayStaticContent',
'PosixDirectoryGetNextTest.SunnyDayStaticContent',
'PosixDirectoryOpenTest.SunnyDayStaticContent',
'PosixFileGetPathInfoTest.WorksOnStaticContentDirectories',

# These tests are disabled due to not receiving the kEndOfStream
# player state update within the specified timeout.
Expand Down
5 changes: 4 additions & 1 deletion starboard/common/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "starboard/common/file.h"

#include <sys/stat.h>

#include <cstring>
#include <string>
#include <vector>
Expand Down Expand Up @@ -49,7 +51,8 @@ void RecordFileWriteStat(int write_file_result) {
}

bool SbFileDeleteRecursive(const char* path, bool preserve_root) {
if (!SbFileExists(path)) {
struct stat file_info;
if (stat(path, &file_info) != 0) {
SB_LOG(ERROR) << "Path does not exist: '" << path << "'";
return false;
}
Expand Down
Loading

0 comments on commit d5ffbd7

Please sign in to comment.