fix android unit tests and add better macos instructions

This commit is contained in:
John Smith 2022-08-23 10:37:41 -04:00
parent e112cc4527
commit 1793dd90e8
13 changed files with 227 additions and 75 deletions

View File

@ -16,10 +16,13 @@ Development of Veilid on GNU/Linux requires a Debian variant such as Debian
itself, Ubuntu or Mint. Pull requests to support other distributions would be
welcome!
Development requires the Android SDK and NDK be installed.
Running the setup script requires:
* Android SDK and NDK
* Rust
You may decide to use Android Studio to maintain your Android dependencies. If
so, use the dependency manager within your IDE. If you do so, you may skip to
You may decide to use Android Studio [here](https://developer.android.com/studio)
to maintain your Android dependencies. If so, use the dependency manager
within your IDE. If you do so, you may skip to
[Run Veilid setup script](#Run Veilid setup script).
* build-tools;30.0.3
@ -45,8 +48,9 @@ your path.
```shell
cat << EOF >> ~/.profile
export ANDROID_SDK_ROOT=<path to sdk>
export ANDROID_NDK_HOME=<path to ndk>
export PATH=${ANDROID_SDK_ROOT}/platform-tools"
export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/22.0.7026061
export PATH=\$PATH:$ANDROID_SDK_ROOT/platform-tools
EOF
```
#### Run Veilid setup script
@ -60,7 +64,72 @@ pull the remaining Rust dependencies:
### macOS
**TODO**
Development of Veilid on MacOS is possible on both Intel and ARM hardware.
Development requires:
* Xcode, preferably latest version
* Homebrew [here](https://brew.sh)
* Android SDK and NDK
* Java 8
* Rust
You may decide to use Android Studio [here](https://developer.android.com/studio)
to maintain your Android dependencies. If so, use the dependency manager
within your IDE. If you do so, you may skip to
[Run Veilid setup script](#Run Veilid setup script).
* build-tools;30.0.3
* ndk;22.0.7026061
* cmake;3.22.1
#### Setup Java
```shell
brew install openjdk@8
```
and then symlink it as appropriate for your system:
Intel:
```shell
sudo ln -sfn /usr/local/opt/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-8.jdk
```
ARM:
```shell
sudo ln -sfn /opt/homebrew/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-8.jdk
```
#### Setup Dependencies using the CLI
Otherwise, you may choose to use Android `sdkmanager`. Use
the command line to install the requisite package versions: `brew install android-commandlinetools`
```shell
sdkmanager --install "build-tools;30.0.3"
sdkmanager --install "ndk;22.0.7026061"
sdkmanager --install "cmake;3.22.1"
```
Export environment variables and add the Android SDK platform-tools directory to
your path.
```shell
cat << EOF >> ~/.zshenv
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_NDK_HOME=$HOME/Library/Android/sdk/ndk/22.0.7026061
export PATH=\$PATH:$HOME/Library/Android/sdk/platform-tools
EOF
```
#### Run Veilid setup script
Now you may run the MacOS setup script to check your development environment and
pull the remaining Rust dependencies:
```shell
./setup_macos.sh
```
### Windows

View File

@ -14,7 +14,6 @@ else
exit 1
fi
# ensure ANDROID_NDK_HOME is defined and exists
if [ -d "$ANDROID_NDK_HOME" ]; then
echo '[X] $ANDROID_NDK_HOME is defined and exists'
@ -55,8 +54,24 @@ else
exit 1
fi
# ensure rustup is installed
if command -v rustup &> /dev/null; then
echo '[X] rustup is available in the path'
else
echo 'rustup is not available in the path'
exit 1
fi
# ensure cargo is installed
if command -v cargo &> /dev/null; then
echo '[X] cargo is available in the path'
else
echo 'cargo is not available in the path'
exit 1
fi
# install targets
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android wasm32-unknown-unknown
# install cargo packages
cargo install wasm-bindgen-cli

View File

@ -6,17 +6,53 @@ if [ ! "$(uname)" == "Darwin" ]; then
exit 1
fi
# install targets
rustup target add aarch64-apple-darwin aarch64-apple-ios x86_64-apple-darwin x86_64-apple-ios wasm32-unknown-unknown
# ensure ANDROID_SDK_ROOT is defined and exists
if [ -d "$ANDROID_SDK_ROOT" ]; then
echo '[X] $ANDROID_SDK_ROOT is defined and exists'
else
echo '$ANDROID_SDK_ROOT is not defined or does not exist'
exit 1
fi
# install cargo packages
cargo install wasm-bindgen-cli
# ensure ANDROID_NDK_HOME is defined and exists
if [ -d "$ANDROID_NDK_HOME" ]; then
echo '[X] $ANDROID_NDK_HOME is defined and exists'
else
echo '$ANDROID_NDK_HOME is not defined or does not exist'
exit 1
fi
# install bitcode compatible ios toolchain
# echo Manual Step:
# echo install +ios-arm64-1.57.0 toolchain for bitcode from https://github.com/getditto/rust-bitcode/releases/latest and unzip
# echo xattr -d -r com.apple.quarantine .
# echo ./install.sh
# ensure ndk is installed
if [ -f "$ANDROID_NDK_HOME/ndk-build" ]; then
echo '[X] Android NDK is installed at the location $ANDROID_NDK_HOME'
else
echo 'Android NDK is not installed at the location $ANDROID_NDK_HOME'
exit 1
fi
# ensure cmake is installed
if [ -d "$ANDROID_SDK_ROOT/cmake" ]; then
echo '[X] Android SDK CMake is installed'
else
echo 'Android SDK CMake is not installed'
exit 1
fi
# ensure emulator is installed
if [ -d "$ANDROID_SDK_ROOT/emulator" ]; then
echo '[X] Android SDK emulator is installed'
else
echo 'Android SDK emulator is not installed'
exit 1
fi
# ensure adb is installed
if command -v adb &> /dev/null; then
echo '[X] adb is available in the path'
else
echo 'adb is not available in the path'
exit 1
fi
# ensure brew is installed
if command -v brew &> /dev/null; then
@ -34,6 +70,34 @@ else
exit 1
fi
# ensure rustup is installed
if command -v rustup &> /dev/null; then
echo '[X] rustup is available in the path'
else
echo 'rustup is not available in the path'
exit 1
fi
# ensure cargo is installed
if command -v cargo &> /dev/null; then
echo '[X] cargo is available in the path'
else
echo 'cargo is not available in the path'
exit 1
fi
# install targets
rustup target add aarch64-apple-darwin aarch64-apple-ios x86_64-apple-darwin x86_64-apple-ios wasm32-unknown-unknown aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
# install cargo packages
cargo install wasm-bindgen-cli
# install bitcode compatible ios toolchain
# echo Manual Step:
# echo install +ios-arm64-1.57.0 toolchain for bitcode from https://github.com/getditto/rust-bitcode/releases/latest and unzip
# echo xattr -d -r com.apple.quarantine .
# echo ./install.sh
# ensure we have command line tools
xcode-select --install

View File

@ -385,14 +385,6 @@ impl NetworkInterfaces {
inner.interface_address_cache.clone()
}
pub fn with_best_addresses<F, R>(&self, f: F) -> R
where
F: FnOnce(&[IpAddr]) -> R,
{
let inner = self.inner.lock();
f(&inner.interface_address_cache)
}
/////////////////////////////////////////////
fn cache_best_addresses(inner: &mut NetworkInterfacesInner) {

View File

@ -268,9 +268,8 @@ impl Network {
if !from.ip().is_unspecified() {
vec![*from]
} else {
self.unlocked_inner
.interfaces
.best_addresses()
let addrs = self.get_usable_interface_addresses();
addrs
.iter()
.filter_map(|a| {
// We create sockets that are only ipv6 or ipv6 (not dual, so only translate matching unspecified address)
@ -311,11 +310,21 @@ impl Network {
}
}
pub fn with_interface_addresses<F, R>(&self, f: F) -> R
where
F: FnOnce(&[IpAddr]) -> R,
{
self.unlocked_inner.interfaces.with_best_addresses(f)
pub fn is_usable_interface_address(&self, addr: IpAddr) -> bool {
let usable_addrs = self.get_usable_interface_addresses();
usable_addrs.contains(&addr)
}
pub fn get_usable_interface_addresses(&self) -> Vec<IpAddr> {
let addrs = self.unlocked_inner.interfaces.best_addresses();
let addrs: Vec<IpAddr> = addrs
.into_iter()
.filter(|addr| {
let address = Address::from_ip_addr(*addr);
address.is_local() || address.is_global()
})
.collect();
addrs
}
// See if our interface addresses have changed, if so we need to punt the network
@ -591,7 +600,7 @@ impl Network {
{
let mut inner = self.inner.lock();
inner.enable_ipv4 = false;
for addr in self.unlocked_inner.interfaces.best_addresses() {
for addr in self.get_usable_interface_addresses() {
if addr.is_ipv4() {
log_net!(debug "enable address {:?} as ipv4", addr);
inner.enable_ipv4 = true;

View File

@ -332,14 +332,15 @@ impl Network {
}
// See if this public address is also a local interface address we haven't registered yet
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
for ip_addr in ip_addrs {
if pdi_addr.ip() == *ip_addr {
let is_interface_address = (|| {
for ip_addr in self.get_usable_interface_addresses() {
if pdi_addr.ip() == ip_addr {
return true;
}
}
false
});
})();
if !local_dial_info_list.contains(&pdi) && is_interface_address {
routing_table.register_dial_info(
RoutingDomain::LocalNetwork,
@ -428,15 +429,9 @@ impl Network {
}
// See if this public address is also a local interface address
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
for ip_addr in ip_addrs {
if gsa.ip() == *ip_addr {
return true;
}
}
false
});
if !registered_addresses.contains(&gsa.ip()) && is_interface_address {
if !registered_addresses.contains(&gsa.ip())
&& self.is_usable_interface_address(gsa.ip())
{
routing_table.register_dial_info(
RoutingDomain::LocalNetwork,
pdi,
@ -559,15 +554,9 @@ impl Network {
}
// See if this public address is also a local interface address
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
for ip_addr in ip_addrs {
if gsa.ip() == *ip_addr {
return true;
}
}
false
});
if !registered_addresses.contains(&gsa.ip()) && is_interface_address {
if !registered_addresses.contains(&gsa.ip())
&& self.is_usable_interface_address(gsa.ip())
{
routing_table.register_dial_info(
RoutingDomain::LocalNetwork,
pdi,
@ -679,15 +668,7 @@ impl Network {
}
// See if this public address is also a local interface address
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
for ip_addr in ip_addrs {
if pdi_addr.ip() == *ip_addr {
return true;
}
}
false
});
if is_interface_address {
if self.is_usable_interface_address(pdi_addr.ip()) {
routing_table.register_dial_info(
RoutingDomain::LocalNetwork,
pdi,

View File

@ -282,15 +282,12 @@ impl Network {
trace!("network stopped");
}
pub fn with_interface_addresses<F, R>(&self, f: F) -> R
where
F: FnOnce(&[IpAddr]) -> R,
{
f(&[])
pub fn is_usable_interface_address(&self, addr: IpAddr) -> bool {
false
}
pub async fn check_interface_addresses(&self) -> EyreResult<bool> {
Ok(false)
pub fn get_usable_interface_addresses(&self) -> Vec<IpAddr> {
Vec::new()
}
//////////////////////////////////////////

View File

@ -8,14 +8,13 @@
<option name="disableWrapperSourceDistributionNotification" value="true" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8" />
<option name="gradleJvm" value="Embedded JDK" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -0,0 +1,20 @@
#!/bin/bash
# Script adb+
# Usage
# You can run any command adb provide on all your current devices
# ./adb+ <command> is the equivalent of ./adb -s <serial number> <command>
#
# Examples
# ./adb+ version
# ./adb+ install apidemo.apk
# ./adb+ uninstall com.example.android.apis
adb devices | while read line
do
if [ ! "$line" = "" ] && [ `echo $line | awk '{print $2}'` = "device" ]
then
device=`echo $line | awk '{print $1}'`
echo "$device $@ ..."
adb -s $device $@
fi
done

View File

@ -67,6 +67,7 @@ cargo {
targetDirectory = "../../../../../target"
prebuiltToolchains = true
profile = gradle.startParameter.taskNames.any{it.toLowerCase().contains("debug")} ? "debug" : "release"
pythonCommand = "python3"
features {
defaultAnd("android_tests", "rt-tokio")
}

View File

@ -0,0 +1,2 @@
#!/bin/bash
./gradlew installDebug

View File

@ -0,0 +1,3 @@
#!/bin/bash
./adb+.sh uninstall com.veilid.veilidcore.veilidcore_android_tests