Skip to content

Commit

Permalink
chore: re-introduce comptime deps as provided deps
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyashsaitwal committed Jan 15, 2024
1 parent b192773 commit 0afa249
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 68 deletions.
11 changes: 4 additions & 7 deletions lib/src/commands/build/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ class BuildCommand extends Command<int> {
await SyncSubCommand().sync(
cacheBox: _libService.extensionDepsBox,
coordinates: {Scope.compile: dependencies},
providedArtifacts: await _libService.providedDependencies(),
providedArtifacts: await _libService.providedDependencies(config),
repositories: config.repositories,
downloadSources: true,
includeAiProvided: false,
);
await timestampBox.put(configTimestampKey, DateTime.now());
} catch (e, s) {
Expand Down Expand Up @@ -138,7 +137,7 @@ class BuildCommand extends Command<int> {
_lgr.startTask('Optimizing and obfuscating the bytecode');

final deps = await _libService.extensionDependencies(config,
includeProvidedDeps: true);
includeAi2ProvidedDeps: true, includeProjectProvidedDeps: true);
final aars = deps.where((el) => el.packaging == 'aar');

final proguardRules = aars
Expand Down Expand Up @@ -200,9 +199,7 @@ class BuildCommand extends Command<int> {
}

Future<void> _mergeManifests(
Config config,
LazyBox<DateTime> timestampBox,
) async {
Config config, LazyBox<DateTime> timestampBox) async {
final deps = await _libService.extensionDependencies(config);
final requiredAars = deps.where((el) =>
el.scope == Scope.runtime &&
Expand Down Expand Up @@ -258,7 +255,7 @@ class BuildCommand extends Command<int> {
_lgr.info('Picked $fileCount source file${fileCount > 1 ? 's' : ''}');

final dependencies = await _libService.extensionDependencies(config,
includeProvidedDeps: true);
includeAi2ProvidedDeps: true, includeProjectProvidedDeps: true);
final compileClasspathJars = dependencies
.where((el) => el.scope == Scope.compile || el.scope == Scope.provided)
.map((el) => el.classpathJars(dependencies))
Expand Down
4 changes: 2 additions & 2 deletions lib/src/commands/build/tools/executor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Executor {

// Take only provided deps since compile and runtime scoped deps have already
// been added to the art jar
final providedDeps = await _libService.providedDependencies();
final providedDeps = await _libService.providedDependencies(config);
final libraryJars = providedDeps
.map((el) => el.classpathJars(providedDeps))
.flattened
Expand Down Expand Up @@ -122,7 +122,7 @@ class Executor {
return p.join(javaHome, 'jmods', 'java.base.jmod').asFile();
}();

final providedDeps = await _libService.providedDependencies();
final providedDeps = await _libService.providedDependencies(config);
final classpathJars = providedDeps
.map((el) => el.classpathJars(providedDeps))
.flattened
Expand Down
2 changes: 1 addition & 1 deletion lib/src/commands/create/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ${'Success!'.green()} Generated a new extension project in ${p.relative(projectD
await GetIt.I.isReady<LibService>();
final libService = GetIt.I<LibService>();

final artifacts = await libService.providedDependencies();
final artifacts = await libService.providedDependencies(null);
final providedDepJars = artifacts.map((el) => el.classesJar).whereNotNull();
final providedDepSources =
artifacts.map((el) => el.sourcesJar).whereNotNull();
Expand Down
27 changes: 17 additions & 10 deletions lib/src/commands/create/templates/other.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ min_sdk: 7
# Desuagring allows you to use Java 8 language features in your extension. You
# also need to enable desugaring if any of your dependencies use Java 8 language
# features.
${!enableKt ? '# ' : ''}desugar: true
${!enableKt ? '#' : ''}desugar: true
${!enableKt ? '' : '''
# Kotlin specific configuration.
Expand All @@ -24,28 +24,35 @@ kotlin:
# External libraries your extension depends on. These can be local JARs / AARs
# stored in the "deps" directory or coordinates of remote Maven artifacts in
# <groupId>:<artifactId>:<version> format.
${enableKt ? 'dependencies:' : '# dependencies:'}
${enableKt ? '- $kotlinGroupId:kotlin-stdlib:$defaultKtVersion\n' : ''}# - example.jar # Local JAR or AAR file stored in "deps" directory
# - com.example:foo-bar:1.2.3 # Coordinate of some remote Maven artifact
${enableKt ? 'dependencies:' : '#dependencies:'}
${enableKt ? '- $kotlinGroupId:kotlin-stdlib:$defaultKtVersion\n' : ''}#- example.jar # Local JAR or AAR file stored in "deps" directory
#- com.example:foo-bar:1.2.3 # Coordinate of some remote Maven artifact
# Default Maven repositories includes Maven Central, Google Maven, JitPack and
# JCenter. If the library you want to use is not available in these repositories,
# you can add additional repositories by specifying their URLs here.
# repositories:
# - https://jitpack.io
#repositories:
#- https://jitpack.io
# Assets that your extension needs. Every asset file must be stored in the assets
# directory as well as declared here. Assets can be of any type.
# assets:
# - data.json
#assets:
#- data.json
# Homepage of your extension. This may be the announcement thread on community
# forums or a link to your GitHub repository.
# homepage: https://github.com/shreyashsaitwal/rush-cli
#homepage: https://github.com/shreyashsaitwal/rush-cli
# Path to the license file of your extension. This should be a path to a local
# file or link to something hosted online.
# license: LICENSE.txt
#license: LICENSE.txt
# Similar to dependencies, except libraries defined as provided are not included
# in the final AIX. This is useful when you want to use a library in your
# extension but don't want to include it in the final AIX because it's already
# included in the App Inventor.
#provided_dependencies:
#- com.example:foo-bar:1.2.3
''';
}

Expand Down
43 changes: 27 additions & 16 deletions lib/src/commands/deps/sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,16 @@ class SyncSubCommand extends Command<int> {
];

// Dev deps to be resolved
final providedDepsToFetch = <String>{};
final ai2ProvidedDepsToFetch = <String>{};
final toolsToFetch = <String>{};

var providedDepArtifacts = await libService.providedDependencies();
var ai2ProvidedDepArtifacts = await libService.providedDependencies(null);
var buildLibArtifacts = await libService.buildLibArtifacts();

// Add every un-cached dev dep to fetch list.
if (providedDepArtifacts.none((el) => el.coordinate == ai2RuntimeCoord)) {
providedDepsToFetch.add(ai2RuntimeCoord);
if (ai2ProvidedDepArtifacts
.none((el) => el.coordinate == ai2RuntimeCoord)) {
ai2ProvidedDepsToFetch.add(ai2RuntimeCoord);
}
for (final coord in toolsCoord) {
if (buildLibArtifacts.none((el) => el.coordinate == coord)) {
Expand All @@ -103,8 +104,8 @@ class SyncSubCommand extends Command<int> {

// Add every non existent dev dep to the fetch list. This can happen when
// the said dep was deleted or the local Maven repo location was changed.
providedDepsToFetch.addAll(
providedDepArtifacts
ai2ProvidedDepsToFetch.addAll(
ai2ProvidedDepArtifacts
.where((el) => !el.artifactFile.asFile().existsSync())
.map((el) => el.coordinate)
.where((el) => el.trim().isNotEmpty),
Expand All @@ -120,13 +121,13 @@ class SyncSubCommand extends Command<int> {
_lgr.stopTask();

if (!onlyExtDeps &&
(providedDepsToFetch.isNotEmpty || toolsToFetch.isNotEmpty)) {
(ai2ProvidedDepsToFetch.isNotEmpty || toolsToFetch.isNotEmpty)) {
_lgr.startTask('Syncing dev-dependencies');
try {
await Future.wait([
sync(
cacheBox: libService.providedDepsBox,
coordinates: {Scope.compile: providedDepsToFetch},
coordinates: {Scope.compile: ai2ProvidedDepsToFetch},
downloadSources: true,
excludeCoordinates: ['com.google.android:android:2.1.2'],
),
Expand Down Expand Up @@ -155,7 +156,7 @@ class SyncSubCommand extends Command<int> {
..stopTask();
}
await BuildUtils.extractAars(
providedDepArtifacts
ai2ProvidedDepArtifacts
.where((el) => el.artifactFile.endsWith('.aar'))
.where((el) =>
!el.classesJar.asFile().existsSync() ||
Expand All @@ -172,7 +173,7 @@ class SyncSubCommand extends Command<int> {
}

// Update the vars after syncing dev deps.
providedDepArtifacts = await libService.providedDependencies();
ai2ProvidedDepArtifacts = await libService.providedDependencies(null);
buildLibArtifacts = await libService.buildLibArtifacts();

Hive.init(_fs.dotRushDir.path);
Expand All @@ -185,15 +186,25 @@ class SyncSubCommand extends Command<int> {

final extDepCoords = config.dependencies
.where((el) => !el.endsWith('.jar') && !el.endsWith('.aar'));
final extProvidedDepCoord = config.providedDependencies
.where((el) => !el.endsWith('.jar') && !el.endsWith('.aar'));

try {
await sync(
cacheBox: libService.extensionDepsBox,
coordinates: {Scope.provided: extProvidedDepCoord},
repositories: config.repositories,
downloadSources: true,
);

final providedDepArtifacts =
await libService.providedDependencies(config);
await sync(
cacheBox: libService.extensionDepsBox,
coordinates: {Scope.compile: extDepCoords},
repositories: config.repositories,
providedArtifacts: providedDepArtifacts,
downloadSources: true,
includeAiProvided: false,
);
await timestampBox.put(configTimestampKey, DateTime.now());
} catch (_) {
Expand All @@ -211,7 +222,8 @@ class SyncSubCommand extends Command<int> {
_lgr.startTask('Adding resolved dependencies to your IDE\'s lib index');

try {
final extensionDeps = await libService.extensionDependencies(config);
final extensionDeps = await libService.extensionDependencies(config,
includeProjectProvidedDeps: true);
await BuildUtils.extractAars(
extensionDeps
.where((el) => el.artifactFile.endsWith('.aar'))
Expand All @@ -223,8 +235,8 @@ class SyncSubCommand extends Command<int> {
.map((el) => el.artifactFile),
);

await _updateIntellijLibIndex(providedDepArtifacts, extensionDeps);
await _updateEclipseClasspath(providedDepArtifacts, extensionDeps);
await _updateIntellijLibIndex(ai2ProvidedDepArtifacts, extensionDeps);
await _updateEclipseClasspath(ai2ProvidedDepArtifacts, extensionDeps);
} catch (_) {
_lgr.stopTask(false);
return 1;
Expand Down Expand Up @@ -287,7 +299,6 @@ class SyncSubCommand extends Command<int> {
Iterable<String> repositories = const [],
Iterable<Artifact> providedArtifacts = const [],
bool downloadSources = false,
bool includeAiProvided = true,
List<String> excludeCoordinates = const [],
}) async {
_lgr.info('Resolving ${coordinates.values.flattened.length} artifacts...');
Expand Down Expand Up @@ -327,7 +338,7 @@ class SyncSubCommand extends Command<int> {

// When resolving extension deps, remove AI2 provided deps from dependencies
// field and add them to the providedDependencies field of each artifact.
if (!includeAiProvided) {
if (providedArtifacts.isNotEmpty) {
final providedDeps = <String>{};
resolvedDeps.removeWhere((el) {
final provided = _providedAlternative(
Expand Down
44 changes: 25 additions & 19 deletions lib/src/commands/deps/tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ class TreeSubCommand extends Command<int> {
await GetIt.I.isReady<LibService>();
final libService = GetIt.I<LibService>();

final remoteExtDepIndex =
await libService.extensionDependencies(config, includeLocal: false);
final remoteExtDepIndex = await libService.extensionDependencies(config,
includeLocal: false, includeProjectProvidedDeps: true);
final requiredRemoteDeps = remoteExtDepIndex
.where((el) => config.dependencies.contains(el.coordinate)
// TODO
// || config.comptimeDeps.contains(el.coordinate)
)
.where((el) =>
config.dependencies.contains(el.coordinate) ||
config.providedDependencies.contains(el.coordinate))
.toList(growable: true);

_lgr.log(p.basename(_fs.cwd).cyan().bold());
Expand All @@ -46,22 +45,22 @@ class TreeSubCommand extends Command<int> {
final local = _localDepGraph(
config.dependencies.where(
(el) => p.extension(el) == '.jar' || p.extension(el) == '.aar'),
false,
remoteExtDepIndex.isEmpty,
);
if (local.isNotEmpty) {
_lgr.log(local);
}

// TODO
// final comptimeLocal = _localDepGraph(
// config.comptimeDeps.where(
// (el) => p.extension(el) == '.jar' || p.extension(el) == '.aar'),
// true,
// remoteExtDepIndex.isEmpty,
// );
// if (comptimeLocal.isNotEmpty) {
// _lgr.log(comptimeLocal);
// }
final providedLocal = _localDepGraph(
config.providedDependencies.where(
(el) => p.extension(el) == '.jar' || p.extension(el) == '.aar'),
true,
remoteExtDepIndex.isEmpty,
);
if (providedLocal.isNotEmpty) {
_lgr.log(providedLocal);
}

final remoteDepsGraph = <String>{
for (final dep in requiredRemoteDeps)
Expand All @@ -77,13 +76,13 @@ class TreeSubCommand extends Command<int> {
return 0;
}

String _localDepGraph(Iterable<String> deps, bool noRemoteDeps) {
String _localDepGraph(Iterable<String> deps, bool isProvided, bool noRemoteDeps,) {
final graph = <String>[];
for (final dep in deps) {
final isLast = dep == deps.last && noRemoteDeps;
var branch = isLast ? Connector.lastSibling : Connector.sibling;
branch += Connector.horizontal * (_branchGap + 1) + Connector.empty;
branch += dep.blue() + ' (compile, local)'.grey();
branch += dep.blue() + ' (${isProvided ? 'provided' : 'compile'}, local)'.grey();
graph.add(branch);
}
return graph.join('\n');
Expand Down Expand Up @@ -120,13 +119,20 @@ class TreeSubCommand extends Command<int> {
':'.grey() +
artifact.version.toString().green() +
' (runtime)'.grey();
} else {
} else if (artifact.scope == Scope.compile) {
connector += artifact.groupId.blue() +
':'.grey() +
artifact.artifactId.blue() +
':'.grey() +
artifact.version.toString().blue() +
' (compile)'.grey();
} else {
connector += artifact.groupId.magenta() +
':'.grey() +
artifact.artifactId.magenta() +
':'.grey() +
artifact.version.toString().magenta() +
' (provided)'.grey();
}

if (isPrinted && hasDeps) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/config/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Config {
@JsonKey(disallowNullValue: true)
final List<String> dependencies;

// @JsonKey(name: 'comptime_dependencies', disallowNullValue: true)
// final List<String> comptimeDeps;
@JsonKey(name: 'provided_dependencies', disallowNullValue: true)
final List<String> providedDependencies;

@JsonKey(name: 'min_sdk', disallowNullValue: true)
final int minSdk;
Expand Down Expand Up @@ -60,7 +60,7 @@ class Config {
this.assets = const [],
this.authors = const [],
this.dependencies = const [],
// this.comptimeDeps = const [],
this.providedDependencies = const [],
this.repositories = const [],
this.kotlin = const Kotlin(compilerVersion: defaultKtVersion),
});
Expand Down
2 changes: 2 additions & 0 deletions lib/src/resolver/resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ class ArtifactResolver {
return dep.scope == Scope.compile.name ||
dep.scope == Scope.runtime.name;
}
// We don't resolve dependencies of any other scopes, specifically the
// provided scope
return false;
});

Expand Down
Loading

0 comments on commit 0afa249

Please sign in to comment.