Skip to content

Commit 7c60318

Browse files
committed
Import a subset of libbase, build an AAR.
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?
1 parent d01efda commit 7c60318

File tree

12 files changed

+1127
-0
lines changed

12 files changed

+1127
-0
lines changed

base/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

base/build.gradle.kts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
plugins {
2+
id("ndksamples.android.library")
3+
}
4+
5+
android {
6+
namespace = "com.android.ndk.samples.base"
7+
8+
externalNativeBuild {
9+
cmake {
10+
path = file("src/main/cpp/CMakeLists.txt")
11+
}
12+
}
13+
14+
buildFeatures {
15+
prefabPublishing = true
16+
}
17+
18+
prefab {
19+
create("base") {
20+
headers = "src/main/cpp/include"
21+
}
22+
}
23+
}
24+
25+
dependencies {
26+
27+
implementation(libs.appcompat)
28+
implementation(libs.material)
29+
testImplementation(libs.junit)
30+
androidTestImplementation(libs.ext.junit)
31+
androidTestImplementation(libs.espresso.core)
32+
}

base/src/main/cpp/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.22.1)
2+
project(Base LANGUAGES CXX)
3+
4+
add_compile_options(-Wall -Werror -Wextra)
5+
6+
add_library(base
7+
STATIC
8+
logging.cpp
9+
)
10+
11+
target_compile_features(base PRIVATE cxx_std_23)
12+
target_compile_options(base PRIVATE -Wno-vla-cxx-extension)
13+
target_include_directories(base PUBLIC include)
14+
target_link_libraries(base PUBLIC log)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2020 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <errno.h>
20+
21+
namespace ndksamples::base {
22+
23+
class ErrnoRestorer {
24+
public:
25+
ErrnoRestorer() : saved_errno_(errno) {}
26+
ErrnoRestorer(const ErrnoRestorer&) = delete;
27+
28+
~ErrnoRestorer() { errno = saved_errno_; }
29+
30+
ErrnoRestorer& operator=(const ErrnoRestorer&) = delete;
31+
32+
// Allow this object to be used as part of && operation.
33+
explicit operator bool() const { return true; }
34+
35+
private:
36+
const int saved_errno_;
37+
};
38+
39+
} // namespace ndksamples::base

0 commit comments

Comments
 (0)