Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Citest #84

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
62 changes: 51 additions & 11 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,54 @@ jobs:
outputs:
matrix: ${{ steps.setup-matrix.outputs.matrix }}

samples:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
sample:
- samples/app
- samples/library

steps:
# Checks-out your repository under $GITHUB_WORKSPACE for the job.
- uses: actions/checkout@v2

- name: Setup Rust
run: |
rustup toolchain install stable
rustup target add x86_64-linux-android
rustup target add x86_64-unknown-linux-gnu
rustup target add aarch64-linux-android

- name: Setup Java 11
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: 11
cache: 'gradle'

- name: ${{ matrix.sample }}
run: |
./gradlew -p ${{ matrix.sample }} :assembleDebug --info --warning-mode all

android_unversioned_tests:
# The type of runner that the job will run on
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest

steps:
# Checks-out your repository under $GITHUB_WORKSPACE for the job.
Expand Down Expand Up @@ -65,27 +110,22 @@ jobs:
needs: [generate_versions] # , sanity_check]

# The type of runner that the job will run on
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
androidTestTask: ${{ fromJson(needs.generate_versions.outputs.matrix) }}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# # Sets up the NDK required by AGP 3.6.x
# - name: Setup NDK
# run: sudo $ANDROID_HOME/tools/bin/sdkmanager 'ndk;20.0.5594570'

# - name: Install Rustup
# run: |
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none
# echo "$HOME/.cargo/bin" >> $GITHUB_PATH

- name: Setup Rust
run: |
rustup toolchain install stable
Expand Down
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,28 @@ $ ls -al build/local-repo/org/mozilla/rust-android-gradle/org.mozilla.rust-andro
build/local-repo/org/mozilla/rust-android-gradle/org.mozilla.rust-android-gradle.gradle.plugin/0.4.0/org.mozilla.rust-android-gradle.gradle.plugin-0.4.0.pom
```

# Testing Local changes
## Sample projects

The easiest way to get started is to run the sample projects. The sample projects have dependency
substitutions configured so that changes made to `plugin/` are reflected in the sample projects
immediately.

```
$ ./gradlew -p samples/library :assembleDebug
...
$ file samples/library/build/outputs/aar/library-debug.aar
samples/library/build/outputs/aar/library-debug.aar: Zip archive data, at least v1.0 to extract
```

```
$ ./gradlew -p samples/app :assembleDebug
...
$ file samples/app/build/outputs/apk/debug/app-debug.apk
samples/app/build/outputs/apk/debug/app-debug.apk: Zip archive data, at least v?[0] to extract
```

## Testing Local changes

An easy way to locally test changes made in this plugin is to simply add this to your project's `settings.gradle`:

```gradle
Expand Down Expand Up @@ -545,17 +566,6 @@ Publishing artifact build/publish-generated-resources/pom.xml
Activating plugin org.mozilla.rust-android-gradle.rust-android version 0.8.1
```

## Sample projects

To run the sample projects:

```
$ ./gradlew -p samples/library :assembleDebug
...
$ ls -al samples/library/build/outputs/aar/library-debug.aar
-rw-r--r-- 1 nalexander staff 8926315 18 Sep 10:22 samples/library/build/outputs/aar/library-debug.aar
```

## Real projects

To test in a real project, use the local Maven repository in your `build.gradle`, like:
Expand Down
10 changes: 9 additions & 1 deletion plugin/src/test/groovy/com/nishtahir/NdkVersionTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ class NdkVersionTest extends AbstractTest {
.build()
.writeProject()

// To ease debugging.
temporaryFolder.root.eachFileRecurse {
System.err.println("before> ${it}")
if (it.path.endsWith(".gradle")) {
System.err.println(it.text)
}
}

when:
BuildResult buildResult = withGradleVersion(TestVersions.latestSupportedGradleVersionFor(androidVersion).version)
.withProjectDir(temporaryFolder.root)
Expand All @@ -36,7 +44,7 @@ class NdkVersionTest extends AbstractTest {

// To ease debugging.
temporaryFolder.root.eachFileRecurse {
println(it)
System.err.println("after> ${it}")
}

then:
Expand Down
19 changes: 13 additions & 6 deletions plugin/src/test/groovy/com/nishtahir/SimpleCargoProject.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,31 @@ class SimpleCargoProject {
}

def writeProject() {
def cargoModule = this.class.classLoader.getResource("rust/Cargo.toml").path
cargoModule = new File(cargoModule).parent
def cargoModuleFile = new File(this.class.classLoader.getResource("rust/Cargo.toml").path).parentFile
def targetDirectoryFile = new File(cargoModuleFile.parentFile, "target")

// On Windows, path components are backslash-separated. We need to
// express the path as Groovy source, which means backslashes need to be
// escaped. The easiest way is to replace backslashes with forward
// slashes.
def module = cargoModuleFile.path.replace("\\", "/")
def targetDirectory = targetDirectoryFile.path.replace("\\", "/")

def targetStrings = targets.collect({"\"${it}\"" }).join(", ")

file('app/build.gradle') << """
cargo {
module = "${cargoModule}"
targetDirectory = "${cargoModule}/../target"
module = "${module}"
targetDirectory = "${targetDirectory}"
targets = [${targetStrings}]
libname = "rust"
}
""".stripIndent()

file('library/build.gradle') << """
cargo {
module = "${cargoModule}"
targetDirectory = "${cargoModule}/../target"
module = "${module}"
targetDirectory = "${targetDirectory}"
targets = [${targetStrings}]
libname = "rust"
}
Expand Down
8 changes: 5 additions & 3 deletions samples/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.agp_version = '4.1.0'
ext.agp_version = '7.0.0'
repositories {
google()
maven {
Expand All @@ -17,6 +17,8 @@ apply plugin: 'org.mozilla.rust-android-gradle.rust-android'

android {
compileSdkVersion 27
ndkVersion "23.1.7779620"

defaultConfig {
applicationId "com.nishtahir.androidrust"
minSdkVersion 21
Expand All @@ -31,17 +33,17 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
ndkVersion "20.1.5948944"
}

cargo {
module = "../rust"
targets = ["arm", "x86", "x86_64", "arm64"]
targets = ["x86_64", "arm64"]
libname = "rust"
}

repositories {
google()
mavenCentral()
}

dependencies {
Expand Down
6 changes: 4 additions & 2 deletions samples/library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
buildscript {
ext.agp_version = '7.0.0'
repositories {
google()
maven {
Expand All @@ -16,6 +17,7 @@ apply plugin: 'org.mozilla.rust-android-gradle.rust-android'

android {
compileSdkVersion 27
ndkVersion "23.1.7779620"

defaultConfig {
minSdkVersion 21
Expand All @@ -24,7 +26,6 @@ android {
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
Expand All @@ -36,7 +37,7 @@ android {

cargo {
module = "../rust"
targets = ["arm", "x86", "x86_64", "arm64"]
targets = ["x86_64", "arm64"]
libname = "rust"

features {
Expand All @@ -52,6 +53,7 @@ cargo {

repositories {
google()
mavenCentral()
}

dependencies {
Expand Down