Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06b1d107 authored by Colin Cross's avatar Colin Cross Committed by Automerger Merge Worker
Browse files

Merge "Fix frameworks/native compiling against musl" am: 79abc051

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1826713

Change-Id: I3f2c642965c099ab71d8d2e253ee9532a3371b69
parents e86f58c5 79abc051
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -74,12 +74,12 @@ std::optional<AdbForwarder> AdbForwarder::forward(unsigned int devicePort) {
              result->toString().c_str());
        return std::nullopt;
    }
    if (!result->stderr.empty()) {
    if (!result->stderrStr.empty()) {
        LOG_HOST("`adb forward tcp:0 tcp:%d` writes to stderr: %s", devicePort,
                 result->stderr.c_str());
                 result->stderrStr.c_str());
    }

    unsigned int hostPort = parsePortNumber(result->stdout, "host port");
    unsigned int hostPort = parsePortNumber(result->stdoutStr, "host port");
    if (hostPort == 0) return std::nullopt;

    return AdbForwarder(hostPort);
@@ -105,9 +105,9 @@ AdbForwarder::~AdbForwarder() {
              result->toString().c_str());
        return;
    }
    if (!result->stderr.empty()) {
    if (!result->stderrStr.empty()) {
        LOG_HOST("`adb forward --remove tcp:%d` writes to stderr: %s", *mPort,
                 result->stderr.c_str());
                 result->stderrStr.c_str());
    }

    LOG_HOST("Successfully run `adb forward --remove tcp:%d`", *mPort);
@@ -139,8 +139,8 @@ sp<IBinder> getDeviceService(std::vector<std::string>&& serviceDispatcherArgs) {
        ALOGE("Command exits with: %s", result->toString().c_str());
        return nullptr;
    }
    if (!result->stderr.empty()) {
        LOG_HOST("servicedispatcher writes to stderr: %s", result->stderr.c_str());
    if (!result->stderrStr.empty()) {
        LOG_HOST("servicedispatcher writes to stderr: %s", result->stderrStr.c_str());
    }

    if (!result->stdoutEndsWithNewLine()) {
@@ -148,7 +148,7 @@ sp<IBinder> getDeviceService(std::vector<std::string>&& serviceDispatcherArgs) {
        return nullptr;
    }

    unsigned int devicePort = parsePortNumber(result->stdout, "device port");
    unsigned int devicePort = parsePortNumber(result->stdoutStr, "device port");
    if (devicePort == 0) return nullptr;

    auto forwardResult = AdbForwarder::forward(devicePort);
+3 −3
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ std::ostream& operator<<(std::ostream& os, const CommandResult& res) {
    if (res.exitCode) os << "code=" << *res.exitCode;
    if (res.signal) os << "signal=" << *res.signal;
    if (res.pid) os << ", pid=" << *res.pid;
    return os << ", stdout=" << res.stdout << ", stderr=" << res.stderr;
    return os << ", stdout=" << res.stdoutStr << ", stderr=" << res.stderrStr;
}

std::string CommandResult::toString() const {
@@ -142,9 +142,9 @@ android::base::Result<CommandResult> execute(std::vector<std::string> argStringV
        int pollRet = poll(fds, nfds, 1000 /* ms timeout */);
        if (pollRet == -1) return android::base::ErrnoError() << "poll()";

        if (!handlePoll(&ret.outPipe, outPollFd, &ret.stdout))
        if (!handlePoll(&ret.outPipe, outPollFd, &ret.stdoutStr))
            return android::base::ErrnoError() << "read(stdout)";
        if (!handlePoll(&ret.errPipe, errPollFd, &ret.stderr))
        if (!handlePoll(&ret.errPipe, errPollFd, &ret.stderrStr))
            return android::base::ErrnoError() << "read(stderr)";

        if (end && end(ret)) return ret;
+5 −5
Original line number Diff line number Diff line
@@ -43,8 +43,8 @@ struct CommandResult {
    std::optional<int32_t> exitCode;
    std::optional<int32_t> signal;
    std::optional<pid_t> pid;
    std::string stdout;
    std::string stderr;
    std::string stdoutStr;
    std::string stderrStr;

    android::base::unique_fd outPipe;
    android::base::unique_fd errPipe;
@@ -55,15 +55,15 @@ struct CommandResult {
        std::swap(exitCode, other.exitCode);
        std::swap(signal, other.signal);
        std::swap(pid, other.pid);
        std::swap(stdout, other.stdout);
        std::swap(stderr, other.stderr);
        std::swap(stdoutStr, other.stdoutStr);
        std::swap(stderrStr, other.stderrStr);
        return *this;
    }
    ~CommandResult();
    [[nodiscard]] std::string toString() const;

    [[nodiscard]] bool stdoutEndsWithNewLine() const {
        return !stdout.empty() && stdout.back() == '\n';
        return !stdoutStr.empty() && stdoutStr.back() == '\n';
    }

private:
+3 −3
Original line number Diff line number Diff line
@@ -75,10 +75,10 @@ public:
        auto debuggableResult = execute(Split("adb shell getprop ro.debuggable", " "), nullptr);
        ASSERT_THAT(debuggableResult, Ok());
        ASSERT_EQ(0, debuggableResult->exitCode) << *debuggableResult;
        auto debuggableBool = ParseBool(Trim(debuggableResult->stdout));
        ASSERT_NE(ParseBoolResult::kError, debuggableBool) << Trim(debuggableResult->stdout);
        auto debuggableBool = ParseBool(Trim(debuggableResult->stdoutStr));
        ASSERT_NE(ParseBoolResult::kError, debuggableBool) << Trim(debuggableResult->stdoutStr);
        if (debuggableBool == ParseBoolResult::kFalse) {
            GTEST_SKIP() << "ro.debuggable=" << Trim(debuggableResult->stdout);
            GTEST_SKIP() << "ro.debuggable=" << Trim(debuggableResult->stdoutStr);
        }

        auto lsResult = execute(Split("adb shell which servicedispatcher", " "), nullptr);
+5 −5
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ TEST(UtilsHost, ExecuteImmediately) {
    auto result = execute({"echo", "foo"}, nullptr);
    ASSERT_THAT(result, Ok());
    EXPECT_THAT(result->exitCode, Optional(EX_OK));
    EXPECT_EQ(result->stdout, "foo\n");
    EXPECT_EQ(result->stdoutStr, "foo\n");
}

TEST(UtilsHost, ExecuteLongRunning) {
@@ -44,7 +44,7 @@ TEST(UtilsHost, ExecuteLongRunning) {
        std::vector<std::string> args{"sh", "-c",
                                      "sleep 0.5 && echo -n f && sleep 0.5 && echo oo && sleep 1"};
        auto result = execute(std::move(args), [](const CommandResult& commandResult) {
            return android::base::EndsWith(commandResult.stdout, "\n");
            return android::base::EndsWith(commandResult.stdoutStr, "\n");
        });
        auto elapsed = std::chrono::system_clock::now() - now;
        auto elapsedMs = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
@@ -53,7 +53,7 @@ TEST(UtilsHost, ExecuteLongRunning) {

        ASSERT_THAT(result, Ok());
        EXPECT_EQ(std::nullopt, result->exitCode);
        EXPECT_EQ(result->stdout, "foo\n");
        EXPECT_EQ(result->stdoutStr, "foo\n");
    }

    // ~CommandResult() called, child process is killed.
@@ -70,7 +70,7 @@ TEST(UtilsHost, ExecuteLongRunning2) {
        std::vector<std::string> args{"sh", "-c",
                                      "sleep 2 && echo -n f && sleep 2 && echo oo && sleep 2"};
        auto result = execute(std::move(args), [](const CommandResult& commandResult) {
            return android::base::EndsWith(commandResult.stdout, "\n");
            return android::base::EndsWith(commandResult.stdoutStr, "\n");
        });
        auto elapsed = std::chrono::system_clock::now() - now;
        auto elapsedMs = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
@@ -79,7 +79,7 @@ TEST(UtilsHost, ExecuteLongRunning2) {

        ASSERT_THAT(result, Ok());
        EXPECT_EQ(std::nullopt, result->exitCode);
        EXPECT_EQ(result->stdout, "foo\n");
        EXPECT_EQ(result->stdoutStr, "foo\n");
    }

    // ~CommandResult() called, child process is killed.