forked from dart-lang/native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
package:native_assets_builder
(dart-lang#69)
- Loading branch information
Showing
66 changed files
with
2,119 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
# This configures the .github/workflows/pull_request_label.yml workflow. | ||
# This configures the .github/workflows/pull_request_label.yml workflow. | ||
|
||
'type-infra': | ||
- '.github/**' | ||
|
||
'package:c_compiler': | ||
- pkgs/c_compiler/**/* | ||
|
||
'package:native_assets_builder': | ||
- pkgs/native_assets_builder/**/* | ||
|
||
'package:native_assets_cli': | ||
- pkgs/native_assets_cli/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Below is a list of people and organizations that have contributed | ||
# to the Dart project. Names should be added to the list like so: | ||
# | ||
# Name/Organization <email address> | ||
|
||
Google LLC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# https://dart.dev/guides/libraries/private-files | ||
# Created by `dart pub` | ||
.dart_tool/ | ||
|
||
# Avoid committing pubspec.lock for library packages; see | ||
# https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
pubspec.lock | ||
|
||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright 2023, the Dart project authors. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of Google LLC nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This package contains the logic for building native assets. | ||
|
||
This package is the backend that invokes toplevel `build.dart` scripts. | ||
For more info on these scripts see https://github.com/dart-lang/native. | ||
|
||
This is a separate package so that dartdev and flutter_tools can reuse | ||
the same logic with flutter_tools having to import dartdev. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
include: package:dart_flutter_team_lints/analysis_options.yaml | ||
|
||
analyzer: | ||
language: | ||
strict-raw-types: true | ||
strict-inference: true | ||
|
||
linter: | ||
rules: | ||
- always_declare_return_types | ||
- avoid_dynamic_calls | ||
- camel_case_types | ||
- depend_on_referenced_packages | ||
- directives_ordering | ||
- prefer_const_declarations | ||
- prefer_expression_function_bodies | ||
- prefer_final_in_for_each | ||
- prefer_final_locals | ||
- prefer_relative_imports | ||
- prefer_single_quotes | ||
- sort_pub_dependencies | ||
- unawaited_futures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
paths: | ||
- test/build_runner/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
export 'package:native_assets_builder/src/build_runner/build_runner.dart'; | ||
export 'package:native_assets_builder/src/package_layout/package_layout.dart'; |
101 changes: 101 additions & 0 deletions
101
pkgs/native_assets_builder/lib/src/build_runner/build_planner.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:graphs/graphs.dart' as graphs; | ||
import 'package:package_config/package_config.dart'; | ||
|
||
class NativeAssetsBuildPlanner { | ||
final PackageGraph packageGraph; | ||
final List<Package> packagesWithNativeAssets; | ||
final Uri dartExecutable; | ||
|
||
NativeAssetsBuildPlanner({ | ||
required this.packageGraph, | ||
required this.packagesWithNativeAssets, | ||
required this.dartExecutable, | ||
}); | ||
|
||
static Future<NativeAssetsBuildPlanner> fromRootPackageRoot({ | ||
required Uri rootPackageRoot, | ||
required List<Package> packagesWithNativeAssets, | ||
required Uri dartExecutable, | ||
}) async { | ||
final result = await Process.run( | ||
dartExecutable.toFilePath(), | ||
[ | ||
'pub', | ||
'deps', | ||
'--json', | ||
], | ||
workingDirectory: rootPackageRoot.toFilePath(), | ||
); | ||
final packageGraph = | ||
PackageGraph.fromPubDepsJsonString(result.stdout as String); | ||
return NativeAssetsBuildPlanner( | ||
packageGraph: packageGraph, | ||
packagesWithNativeAssets: packagesWithNativeAssets, | ||
dartExecutable: dartExecutable, | ||
); | ||
} | ||
|
||
List<Package> plan() { | ||
final packageMap = { | ||
for (final package in packagesWithNativeAssets) package.name: package | ||
}; | ||
final packagesToBuild = packageMap.keys.toSet(); | ||
final stronglyConnectedComponents = packageGraph.computeStrongComponents(); | ||
final result = <Package>[]; | ||
for (final stronglyConnectedComponent in stronglyConnectedComponents) { | ||
final stronglyConnectedComponentWithNativeAssets = [ | ||
for (final packageName in stronglyConnectedComponent) | ||
if (packagesToBuild.contains(packageName)) packageName | ||
]; | ||
if (stronglyConnectedComponentWithNativeAssets.length > 1) { | ||
throw Exception( | ||
'Cyclic dependency for native asset builds in the following ' | ||
'packages: $stronglyConnectedComponent.', | ||
); | ||
} else if (stronglyConnectedComponentWithNativeAssets.length == 1) { | ||
result.add( | ||
packageMap[stronglyConnectedComponentWithNativeAssets.single]!); | ||
} | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
class PackageGraph { | ||
final Map<String, List<String>> map; | ||
|
||
PackageGraph(this.map); | ||
|
||
/// Construct a graph from the JSON produced by `dart pub deps --json`. | ||
factory PackageGraph.fromPubDepsJsonString(String json) => | ||
PackageGraph.fromPubDepsJson(jsonDecode(json) as Map<dynamic, dynamic>); | ||
|
||
/// Construct a graph from the JSON produced by `dart pub deps --json`. | ||
factory PackageGraph.fromPubDepsJson(Map<dynamic, dynamic> map) { | ||
final result = <String, List<String>>{}; | ||
final packages = map['packages'] as List<dynamic>; | ||
for (final package in packages) { | ||
final package_ = package as Map<dynamic, dynamic>; | ||
final name = package_['name'] as String; | ||
final dependencies = (package_['dependencies'] as List<dynamic>) | ||
.whereType<String>() | ||
.toList(); | ||
result[name] = dependencies; | ||
} | ||
return PackageGraph(result); | ||
} | ||
|
||
Iterable<String> neighborsOf(String vertex) => map[vertex] ?? []; | ||
|
||
Iterable<String> get vertices => map.keys; | ||
|
||
List<List<String>> computeStrongComponents() => | ||
graphs.stronglyConnectedComponents(vertices, neighborsOf); | ||
} |
Oops, something went wrong.