diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9de938d3..381e0ff3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,11 @@ on: jobs: natives-linux-windows: name: Linux (x86/ARM/PPC) and Windows native library compilation - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + container: + image: ubuntu:18.04 + env: + GCC: gcc-8 defaults: run: @@ -14,15 +18,20 @@ jobs: steps: - name: Checkout the target branch - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup Java - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: temurin java-version: 8 + # Don't need the dependency cache here (or in any of the other native + # library compilation steps), because we're not invoking the Java + # compiler in this step. We only need the JDK for its headers. - name: Install build prerequisites run: | - sudo apt update - sudo make crosstools + apt-get update + apt-get --assume-yes install make $GCC + make crosstools - name: Build the Linux and Windows native libraries run: | @@ -33,25 +42,25 @@ jobs: # exactly to the directories inside `src/main/c/resources/native`. That # way, the Java build job can pull down all artifacts and unpack them # into that directory to overwrite the versions in-repo. This is sadly - # necessary because the actions/download-artifact@v2 action flattens + # necessary because the actions/download-artifact@v3 action flattens # paths inside artifacts. If it retained full relative paths, we could # put Linux and Windows natives inside the same artifact, and we could be # flexible with the artifact names. But it doesn't, so we can't, and we # can't. - name: Upload Linux native libraries - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: linux path: src/main/c/resources/native/linux - name: Upload Windows native libraries - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: windows path: src/main/c/resources/native/windows natives-macos: name: macOS native library compilation - runs-on: macos-10.15 + runs-on: macos-latest defaults: run: @@ -59,10 +68,11 @@ jobs: steps: - name: Checkout the target branch - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup Java - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: temurin java-version: 8 - name: Build the macOS native libraries @@ -71,18 +81,16 @@ jobs: make osx - name: Upload macOS native libraries - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: osx path: src/main/c/resources/native/osx/libNRJavaSerial.jnilib natives-freebsd: name: FreeBSD native library compilation - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest container: - image: empterdose/freebsd-cross-build:9.3 - env: - JAVA_HOME: /usr/lib/jvm/default-jvm + image: empterdose/freebsd-cross-build:11.4 defaults: run: @@ -90,30 +98,35 @@ jobs: steps: - name: Checkout the target branch - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 8 + - name: Fake the FreeBSD Java headers # This feels extremely dirty, but the only native header we care about # is `jni_md.h`, and it is exactly identical between Linux and FreeBSD # (at least in OpenJDK 8). run: | - apk add openjdk8 ln -s $JAVA_HOME/include/linux $JAVA_HOME/include/freebsd - name: Build the FreeBSD native libraries run: | make clean-freebsd - settarget i386-freebsd9 make freebsd32 - settarget x86_64-freebsd9 make freebsd64 + settarget i386-freebsd11 make freebsd32 + settarget x86_64-freebsd11 make freebsd64 + settarget arm64-freebsd11 make freebsdarm64v8 - name: Upload FreeBSD native libraries - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: freebsd path: src/main/c/resources/native/freebsd java: name: Java compilation - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest needs: - natives-linux-windows @@ -126,18 +139,20 @@ jobs: # don't regress formatting when compared with the master branch, we need # to have a local copy of the master branch for comparison. - name: Checkout the master branch - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: master - name: Checkout the target branch - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup Java - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: temurin java-version: 8 + cache: gradle - name: Download native libraries - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: path: src/main/c/resources/native @@ -146,9 +161,9 @@ jobs: - name: Determine commit hash for artifact filename id: vars - run: echo "::set-output name=short-rev::$(git rev-parse --short HEAD)" + run: echo "short-rev=$(git rev-parse --short HEAD)" >>$GITHUB_OUTPUT - name: Upload build artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: nrjavaserial-${{steps.vars.outputs.short-rev}} path: build/libs/*.jar diff --git a/README.md b/README.md index b7425ad9..34a00e6f 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,13 @@ ease of use and embeddability in other libraries. The resulting JAR will be found in the `build/libs/` directory. +Optionally, you can publish (“install”) your new build +into your local Maven repository (`~/.m2/repository`). +That way, you easily can consume your own build of the library +from other locally-built Maven/Gradle projects. + + $ ./gradlew publishToMavenLocal + # Building the native libraries The native libraries are written in C, diff --git a/build.gradle b/build.gradle index a073dac8..7994d5ce 100644 --- a/build.gradle +++ b/build.gradle @@ -1,80 +1,97 @@ plugins { - id "biz.aQute.bnd.builder" version "5.0.1" - id "com.diffplug.spotless" version "5.9.0" + id 'base' + // The application of the Bnd plugin triggers a Gradle warning: + // + // The AbstractTask.getConvention() method has been deprecated. This is + // scheduled to be removed in Gradle 9.0. Consult the upgrading guide + // for further information: https://docs.gradle.org/8.3/userguide/ + // upgrading_version_8.html#deprecated_access_to_conventions + // + // This warning is caused by Bnd itself, and there is nothing we can do + // about it in our own configuration. This will be resolved [in Bnd v7.0]. + // + // [in Bnd v7.0]: https://github.com/bndtools/bnd/issues/5714#issuecomment-1635684935 + id 'biz.aQute.bnd.builder' version '6.4.0' + // This is the [last version] of Spotless which runs on Java 8. Even though + // our toolchain configuration allows us to run Gradle on a higher Java + // version than we use to build, Java 8 is a pretty fixed target, so as + // long as we're not able to take advantage of any newer language features, + // we're probably not losing much by sticking with an older linter. + // + // [last version]: https://github.com/diffplug/spotless/issues/1337 + // [toolchain]: https://docs.gradle.org/current/userguide/toolchains.html + id 'com.diffplug.spotless' version '6.13.0' + id 'eclipse' + id 'java' + id 'maven-publish' + id 'signing' } -apply plugin: 'java' -apply plugin: 'eclipse' -apply plugin: 'maven' -apply plugin: 'signing' - [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' -File buildDir = file("."); +File buildDir = file('.'); Properties props = new Properties() -props.load(new FileInputStream(buildDir.getAbsolutePath() + "/src/main/resources/com/neuronrobotics/nrjavaserial/build.properties")) +props.load(new FileInputStream("${buildDir.getAbsolutePath()}/src/main/resources/com/neuronrobotics/nrjavaserial/build.properties")) -group = "com.neuronrobotics" -archivesBaseName = "nrjavaserial" -version = props."app.version" +group = 'com.neuronrobotics' +base.archivesName = props.'app.name' +version = props.'app.version' sourceSets { test { java { - srcDirs = ["test/src"] + srcDirs = ['test/src'] } } main { resources { - srcDirs = ["src/main/resources", "src/main/c/resources"] - includes = ["**/*.so","**/*.dll", "**/*.jnilib","**/*.properties"] + srcDirs = ['src/main/resources', 'src/main/c/resources'] + includes = ['**/*.so','**/*.dll', '**/*.jnilib', '**/*.properties'] } } } -jar.archiveName = "nrjavaserial-${props.'app.version'}.jar" - repositories { mavenCentral() - jcenter() } dependencies { - compile fileTree(dir: 'libs', includes: ['*.jar']) - testCompile 'junit:junit:4.12' - compile 'commons-net:commons-net:3.9.0' + testImplementation 'junit:junit:4.12' + implementation 'commons-net:commons-net:3.9.0' compileOnly 'net.java.dev.jna:jna:4.4.0' compileOnly 'net.java.dev.jna:jna-platform:4.4.0' } -jar { - jar.duplicatesStrategy = DuplicatesStrategy.EXCLUDE - - bnd("Created-By": "Commonwealth Robotics Cooperative", - "Specification-Title": props."app.name", - "Specification-Version": props."app.version", - "Specification-Vendor": "Commonwealth Robotics Cooperative", - "Implementation-Title": props."app.name", - "Implementation-Version" : props."app.version", - "Implementation-Vendor": "Commonwealth Robotics Cooperative", - "Import-Package": "com.sun.jna.platform.win32;resolution:=optional,org.apache.commons.net.telnet;resolution:=optional,!gnu.io*,*", - "Export-Package": "gnu.io*" - ) - -} +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } -task javadocJar(type: Jar) { - classifier = 'javadoc' - from javadoc + withJavadocJar() + withSourcesJar() } -task sourcesJar(type: Jar) { - classifier = 'sources' - from (sourceSets.main.allSource) { - exclude 'native/' +jar { + bundle { + bnd( + 'Specification-Title': props.'app.name', + 'Specification-Version': props.'app.version', + 'Specification-Vendor': 'Commonwealth Robotics Cooperative', + 'Implementation-Title': props.'app.name', + 'Implementation-Version' : props.'app.version', + 'Implementation-Vendor': 'Commonwealth Robotics Cooperative', + 'Import-Package': 'com.sun.jna.platform.win32;resolution:=optional,org.apache.commons.net.telnet;resolution:=optional,!gnu.io*,*', + 'Export-Package': 'gnu.io*', + ) } } +// withSourcesJar() creates the sourcesJar task which, by default, packages +// sourceSets.main.allSource. Including native libraries in this source set is +// the easiest way to include them the final library archive, but we don't want +// an extra half meg of binaries to be included in the source archive. +sourcesJar.exclude('native/') + spotless { enforceCheck false ratchetFrom 'origin/master' @@ -93,84 +110,146 @@ spotless { eclipse() } } -/* -signing { - required { - gradle.taskGraph.hasTask("uploadArchives") - } - sign configurations.archives -} -artifacts { - archives javadocJar - archives sourcesJar - archives jar -} - -//import org.gradle.plugins.signing.Sign -// -//gradle.taskGraph.whenReady { taskGraph -> -// if (taskGraph.allTasks.any { it instanceof Sign }) { -// // Use Java 6's console to read from the console (no good for -// // a CI environment) -// Console console = System.console() -// console.printf "\n\nWe have to sign some things in this build." + -// "\n\nPlease enter your signing details.\n\n" +// You can provide OSSRH publication credentials in three ways. Either: // -// def id = console.readLine("PGP Key Id: ") -// def file = console.readLine("PGP Secret Key Ring File (absolute path): ") -// def password = console.readPassword("PGP Private Key Password: ") +// 1. Pass the username and password properties – ossrhUsername and +// ossrhPassword – on the command line: // -// allprojects { ext."signing.keyId" = id } -// allprojects { ext."signing.secretKeyRingFile" = file } -// allprojects { ext."signing.password" = password } +// ./gradlew ... -PossrhUsername=username -PossrhPassword=password // -// console.printf "\nThanks.\n\n" -// } -//} +// 2. Configure those properties in ~/.gradle/gradle.properties. +// 3. Set the OSSRHUSERNAME and OSSRHPASSWORD environment variables to the +// username and password, respectively. +publishing { + def ossrhUsername = findProperty('ossrhUsername') + def ossrhPassword = findProperty('ossrhPassword') + + if (System.env.OSSRHUSERNAME && System.env.OSSRHPASSWORD) { + ossrhUsername = System.env.OSSRHUSERNAME + ossrhPassword = System.env.OSSRHPASSWORD + } -uploadArchives { repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { - authentication(userName: ossrhUsername, password: ossrhPassword) + // A Nexus Repository instance running on localhost. Useful for + // debugging the publishing process. Named “localhost”, not “local”, to + // avoid confusion with the publishToMavenLocal task, which publishes + // to the local Maven cache at ~/.m2/repository. + maven { + name = 'localhost' + url = 'http://localhost:8081/repository/maven-releases/' + allowInsecureProtocol = true + credentials { + username = ossrhUsername + password = ossrhPassword + } } - snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { - authentication(userName: ossrhUsername, password: ossrhPassword) + maven { + name = 'ossrh' + url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' + credentials { + username = ossrhUsername + password = ossrhPassword + } } + maven { + name = 'ossrhSnapshots' + url = 'https://oss.sonatype.org/content/repositories/snapshots/' + credentials { + username = ossrhUsername + password = ossrhPassword + } + } + } - pom.project { - name 'NRJavaSerial' - packaging 'jar' - description 'A fork of the RXTX library with a focus on ease of use and embeddability in other libraries.' - url 'http://neuronrobotics.com' + publications { + nrJavaSerial(MavenPublication) { + pom { + // By default, the artifact ID is derived from the name of the + // directory housing this file. If we don't specifically + // override that, we'll end up with an unexpected artifact ID + // if the project directory is called something other than + // “nrjavaserial”. + artifactId = props.'app.name' + name = 'NRJavaSerial' + description = 'A fork of the RXTX library with a focus on ease of use and embeddability in other libraries.' + url = 'https://nrjs.org' + + from components.java scm { - connection 'scm:git:https://github.com/NeuronRobotics/nrjavaserial.git' - developerConnection 'scm:git:git@github.com:NeuronRobotics/nrjavaserial.git' - url 'https://github.com/NeuronRobotics/nrjavaserial' + connection = 'scm:git:https://github.com/NeuronRobotics/nrjavaserial.git' + developerConnection = 'scm:git:git@github.com:NeuronRobotics/nrjavaserial.git' + url = 'https://github.com/NeuronRobotics/nrjavaserial' } licenses { license { - name 'The Apache License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + name = 'RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface' + url = 'https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/master/LICENSE' } } developers { developer { - id 'madhephaestus' - name 'Kevin Harrington' - email 'kharrington@neuronrobotics.com' + id = 'madhephaestus' + name = 'Kevin Harrington' + email = 'kharrington@neuronrobotics.com' + } + developer { + id = 'MrDOS' + name = 'Samuel Coleman' + email = 'samuel@seenet.ca' } } } } } } -*/ + +// You can provide a signatory in three ways. Either: +// +// 1. Pass the signatory properties – signing.keyId, signing.secretKeyRingFile, +// and signing.password – on the command line: +// +// ./gradlew ... \ +// -Psigning.keyId=7FD6B0A1 \ +// -Psigning.secretKeyRingFile=/path/to/.gnupg/secring.gpg \ +// -Psigning.password=secret +// +// 2. Configure those properties in ~/.gradle/gradle.properties. +// 3. Set the SIGNINGKEY and SIGNINGPASSWORD environment variables to an +// ASCII-armored PGP key and password, respectively. +// +// For more details on the behaviour of the properties and their expected +// values, see the signing plugin documentation: +// +// https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signatory_credentials +// +// If a signatory has not been configured, or if the signing.skip property is +// set, artifacts will not be signed prior to publication. +// +// This signing block must appear after the publishing block in order to refer +// to the specific publication to be signed. +signing { + if (project.hasProperty('signing.skip')) { + // We've been explicitly told not to sign artifacts, even if we have a + // configured signatory. + return + } else if (System.env.SIGNINGKEY && System.env.SIGNINGPASSWORD) { + useInMemoryPgpKeys(System.env.SIGNINGKEY, System.env.SIGNINGPASSWORD) + } else if (findProperty('signing.keyId') && + findProperty('signing.secretKeyRingFile') && + findProperty('signing.password')) { + // No special configuration necessary for properties: the signing plugin + // self-configures from the signing.keyId, signing.secretKeyRingFile, and + // signing.password properties when populated. + } else { + // No signatory is configured; skip signing. + return + } + + sign publishing.publications.nrJavaSerial +} diff --git a/gradle.properties b/gradle.properties deleted file mode 120000 index 4e89a6ba..00000000 --- a/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -/home/hephaestus/gradle.properties \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index f3d88b1c..7f93135c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b7c8c5db..ac72c34e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 2fe81a7d..0adc8e1a 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,78 +17,111 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -97,87 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 9109989e..6689b85b 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +55,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,38 +65,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..208c9255 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,3 @@ +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' +} diff --git a/src/main/c/Makefile b/src/main/c/Makefile index d9569ddf..837a9d79 100644 --- a/src/main/c/Makefile +++ b/src/main/c/Makefile @@ -58,6 +58,14 @@ include JAVA_HOME.mk include platform.mk +# Most of the time, GCC is called `gcc` and is installed from a `gcc` package. +# However, sometimes a distribution packages multiple versions of GCC. In this +# case, both the binary and package names of non-default versions are suffixed +# (e.g., `gcc-8`). We can't use the standard CC variable to adapt to this, +# because each target already overrides that variable with the name of the +# appropriate cross compiler. +GCC ?= gcc + # In all cases, we want to include the system JNI headers, our own headers, # crank the optimization level, and compile position-independent code so that # it will work as a library (dlopen(3) et al. can load it into any memory). @@ -87,13 +95,13 @@ all: $(error $(NO_TARGET_PLATFORM_SPECIFIED)) crosstools: - apt install --install-recommends \ - gcc-i686-linux-gnu \ - gcc-arm-linux-gnueabi \ - gcc-arm-linux-gnueabihf \ - gcc-aarch64-linux-gnu \ + apt-get --assume-yes install \ + $(GCC)-i686-linux-gnu \ + $(GCC)-arm-linux-gnueabi \ + $(GCC)-arm-linux-gnueabihf \ + $(GCC)-aarch64-linux-gnu \ gcc-mingw-w64 \ - gcc-powerpc-linux-gnu + $(GCC)-powerpc-linux-gnu # Does not include Android, because Android toolchains are large, not commonly # available, and the resulting library is not typically desired. @@ -108,7 +116,7 @@ LINUX_CFLAGS += -U_FORTIFY_SOURCE endif # Requires gcc-i686-linux-gnu. -linux32: export CC := i686-linux-gnu-gcc +linux32: export CC := i686-linux-gnu-$(GCC) linux32: export CFLAGS += $(LINUX_CFLAGS) -m32 linux32: export LDFLAGS += -m32 linux32: export platform := linux/x86_32 @@ -116,6 +124,7 @@ linux32: $(MAKE) -f natives.mk # Requires gcc. +linux64: export CC := $(GCC) linux64: export CFLAGS += $(LINUX_CFLAGS) -m64 linux64: export platform := linux/x86_64 linux64: @@ -127,7 +136,7 @@ arm: arm32v5 \ arm32v8 arm32v8HF arm64v8 # Requires gcc-arm-linux-gnueabi. -arm32v5: export CC := arm-linux-gnueabi-gcc +arm32v5: export CC := arm-linux-gnueabi-$(GCC) arm32v5: export CFLAGS += $(LINUX_CFLAGS) -march=armv5t arm32v5: export LDFLAGS += -march=armv5t arm32v5: export platform := linux/ARM_32 @@ -136,7 +145,7 @@ arm32v5: $(MAKE) -f natives.mk # Requires gcc-arm-linux-gnueabi. -arm32v6: export CC := arm-linux-gnueabi-gcc +arm32v6: export CC := arm-linux-gnueabi-$(GCC) arm32v6: export CFLAGS += $(LINUX_CFLAGS) -march=armv6 arm32v6: export LDFLAGS += -march=armv6 arm32v6: export platform := linux/ARM_32 @@ -145,16 +154,16 @@ arm32v6: $(MAKE) -f natives.mk # Requires gcc-arm-linux-gnueabihf. -arm32v6HF: export CC := arm-linux-gnueabihf-gcc -arm32v6HF: export CFLAGS += $(LINUX_CFLAGS) -march=armv6 -mfpu=vfp -marm -arm32v6HF: export LDFLAGS += -march=armv6 -mfpu=vfp -marm +arm32v6HF: export CC := arm-linux-gnueabihf-$(GCC) +arm32v6HF: export CFLAGS += $(LINUX_CFLAGS) -march=armv6+fp -marm +arm32v6HF: export LDFLAGS += -march=armv6+fp -marm arm32v6HF: export platform := linux/ARM_32 arm32v6HF: export variant := v6_HF arm32v6HF: $(MAKE) -f natives.mk # Requires gcc-arm-linux-gnueabi. -arm32v7: export CC := arm-linux-gnueabi-gcc +arm32v7: export CC := arm-linux-gnueabi-$(GCC) arm32v7: export CFLAGS += $(LINUX_CFLAGS) -march=armv7-a arm32v7: export LDFLAGS += -march=armv7-a arm32v7: export platform := linux/ARM_32 @@ -163,16 +172,16 @@ arm32v7: $(MAKE) -f natives.mk # Requires gcc-arm-linux-gnueabihf. -arm32v7HF: export CC := arm-linux-gnueabihf-gcc -arm32v7HF: export CFLAGS += $(LINUX_CFLAGS) -march=armv7-a -arm32v7HF: export LDFLAGS += -march=armv7-a +arm32v7HF: export CC := arm-linux-gnueabihf-$(GCC) +arm32v7HF: export CFLAGS += $(LINUX_CFLAGS) -march=armv7-a+fp +arm32v7HF: export LDFLAGS += -march=armv7-a+fp arm32v7HF: export platform := linux/ARM_32 arm32v7HF: export variant := v7_HF arm32v7HF: $(MAKE) -f natives.mk # Requires gcc-arm-linux-gnueabi. -arm32v8: export CC := arm-linux-gnueabi-gcc +arm32v8: export CC := arm-linux-gnueabi-$(GCC) arm32v8: export CFLAGS += $(LINUX_CFLAGS) -march=armv8-a arm32v8: export LDFLAGS += -march=armv8-a arm32v8: export platform := linux/ARM_32 @@ -181,18 +190,18 @@ arm32v8: $(MAKE) -f natives.mk # Requires gcc-arm-linux-gnueabihf. -arm32v8HF: export CC := arm-linux-gnueabihf-gcc -arm32v8HF: export CFLAGS += $(LINUX_CFLAGS) -march=armv8-a -arm32v8HF: export LDFLAGS += -march=armv8-a +arm32v8HF: export CC := arm-linux-gnueabihf-$(GCC) +arm32v8HF: export CFLAGS += $(LINUX_CFLAGS) -march=armv8-a -mfpu=neon-fp-armv8 +arm32v8HF: export LDFLAGS += -march=armv8-a -mfpu=neon-fp-armv8 arm32v8HF: export platform := linux/ARM_32 arm32v8HF: export variant := v8_HF arm32v8HF: $(MAKE) -f natives.mk # Requires gcc-aarch64-linux-gnu. -arm64v8: export CC := aarch64-linux-gnu-gcc -arm64v8: export CFLAGS += $(LINUX_CFLAGS) -march=armv8-a -arm64v8: export LDFLAGS += -march=armv8-a +arm64v8: export CC := aarch64-linux-gnu-$(GCC) +arm64v8: export CFLAGS += $(LINUX_CFLAGS) -march=armv8-a+fp +arm64v8: export LDFLAGS += -march=armv8-a+fp arm64v8: export platform := linux/ARM_64 arm64v8: export variant := v8 arm64v8: @@ -208,15 +217,19 @@ android: $(MAKE) -f natives.mk # Requires gcc-powerpc-linux-gnu. -ppc: export CC := powerpc-linux-gnu-gcc +ppc: export CC := powerpc-linux-gnu-$(GCC) ppc: export CFLAGS += $(LINUX_CFLAGS) ppc: export platform := linux/PPC ppc: $(MAKE) -f natives.mk # Requires a macOS host. -osx: export CFLAGS += -I$(JAVA_HOME)/include/darwin -arch x86_64 -osx: export LDFLAGS := -arch x86_64 -dynamiclib -framework JavaVM -framework IOKit -framework CoreFoundation +osx: export CFLAGS += -I$(JAVA_HOME)/include/darwin \ + -target x86_64-apple-macos10.7 +osx: export LDFLAGS := -target x86_64-apple-macos10.7 \ + -dynamiclib \ + -framework IOKit \ + -framework CoreFoundation osx: export objects := fuserImp.o SerialImp.o osx: export platform := osx osx: export lib_type := jnilib