Skip to content

Commit

Permalink
- integrate tmux
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhoavn committed May 28, 2020
1 parent 114a4cd commit 58a9b54
Show file tree
Hide file tree
Showing 11 changed files with 427 additions and 4 deletions.
4 changes: 4 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Released under [the GPLv3 license](https://www.gnu.org/licenses/gpl.html).

- Contains code from `termux-app` by which is released under GPLv3.
- Contains binary from `code-server` by which is released under MIT License.
77 changes: 76 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
ndkVersion '21.1.6352462'

defaultConfig {
applicationId "vn.vhn.vhscode"
applicationId "vn.vhn.vsc"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"

externalNativeBuild {
ndkBuild {
cFlags "-std=c11", "-Wall", "-Wextra", "-Werror", "-Os", "-fno-stack-protector", "-Wl,--gc-sections"
}
}

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

ndk {
Expand All @@ -31,6 +38,12 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

externalNativeBuild {
ndkBuild {
path "src/main/cpp/Android.mk"
}
}
}

dependencies {
Expand All @@ -46,3 +59,65 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

def downloadBootstrap(String arch, String expectedChecksum, int version) {
def digest = java.security.MessageDigest.getInstance("SHA-256")

def localUrl = "src/main/cpp/bootstrap-" + arch + ".zip"
def file = new File(projectDir, localUrl)
if (file.exists()) {
def buffer = new byte[8192]
def input = new FileInputStream(file)
while (true) {
def readBytes = input.read(buffer)
if (readBytes < 0) break
digest.update(buffer, 0, readBytes)
}
def checksum = new BigInteger(1, digest.digest()).toString(16)
if (checksum == expectedChecksum) {
return
} else {
logger.quiet("Deleting old local file with wrong hash: " + localUrl)
file.delete()
}
}

def remoteUrl = "https://bintray.com/termux/bootstrap/download_file?file_path=bootstrap-" + arch + "-v" + version + ".zip"
logger.quiet("Downloading " + remoteUrl + " ...")

file.parentFile.mkdirs()
def out = new BufferedOutputStream(new FileOutputStream(file))

def connection = new URL(remoteUrl).openConnection()
connection.setInstanceFollowRedirects(true)
def digestStream = new java.security.DigestInputStream(connection.inputStream, digest)
out << digestStream
out.close()

def checksum = new BigInteger(1, digest.digest()).toString(16)
if (checksum != expectedChecksum) {
file.delete()
throw new GradleException("Wrong checksum for " + remoteUrl + ": expected: " + expectedChecksum + ", actual: " + checksum)
}
}

clean {
doLast {
def tree = fileTree(new File(projectDir, 'src/main/cpp'))
tree.include 'bootstrap-*.zip'
tree.each { it.delete() }
}
}

task downloadBootstraps(){
doLast {
def version = 22
downloadBootstrap("aarch64", "d00cd85b773202924e0256af25c521744fcfa845a1120ecffe685a4a0baf44d6", version)
}
}

afterEvaluate {
android.applicationVariants.all { variant ->
variant.javaCompileProvider.get().dependsOn(downloadBootstraps)
}
}
5 changes: 5 additions & 0 deletions app/src/main/cpp/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libtermux-bootstrap
LOCAL_SRC_FILES := termux-bootstrap-zip.S termux-bootstrap.c
include $(BUILD_SHARED_LIBRARY)
Binary file added app/src/main/cpp/bootstrap-aarch64.zip
Binary file not shown.
18 changes: 18 additions & 0 deletions app/src/main/cpp/termux-bootstrap-zip.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.global blob
.global blob_size
.section .rodata
blob:
#if defined __i686__
.incbin "bootstrap-i686.zip"
#elif defined __x86_64__
.incbin "bootstrap-x86_64.zip"
#elif defined __aarch64__
.incbin "bootstrap-aarch64.zip"
#elif defined __arm__
.incbin "bootstrap-arm.zip"
#else
# error Unsupported arch
#endif
1:
blob_size:
.int 1b - blob
11 changes: 11 additions & 0 deletions app/src/main/cpp/termux-bootstrap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <jni.h>

extern jbyte blob[];
extern int blob_size;

JNIEXPORT jbyteArray JNICALL Java_com_termux_app_TermuxInstaller_getZip(JNIEnv *env, __attribute__((__unused__)) jobject This)
{
jbyteArray ret = (*env)->NewByteArray(env, blob_size);
(*env)->SetByteArrayRegion(env, ret, 0, blob_size, blob);
return ret;
}
Loading

0 comments on commit 58a9b54

Please sign in to comment.