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 May 15, 2024
1 parent 3930e39 commit fd431ee
Show file tree
Hide file tree
Showing 17 changed files with 1,777 additions and 2 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"

defaultConfig {
externalNativeBuild {
cmake {
arguments.add("-DANDROID_WEAK_API_DEFS=ON")
}
}
}

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

buildFeatures {
prefab = true
prefabPublishing = true
}

prefab {
create("base") {
headers = "src/main/cpp/include"
}
}
}
4 changes: 4 additions & 0 deletions base/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
16 changes: 16 additions & 0 deletions base/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.22.1)
project(base LANGUAGES CXX)

add_compile_options(-Wall -Werror -Wextra)

add_library(base
STATIC
logging.cpp
stringprintf.cpp
strings.cpp
)

target_include_directories(base
PUBLIC
include
)
42 changes: 42 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,42 @@
/*
* 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>

#include "base/macros.h"

namespace android {
namespace base {

class ErrnoRestorer {
public:
ErrnoRestorer() : saved_errno_(errno) {}

~ErrnoRestorer() { errno = saved_errno_; }

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

private:
const int saved_errno_;

DISALLOW_COPY_AND_ASSIGN(ErrnoRestorer);
};

} // namespace base
} // namespace android
Loading

0 comments on commit fd431ee

Please sign in to comment.