Skip to content

Commit

Permalink
Generate dependencies.json
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Oct 10, 2024
1 parent 182a442 commit 22737bc
Show file tree
Hide file tree
Showing 8 changed files with 1,226 additions and 18 deletions.
25 changes: 9 additions & 16 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import com.github.jk1.license.render.*

buildscript {
ext {
// Compatibility tables:
// https://docs.gradle.org/current/userguide/compatibility.html
// https://developer.android.com/build/releases/gradle-plugin
// https://kotlinlang.org/docs/gradle-configure-project.html
//
// Related packages (must be updated together):
// org.jetbrains.kotlin:kotlin-gradle-plugin (build.gradle)
// com.android.tools.build:gradle (build.gradle)
// com.android.application (settings.gradle)
// org.jetbrains.kotlin.android (settings.gradle)
// kotlinCompilerExtensionVersion (app/build.gradle)
// org.jetbrains.kotlin:kotlin-stdlib (app/build.gradle)
// androidx.*-ktx (app/build.gradle)
//
// Gradle version is defined here:
// gradle/wrapper/gradle-wrapper.properties => distributionUrl
kotlin_version = "1.8.0"
}

Expand All @@ -33,6 +19,7 @@ buildscript {

plugins {
id "com.diffplug.spotless" version "6.12.0"
id "com.github.jk1.dependency-license-report" version "2.9"
}

allprojects {
Expand Down Expand Up @@ -74,3 +61,9 @@ spotless {
endWithNewline()
}
}

licenseReport {
configurations = ["releaseRuntimeClasspath"]
outputDir = project.layout.buildDirectory.get().asFile.path
renderers = [new ExtendedJsonReportRenderer("android_licenses.json")]
}
10 changes: 9 additions & 1 deletion docs/automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Generated files have `*.g.dart` or `.g.kt` extension and must no be modified by

`model` package uses `mobx_codegen` to generate reactive model classes. `agent` package uses `pigeon` to generate android platform channels bridge.

## Generate assets
## Generate resources

Icons and splash screen are generated using `flutter_launcher_icons` and `flutter_native_splash` packages. You can find configuration in `pubspec.yaml` and source assets in `assets` directory.

Expand All @@ -96,6 +96,14 @@ Regenerate splash screen:
doit gen:splash
```

The list of transitive dependencies and their licenses is generated using `flutter_oss_licenses` package and [Gradle-License-Report](https://github.com/jk1/Gradle-License-Report) plugin, and then composed into a single json file `metadata/dependencies.json` using `script/generate_dependencies.py` script.

Regenerate dependencies:

```
doit gen:deps
```

## Format code

Run all code formatters:
Expand Down
22 changes: 22 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Development

## Kotlin and gradle versions

Compatibility tables:

* [Gradle](https://docs.gradle.org/current/userguide/compatibility.html)
* [Android Gradle plugin](https://developer.android.com/build/releases/gradle-plugin)
* [Kotlin Gradle plugin](https://kotlinlang.org/docs/gradle-configure-project.html)

Gradle version is defined in `distributionUrl` parameter in `android/gradle/wrapper/gradle-wrapper.properties`.

Related packages that must be compatible with each other and updated together:

| Dependency | Location |
|---------------------------------------------|----------------------------|
| `org.jetbrains.kotlin:kotlin-gradle-plugin` | `android/build.gradle` |
| `com.android.tools.build:gradle` | `android/build.gradle` |
| `com.android.application` | `android/settings.gradle` |
| `org.jetbrains.kotlin.android` | `android/settings.gradle` |
| `kotlinCompilerExtensionVersion` | `android/app/build.gradle` |
| `org.jetbrains.kotlin:kotlin-stdlib` | `android/app/build.gradle` |
| `androidx.*-ktx` | `android/app/build.gradle` |

## Capture android logs

This script is a wrapper for `adb logcat`:
Expand Down
20 changes: 19 additions & 1 deletion dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,24 @@ def task_gen_agent():
'title': title_with_actions,
}

# doit gen:deps
def task_gen_deps():
"""collect dependencies and their licenses"""
return {
'basename': 'gen:deps',
'actions': [
# generate build/android_licenses.json
f'cd android && {_gradlew()} generateLicenseReport',
# generate build/flutter_licenses.json
'flutter pub get',
'flutter pub run flutter_oss_licenses:generate.dart '+
'--json -o build/flutter_licenses.json',
# generate metadata/dependencies.json
f'{sys.executable} script/generate_dependencies.py',
],
'title': title_with_actions,
}

# doit gen:icons
def task_gen_icons():
"""run flutter icons generation (flutter_launcher_icons)"""
Expand All @@ -194,7 +212,7 @@ def task_gen_splash():
"""run flutter splash screens generation (flutter_native_splash)"""
return {
'basename': 'gen:splash',
'actions': ['dart run flutter_native_splash:create '],
'actions': ['dart run flutter_native_splash:create'],
'title': title_with_actions,
}

Expand Down
1,007 changes: 1,007 additions & 0 deletions metadata/dependencies.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
dart_pubspec_licenses:
dependency: transitive
description:
name: dart_pubspec_licenses
sha256: a488baa010044452b208bc35c6dd62ac072a1ea918f796e4381d5aa1b21cfa41
url: "https://pub.dev"
source: hosted
version: "3.0.1"
dart_style:
dependency: transitive
description:
Expand Down Expand Up @@ -304,6 +312,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.4.1"
flutter_oss_licenses:
dependency: "direct dev"
description:
name: flutter_oss_licenses
sha256: "1219e0e03faac80e68a554b79447d4936c79081d698abca912cc123fb77094aa"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dev_dependencies:
test: ^1.25.2
build_runner: ^2.4.11
mobx_codegen: ^2.6.1
flutter_oss_licenses: ^3.0.2

flutter:
uses-material-design: true
Expand Down
143 changes: 143 additions & 0 deletions script/generate_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#! /usr/bin/env python3

from collections import OrderedDict
import functools
import json
import os
import re
import requests

# output file
DEPENDENCIES_JSON = 'metadata/dependencies.json'

# input files
ANDROID_LICENSES = 'build/android_licenses.json'
FLUTTER_LICENSES = 'build/flutter_licenses.json'

# hard-coded license urls
LICENSE_URLS = {
'The MIT License': 'https://spdx.org/licenses/MIT.txt',
'MIT': 'https://spdx.org/licenses/MIT.txt',
}

# hard-coded additional dependencies
EXTRA_DEPS = {
'Roc Toolkit': 'https://raw.githubusercontent.com/roc-streaming/roc-toolkit/HEAD/LICENSE',
# Roc Toolkit dependencies:
# see https://roc-streaming.org/toolkit/docs/building/dependencies.html
'Hedley': 'https://raw.githubusercontent.com/nemequ/hedley/HEAD/COPYING',
'OpenFEC': 'https://raw.githubusercontent.com/roc-streaming/openfec/HEAD/Licence_CeCILL_V2-en.txt',
'OpenSSL': 'https://raw.githubusercontent.com/openssl/openssl/HEAD/LICENSE.txt',
'SpeexDSP': 'https://raw.githubusercontent.com/xiph/speexdsp/HEAD/COPYING',
'dr_wav': 'https://raw.githubusercontent.com/mackron/dr_libs/HEAD/LICENSE',
'libuv': 'https://raw.githubusercontent.com/libuv/libuv/HEAD/LICENSE',
'libuv-extra': 'https://raw.githubusercontent.com/libuv/libuv/HEAD/LICENSE-extra',
}

@functools.cache
def load_document(url):
resp = requests.get(url)
resp.raise_for_status()
return resp.text

def android_license(dep):
license_name = dep.get('moduleLicense', '')
license_url = dep.get('moduleLicenseUrl', '')
project_name = dep.get('moduleName', '')
project_url = dep.get('moduleUrl', '')

m = re.match(r'^https://github.com/(.+)$', project_url)
if m:
github_url = f'https://raw.githubusercontent.com/{m.group(1)}/HEAD/LICENSE'
try:
return load_document(github_url)
except:
pass

m = re.match(r'^https://spdx.org/licenses/(.+).html$', license_url)
if m:
license_url = re.sub(r'.html$', '.txt', license_url)

if license_url:
try:
return load_document(license_url)
except:
pass

if license_name in LICENSE_URLS:
license_url = LICENSE_URLS[license_name]
try:
return load_document(license_url)
except:
pass

print(f'unable to locate license for {project_name}')
exit(1)

def collect_android_dependencies():
result_deps = []

print(f'processing {ANDROID_LICENSES}')
with open(ANDROID_LICENSES) as fp:
android_deps = json.load(fp)

for dep in android_deps['dependencies']:
skip = False
for key in ['moduleName', 'moduleLicense']:
if not key in dep:
skip = True
break
if skip:
continue

result_deps.append(OrderedDict({
'name': dep['moduleName'],
'platform': 'android',
'license': android_license(dep),
}))

return result_deps

def collect_flutter_dependencies():
result_deps = []

print(f'processing {FLUTTER_LICENSES}')
with open(FLUTTER_LICENSES) as fp:
flutter_deps = json.load(fp)

for dep in flutter_deps:
result_deps.append(OrderedDict({
'name': dep['name'],
'platform': 'all',
'license': dep['license'],
}))

return result_deps

def collect_extra_dependencies():
result_deps = []

print('processing extra dependencies')
for name, url in EXTRA_DEPS.items():
result_deps.append(OrderedDict({
'name': name,
'platform': 'all',
'license': load_document(url),
}))

return result_deps

def dump_json(dependencies):
print(f'writing {DEPENDENCIES_JSON}')
with open(DEPENDENCIES_JSON, 'w') as fp:
json.dump(dependencies, fp, indent=4)

os.chdir(os.path.join(
os.path.dirname(os.path.abspath(__file__)), '..'))

dependencies = []
dependencies += collect_android_dependencies()
dependencies += collect_flutter_dependencies()
dependencies += collect_extra_dependencies()

dump_json(dependencies)

0 comments on commit 22737bc

Please sign in to comment.