Skip to content

Commit

Permalink
Import a subset of libbase, build an AAR.
Browse files Browse the repository at this point in the history
It's still quite a lot for just CHECK, LOG, and
DISALLOW_COPY_AND_ASSIGN. The strings stuff is only needed because r26
is too old to have the stdlib string split/starts_with/etc. Maybe I'll
end up wanting more later and this is a worthwhile start?
  • Loading branch information
DanAlbert committed Jun 11, 2024
1 parent d01efda commit 7c60318
Show file tree
Hide file tree
Showing 12 changed files with 1,127 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions base/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins {
id("ndksamples.android.library")
}

android {
namespace = "com.android.ndk.samples.base"

externalNativeBuild {
cmake {
path = file("src/main/cpp/CMakeLists.txt")
}
}

buildFeatures {
prefabPublishing = true
}

prefab {
create("base") {
headers = "src/main/cpp/include"
}
}
}

dependencies {

implementation(libs.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
}
14 changes: 14 additions & 0 deletions base/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.22.1)
project(Base LANGUAGES CXX)

add_compile_options(-Wall -Werror -Wextra)

add_library(base
STATIC
logging.cpp
)

target_compile_features(base PRIVATE cxx_std_23)
target_compile_options(base PRIVATE -Wno-vla-cxx-extension)
target_include_directories(base PUBLIC include)
target_link_libraries(base PUBLIC log)
39 changes: 39 additions & 0 deletions base/src/main/cpp/include/base/errno_restorer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2020 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.
*/

#pragma once

#include <errno.h>

namespace ndksamples::base {

class ErrnoRestorer {
public:
ErrnoRestorer() : saved_errno_(errno) {}
ErrnoRestorer(const ErrnoRestorer&) = delete;

~ErrnoRestorer() { errno = saved_errno_; }

ErrnoRestorer& operator=(const ErrnoRestorer&) = delete;

// Allow this object to be used as part of && operation.
explicit operator bool() const { return true; }

private:
const int saved_errno_;
};

} // namespace ndksamples::base
Loading

0 comments on commit 7c60318

Please sign in to comment.