Skip to content

Commit

Permalink
build_transformer: add support for dart workspaces
Browse files Browse the repository at this point in the history
iteratively look for the root .dart_tools folder containing package_config.json
  • Loading branch information
takenagain committed Dec 30, 2024
1 parent 38d35cf commit 8bc5fa3
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/komodo_defi_framework/app_build/build_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"coins": {
"fetch_at_build_enabled": true,
"update_commit_on_build": true,
"bundled_coins_repo_commit": "78be0d03414110e38f27521bd8b5a85e24cee3a0",
"bundled_coins_repo_commit": "f0c99218eb738a265fb35e5d72578e67d25bc2f9",
"coins_repo_api_url": "https://api.github.com/repos/KomodoPlatform/coins",
"coins_repo_content_url": "https://komodoplatform.github.io/coins",
"coins_repo_branch": "master",
Expand Down
21 changes: 20 additions & 1 deletion packages/komodo_defi_sdk/example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
PODS:
- flutter_inappwebview_macos (0.0.1):
- FlutterMacOS
- OrderedSet (~> 6.0.3)
- flutter_secure_storage_macos (6.1.1):
- FlutterMacOS
- FlutterMacOS (1.0.0)
Expand All @@ -7,22 +10,33 @@ PODS:
- local_auth_darwin (0.0.1):
- Flutter
- FlutterMacOS
- OrderedSet (6.0.3)
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- url_launcher_macos (0.0.1):
- FlutterMacOS

DEPENDENCIES:
- flutter_inappwebview_macos (from `Flutter/ephemeral/.symlinks/plugins/flutter_inappwebview_macos/macos`)
- flutter_secure_storage_macos (from `Flutter/ephemeral/.symlinks/plugins/flutter_secure_storage_macos/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- komodo_defi_framework (from `Flutter/ephemeral/.symlinks/plugins/komodo_defi_framework/macos`)
- local_auth_darwin (from `Flutter/ephemeral/.symlinks/plugins/local_auth_darwin/darwin`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)

SPEC REPOS:
trunk:
- OrderedSet

EXTERNAL SOURCES:
flutter_inappwebview_macos:
:path: Flutter/ephemeral/.symlinks/plugins/flutter_inappwebview_macos/macos
flutter_secure_storage_macos:
:path: Flutter/ephemeral/.symlinks/plugins/flutter_secure_storage_macos/macos
FlutterMacOS:
Expand All @@ -35,14 +49,19 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
shared_preferences_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin
url_launcher_macos:
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos

SPEC CHECKSUMS:
flutter_inappwebview_macos: bdf207b8f4ebd58e86ae06cd96b147de99a67c9b
flutter_secure_storage_macos: 59459653abe1adb92abbc8ea747d79f8d19866c9
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
komodo_defi_framework: f716eeef2f8d5cd3a97efe7bb103e8e18285032c
komodo_defi_framework: f0b88d0dfa7907a9ece425bf4f1435cd94cfdc73
local_auth_darwin: 66e40372f1c29f383a314c738c7446e2f7fdadc3
OrderedSet: e539b66b644ff081c73a262d24ad552a69be3a94
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
url_launcher_macos: c82c93949963e55b228a30115bd219499a6fe404

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void main(List<String> arguments) async {
final canRunConcurrent = _argResults.flag('concurrent');

final artifactOutputPackage = getDependencyDirectory(
_projectRoot.path,
_projectRoot,
_argResults.option('artifact_output_package')!,
)?.absolute ??
(throw Exception('Artifact output package not found'));
Expand Down
69 changes: 46 additions & 23 deletions packages/komodo_wallet_build_transformer/lib/src/util/cli_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ import 'package:path/path.dart' as path;
///
/// [projectPath] is the directory of the specified project.
/// [dependencyName] is the name of the dependency to look up.
Directory? getDependencyDirectory(String projectPath, String dependencyName) {
Directory? getDependencyDirectory(
Directory projectPath,
String dependencyName,
) {
final log = Logger('komodo_wallet_build_transformer');
final packageConfigFile =
File(path.join(projectPath, '.dart_tool', 'package_config.json'))
.absolute;

final projectDir = Directory(projectPath).absolute;
// Find the root .dart_tool directory by traversing up
final dartToolDir = _findDartToolDirectory(projectPath);
if (dartToolDir == null) {
throw Exception(
'Could not find .dart_tool directory in any parent directory of '
'$projectPath',
);
}

final packageConfigFile = File(
path.join(dartToolDir.path, 'package_config.json'),
).absolute;

if (!packageConfigFile.existsSync()) {
throw Exception(
'package_config.json not found in $projectPath/.dart_tool/',
'package_config.json not found in ${dartToolDir.path}',
);
}

Expand All @@ -33,25 +44,11 @@ Directory? getDependencyDirectory(String projectPath, String dependencyName) {

final packages = packageConfig['packages'] as List;

Directory? projectPackageDir;
String? packageRootUri;

for (final package in packages) {
final rootUri = package['rootUri'] as String;

final packageRoot = path.join(packageConfigFile.parent.path, rootUri);

// Check if packageConfigFile + rootUri is the same as the projectDir
if (path.equals(packageRoot, projectDir.path)) {
projectPackageDir = Directory(
path.normalize(
path.join(packageRoot, package['packageUri'] as String?),
),
);

log.info('Found package $dependencyName at $projectPackageDir');
}

if (package['name'] == dependencyName) {
if (rootUri.startsWith('file:///')) {
return Directory(path.fromUri(Uri.parse(rootUri)));
Expand All @@ -61,19 +58,45 @@ Directory? getDependencyDirectory(String projectPath, String dependencyName) {
log.info('Found package $dependencyName at $packageRootUri');
}

if (projectPackageDir != null && packageRootUri != null) {
if (packageRootUri != null) {
break;
}
}

if (packageRootUri != null && projectPackageDir != null) {
return resolvePackageDirectory(projectPackageDir, packageRootUri);
if (packageRootUri != null) {
return resolvePackageDirectory(dartToolDir, packageRootUri);
}

log.warning('Dependency $dependencyName not found in package_config.json');
return null;
}

/// Finds the .dart_tool directory by traversing up the directory tree
/// until it is found or the root directory is reached.
Directory? _findDartToolDirectory(Directory startDir) {
Directory? currentDir = startDir.absolute;

while (currentDir != null) {
final dartToolDir = Directory(path.join(currentDir.path, '.dart_tool'));
final packageConfigFile =
File(path.join(dartToolDir.path, 'package_config.json'));

if (dartToolDir.existsSync() && packageConfigFile.existsSync()) {
return dartToolDir;
}

final parentDir = path.dirname(currentDir.path);
if (parentDir == currentDir.path) {
// We've reached the root directory
return null;
}

currentDir = Directory(parentDir);
}

return null;
}

/// Resolves the package directory from the [projectPackageDir] and the
/// [packageRootUri]. If the [packageRootUri] is a relative path, it will be
/// resolved from the [projectPackageDir]. Otherwise, it will be joined with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ Level logLevelFromString(String level) {
/// The [allowStackTracesFromLevel] is the minimum level of log messages that
/// will have their stack traces printed.
/// By default, stack traces are only printed for log messages at the
/// [Level.WARNING] level or higher.
/// [Level.SEVERE] level or higher.
/// If [allowStackTracesFromLevel] is set to [Level.ALL], stack traces will
/// be printed for all log messages.
/// If [allowStackTracesFromLevel] is set to [Level.OFF], stack traces will
/// not be printed for any log messages.
void configureLogToConsole(
String loggingLevel, {
Level allowStackTracesFromLevel = Level.WARNING,
Level allowStackTracesFromLevel = Level.SEVERE,
}) {
recordStackTraceAtLevel = allowStackTracesFromLevel;
Logger.root.level = logLevelFromString(loggingLevel);
Expand Down

0 comments on commit 8bc5fa3

Please sign in to comment.