From 3c3d628f0c2e026b781629f2e7d9f258008b1e7f Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 12 Nov 2020 17:21:41 -0600 Subject: [PATCH] t/oxr_android: Add resources and build code to grab the CDDL license for display. Used by a dependency of Hilt. --- build.gradle | 3 ++ src/xrt/targets/openxr_android/build.gradle | 51 ++++++++++++++----- .../config/custom_license_mappings.prop | 4 +- .../openxr_android/src/main/res/.gitignore | 5 ++ .../src/main/res/raw/.gitignore | 1 - .../src/main/res/values/license_cddl_1_0.xml | 12 +++++ 6 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 src/xrt/targets/openxr_android/src/main/res/.gitignore delete mode 100644 src/xrt/targets/openxr_android/src/main/res/raw/.gitignore create mode 100644 src/xrt/targets/openxr_android/src/main/res/values/license_cddl_1_0.xml diff --git a/build.gradle b/build.gradle index c215eff55..dcaeb3fa1 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,9 @@ plugins { // For getting git describe data and formatting it how Android wants. id "com.gladed.androidgitversion" version "0.4.13" + + // For downloading e.g. the CDDL (for transitive dependencies of hilt) + id "de.undercouch.download" version "4.1.1" } ext { diff --git a/src/xrt/targets/openxr_android/build.gradle b/src/xrt/targets/openxr_android/build.gradle index e4fa3ffde..9b7bb1a7f 100644 --- a/src/xrt/targets/openxr_android/build.gradle +++ b/src/xrt/targets/openxr_android/build.gradle @@ -25,27 +25,51 @@ def parseOpenXRVersion(def fn) { String.join('.', components) } +// For JSR250 used by Hilt +task getCDDL { + doLast { + ant.invokeMethod("get", [src: "https://spdx.org/licenses/CDDL-1.0.txt", dest: "${} "]) + } + +} + +project.ext.renameLicense = { String name -> + def lowerNoExtension = name.toLowerCase().replace(".txt", "") + def result = lowerNoExtension.replaceAll(~/[\-.]/, "_") + ".txt" + return result +} + +project.ext.filterLicense = {String line -> + if (line.trim().isEmpty()) { + return '

' + } else { + return groovy.xml.XmlUtil.escapeXml(line) + } +} // TODO: this copies to the source dir for simplicity right now, but it's not great! task copyLicenses(type: Copy) { from "${rootDir}/LICENSES/" include 'BSL-1.0.txt' - rename { - String name -> - def lowerNoExtension = name.toLowerCase().replace(".txt", "") - def result = lowerNoExtension.replaceAll(~/[\-.]/, "_") + ".txt" - return result - } + rename(renameLicense) into project.layout.projectDirectory.dir('src/main/res/raw').asFile - filter { line -> - if (line.trim().isEmpty()) { - return '

' - } else { - return groovy.xml.XmlUtil.escapeXml(line) - } - } + filter(filterLicense) +} +project.ext.licenseDir = new File(project.buildDir, 'intermediates/licenses/') + +task downloadCddl(type: Download) { + src 'https://spdx.org/licenses/CDDL-1.0.txt' + dest "${project.licenseDir}/CDDL-1.0.txt" + overwrite false } +task copyDownloadedLicenses(type: Copy) { + from downloadCddl.dest + rename(renameLicense) + into project.layout.projectDirectory.dir('src/main/res/raw').asFile + filter(filterLicense) + dependsOn downloadCddl +} android { compileSdkVersion project.sharedTargetSdk buildToolsVersion '30.0.2' @@ -79,6 +103,7 @@ android { // Be sure to copy over licenses formatted as required. preBuild.dependsOn(copyLicenses) + preBuild.dependsOn(copyDownloadedLicenses) } buildTypes { diff --git a/src/xrt/targets/openxr_android/config/custom_license_mappings.prop b/src/xrt/targets/openxr_android/config/custom_license_mappings.prop index 9fb09f650..1ecfb3283 100644 --- a/src/xrt/targets/openxr_android/config/custom_license_mappings.prop +++ b/src/xrt/targets/openxr_android/config/custom_license_mappings.prop @@ -1 +1,3 @@ -cjson:mit +# Copyright 2020, Collabora, Ltd. +# SPDX-License-Identifier: BSL-1.0 +javax_annotation__jsr250_api:cddl_1_0 diff --git a/src/xrt/targets/openxr_android/src/main/res/.gitignore b/src/xrt/targets/openxr_android/src/main/res/.gitignore new file mode 100644 index 000000000..beb826d81 --- /dev/null +++ b/src/xrt/targets/openxr_android/src/main/res/.gitignore @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: CC0-1.0 +# SPDX-FileCopyrightText: 2020 Collabora, Ltd. and the Monado contributors + +bsl_1_0.txt +cddl_1_0.txt diff --git a/src/xrt/targets/openxr_android/src/main/res/raw/.gitignore b/src/xrt/targets/openxr_android/src/main/res/raw/.gitignore deleted file mode 100644 index ab25a59eb..000000000 --- a/src/xrt/targets/openxr_android/src/main/res/raw/.gitignore +++ /dev/null @@ -1 +0,0 @@ -bsl_1_0.txt diff --git a/src/xrt/targets/openxr_android/src/main/res/values/license_cddl_1_0.xml b/src/xrt/targets/openxr_android/src/main/res/values/license_cddl_1_0.xml new file mode 100644 index 000000000..030744fd8 --- /dev/null +++ b/src/xrt/targets/openxr_android/src/main/res/values/license_cddl_1_0.xml @@ -0,0 +1,12 @@ + + + + + Common Development and Distribution License 1.0 + + + raw:cddl_1_0 +