Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/android_x86.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Android CI x86

on: [push]

jobs:
build:

runs-on: macOS-latest

steps:
- uses: actions/checkout@v1
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Install Swift toolchain 5.0.3
run: wget https://swift.org/builds/swift-5.0.3-release/xcode/swift-5.0.3-RELEASE/swift-5.0.3-RELEASE-osx.pkg;
sudo installer -pkg swift-5.0.3-RELEASE-osx.pkg -target /
- name: Install NDK
run: wget https://dl.google.com/android/repository/android-ndk-r17c-darwin-x86_64.zip;
unzip android-ndk-r17c-darwin-x86_64.zip
- name: Install Swift Android Toolchain
run: SWIFT_ANDROID=$(curl -fsSL https://api.bintray.com/packages/readdle/swift-android-toolchain/swift-android-toolchain/versions/_latest | python -c 'import json,sys;print(json.load(sys.stdin))["name"]');
wget https://dl.bintray.com/readdle/swift-android-toolchain/swift-android-$SWIFT_ANDROID.zip;
unzip swift-android-$SWIFT_ANDROID.zip;
swift-android-$SWIFT_ANDROID/bin/swift-android tools --update;
ln -sfn swift-android-$SWIFT_ANDROID swift-android-current
- name: Download Android Emulator
run: $ANDROID_HOME/tools/bin/sdkmanager "system-images;android-29;google_apis;x86"
- name: Create Android Emulator
run: $ANDROID_HOME/tools/bin/avdmanager create avd -n ci-test -k "system-images;android-29;google_apis;x86" -d "pixel" --force
- name: Start Android Emulator
run: $ANDROID_HOME/emulator/emulator -no-window -avd ci-test -noaudio > /dev/null &
- name: Run connected android tests
run: export TOOLCHAINS=org.swift.50320190830a;
export ANDROID_NDK_HOME=$(pwd)/android-ndk-r17c;
export SWIFT_ANDROID_HOME=$(pwd)/swift-android-current;
export PATH=$ANDROID_NDK_HOME:$PATH;
export PATH=$SWIFT_ANDROID_HOME/bin:$SWIFT_ANDROID_HOME/build-tools/current:$PATH;
adb wait-for-device;
./gradlew sample:cAT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Android CI
name: Android CI x86_64

on: [push]

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.4.21'

repositories {
google()
Expand All @@ -9,8 +9,8 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "com.readdle.android.swift:gradle:1.3.2"
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "com.readdle.android.swift:gradle:1.3.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
Expand Down
2 changes: 1 addition & 1 deletion compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ archivesBaseName = "compiler"

dependencies {
implementation project(':library')
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.code.gson:gson:2.8.6'
}

apply from: rootProject.file('bintray-publish.gradle')
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ public void generateCode(SwiftWriter swiftWriter, String javaFullName, String sw

String retType = "";
if (returnSwiftType != null) {
retType = " -> " + returnSwiftType.javaSigType(isReturnTypeOptional) + "?";
retType = " -> " + returnSwiftType.javaSigType(isReturnTypeOptional);
if (isReturnTypeOptional || !returnSwiftType.isPrimitiveType()) {
retType += "?";
}
}

swiftWriter.emit(String.format(")%s {\n", retType));
Expand All @@ -75,7 +78,12 @@ public void generateCode(SwiftWriter swiftWriter, String javaFullName, String sw
swiftWriter.emitStatement("}");
swiftWriter.emitStatement("catch {");
Utils.handleRuntimeError(swiftWriter);
swiftWriter.emitStatement(String.format("return%s", returnSwiftType != null ? " nil" : ""));
if (!isReturnTypeOptional && returnSwiftType.isPrimitiveType()) {
swiftWriter.emitStatement("return " + returnSwiftType.primitiveDefaultValue());
}
else {
swiftWriter.emitStatement("return nil");
}
swiftWriter.emitStatement("}");
}

Expand All @@ -96,7 +104,12 @@ public void generateCode(SwiftWriter swiftWriter, String javaFullName, String sw
swiftWriter.emitStatement("}");
swiftWriter.emitStatement("catch {");
Utils.handleRuntimeError(swiftWriter);
swiftWriter.emitStatement("return nil");
if (!isReturnTypeOptional && returnSwiftType.isPrimitiveType()) {
swiftWriter.emitStatement("return " + returnSwiftType.primitiveDefaultValue());
}
else {
swiftWriter.emitStatement("return nil");
}
swiftWriter.emitStatement("}");
}

Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
GROUP=com.readdle.swift.java.codegen
VERSION_NAME=0.9.0
VERSION_NAME=0.9.1

org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true
29 changes: 21 additions & 8 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ swift {
useKapt true
cleanEnabled true
debug {
abiFilters("x86_64")
extraBuildFlags("-Xswiftc", "-DDEBUG")
}
}
Expand All @@ -22,7 +21,7 @@ android {
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
javaCompileOptions {
annotationProcessorOptions {
arguments = ["com.readdle.codegen.package": """{
Expand All @@ -39,8 +38,22 @@ android {
}
buildTypes {
release {
debuggable false
jniDebuggable false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
shrinkResources false
ndk {
abiFilters = ["armeabi-v7a", "arm64-v8a", "x86", "x86_64"]
}
}
debug {
debuggable true
jniDebuggable true
minifyEnabled false
shrinkResources false
ndk {
abiFilters = ["x86", "x86_64"]
}
}
}

Expand Down Expand Up @@ -68,10 +81,10 @@ dependencies {
kapt project(':compiler')
implementation project(':library')

implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'com.android.support:support-annotations:28.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;
import com.readdle.codegen.anotation.SwiftRuntimeError;
Expand Down Expand Up @@ -29,9 +29,11 @@ public void testZero() {
public void testMin() {
try {
Assert.assertEquals(IntTest.testMin(), Integer.MIN_VALUE);
Assert.fail();
}
catch (Exception e) {
if (SwiftEnvironment.is64BitArch()) {
// Only on 64 bit arch there is not enough bytes to represent system Int.min
Assert.fail();
}
} catch (Exception e) {
Assert.assertTrue(e instanceof SwiftRuntimeError);
Assert.assertEquals(e.getMessage(), "Invalid value \"" + Long.MIN_VALUE + "\": Not enough bits to represent Int []");
}
Expand All @@ -41,7 +43,10 @@ public void testMin() {
public void testMax() {
try {
Assert.assertEquals(IntTest.testMax(), Integer.MAX_VALUE);
Assert.fail();
if (SwiftEnvironment.is64BitArch()) {
// Only on 64 bit arch there is not enough bytes to represent system Int.maxå
Assert.fail();
}
}
catch (Exception e) {
Assert.assertTrue(e instanceof SwiftRuntimeError);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.readdle.swiftjava.sample

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.readdle.codegen.anotation.JavaSwift
import com.readdle.swiftjava.sample.SwiftEnvironment.Companion.initEnvironment
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class Issue31Tests {

@Before
fun setUp() {
System.loadLibrary("SampleAppCore")
JavaSwift.init()
initEnvironment()
}

@Test
fun testValueTypeNanBug() {
val progress = Issue31TestProgress(elapsed = 8, total = 8)
Assert.assertNotEquals(Double.NaN, progress.percentage)
Assert.assertNotEquals(Double.NaN, progress.calculatePercentage())
}

@Test
fun testReferenceTypeNanBug() {
val progress = Issue31ReferenceTestProgress.init(elapsed = 8, total = 8)
Assert.assertNotEquals(Double.NaN, progress.percentage)
Assert.assertNotEquals(Double.NaN, progress.calculatePercentage())
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.readdle.swiftjava.sample;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;
import com.readdle.codegen.anotation.SwiftError;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample

import android.support.test.runner.AndroidJUnit4
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.readdle.codegen.anotation.JavaSwift
import com.readdle.codegen.anotation.SwiftError
import com.readdle.swiftjava.sample.SampleValue.Companion.funcThrows
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;
import com.readdle.codegen.anotation.SwiftRuntimeError;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.readdle.swiftjava.sample;

import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.readdle.codegen.anotation.JavaSwift;
import com.readdle.codegen.anotation.SwiftRuntimeError;
Expand Down Expand Up @@ -37,7 +37,10 @@ public void testMin() {
public void testMax() {
try {
Assert.assertEquals(UIntTest.testMax(), MAX_VALUE);
Assert.fail();
if (SwiftEnvironment.is64BitArch()) {
// Only on 64 bit arch there is not enough bytes to represent system UInt.max
Assert.fail();
}
}
catch (Exception e) {
Assert.assertTrue(e instanceof SwiftRuntimeError);
Expand Down
Loading