Skip to content

Commit

Permalink
Fix cache location, artifacts, and re-enable dart2js test (flutter#29783
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jonahwilliams authored Mar 26, 2019
1 parent 7cf4a6d commit 44b22c7
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
23 changes: 11 additions & 12 deletions dev/bots/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,21 @@ Future<void> _runBuildTests() async {
await _flutterBuildApk(path);
await _flutterBuildIpa(path);
}
// TODO(jonahwilliams): re-enable when engine rolls.
//await _flutterBuildDart2js(path.join('dev', 'integration_tests', 'web'));
await _flutterBuildDart2js(path.join('dev', 'integration_tests', 'web'));

print('${bold}DONE: All build tests successful.$reset');
}

// Future<void> _flutterBuildDart2js(String relativePathToApplication) async {
// print('Running Dart2JS build tests...');
// await runCommand(flutter,
// <String>['build', 'web', '-v'],
// workingDirectory: path.join(flutterRoot, relativePathToApplication),
// expectNonZeroExit: false,
// timeout: _kShortTimeout,
// );
// print('Done.');
// }
Future<void> _flutterBuildDart2js(String relativePathToApplication) async {
print('Running Dart2JS build tests...');
await runCommand(flutter,
<String>['build', 'web', '-v'],
workingDirectory: path.join(flutterRoot, relativePathToApplication),
expectNonZeroExit: false,
timeout: _kShortTimeout,
);
print('Done.');
}

Future<void> _flutterBuildAot(String relativePathToApplication) async {
print('Running AOT build tests...');
Expand Down
20 changes: 18 additions & 2 deletions packages/flutter_tools/lib/src/artifacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum Artifact {
engineDartBinary,
dart2jsSnapshot,
kernelWorkerSnapshot,
flutterWebSdk,
}

String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMode mode ]) {
Expand Down Expand Up @@ -66,16 +67,19 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo
case Artifact.flutterPatchedSdkPath:
assert(false, 'No filename for sdk path, should not be invoked');
return null;
case Artifact.flutterWebSdk:
assert(false, 'No filename for web sdk path, should not be invoked');
return null;
case Artifact.engineDartSdkPath:
return 'dart-sdk';
case Artifact.frontendServerSnapshotForEngineDartSdk:
return 'frontend_server.dart.snapshot';
case Artifact.engineDartBinary:
return 'dart';
case Artifact.dart2jsSnapshot:
return 'flutter_dart2js.dart.snapshot';
return 'dart2js.dart.snapshot';
case Artifact.kernelWorkerSnapshot:
return 'flutter_kernel_worker.dart.snapshot';
return 'kernel_worker.dart.snapshot';
}
assert(false, 'Invalid artifact $artifact.');
return null;
Expand Down Expand Up @@ -174,6 +178,10 @@ class CachedArtifacts extends Artifacts {
return fs.path.join(engineArtifactsPath, 'common', 'flutter_patched_sdk');
}

String _getFlutterWebSdkPath() {
return cache.getWebSdkDirectory().path;
}

String _getHostArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
switch (artifact) {
case Artifact.genSnapshot:
Expand All @@ -197,6 +205,8 @@ class CachedArtifacts extends Artifacts {
return fs.path.join(_getFlutterPatchedSdkPath(), 'lib', _artifactToFileName(artifact));
case Artifact.flutterPatchedSdkPath:
return _getFlutterPatchedSdkPath();
case Artifact.flutterWebSdk:
return _getFlutterWebSdkPath();
case Artifact.dart2jsSnapshot:
return fs.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact));
case Artifact.kernelWorkerSnapshot:
Expand Down Expand Up @@ -271,6 +281,8 @@ class LocalEngineArtifacts extends Artifacts {
return fs.path.join(engineOutPath, _artifactToFileName(artifact));
case Artifact.flutterPatchedSdkPath:
return _getFlutterPatchedSdkPath();
case Artifact.flutterWebSdk:
return _getFlutterWebSdkPath();
case Artifact.frontendServerSnapshotForEngineDartSdk:
return fs.path.join(_hostEngineOutPath, 'gen', _artifactToFileName(artifact));
case Artifact.engineDartSdkPath:
Expand All @@ -295,6 +307,10 @@ class LocalEngineArtifacts extends Artifacts {
return fs.path.join(engineOutPath, 'flutter_patched_sdk');
}

String _getFlutterWebSdkPath() {
return fs.path.join(engineOutPath, 'flutter_web_sdk');
}

String _genSnapshotPath() {
const List<String> clangDirs = <String>['.', 'clang_x86', 'clang_x64', 'clang_i386'];
final String genSnapshotName = _artifactToFileName(Artifact.genSnapshot);
Expand Down
17 changes: 15 additions & 2 deletions packages/flutter_tools/lib/src/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class FlutterWebSdk extends CachedArtifact {
String get version => cache.getVersionFor('engine');

@override
Future<void> updateInner() {
Future<void> updateInner() async {
String platformName = 'flutter-web-sdk-';
if (platform.isMacOS) {
platformName += 'darwin-x64';
Expand All @@ -388,7 +388,20 @@ class FlutterWebSdk extends CachedArtifact {
platformName += 'windows-x64';
}
final Uri url = Uri.parse('$_storageBaseUrl/flutter_infra/flutter/$version/$platformName.zip');
return _downloadZipArchive('Downloading Web SDK...', url, location);
await _downloadZipArchive('Downloading Web SDK...', url, location);
// This is a temporary work-around for not being able to safely download into a shared directory.
for (FileSystemEntity entity in location.listSync(recursive: true)) {
if (entity is File) {
final List<String> segments = fs.path.split(entity.path);
segments.remove('flutter_web_sdk');
final String newPath = fs.path.joinAll(segments);
final File newFile = fs.file(newPath);
if (!newFile.existsSync()) {
newFile.createSync(recursive: true);
}
entity.copySync(newPath);
}
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions packages/flutter_tools/lib/src/commands/build_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import 'dart:async';

import '../base/common.dart';
import '../base/logger.dart';
import '../build_info.dart';
import '../globals.dart';
import '../runner/flutter_command.dart' show ExitStatus, FlutterCommandResult;
import '../runner/flutter_command.dart' show FlutterCommandResult;
import '../web/compile.dart';
import 'build.dart';

Expand All @@ -33,6 +34,9 @@ class BuildWebCommand extends BuildSubCommand {
final Status status = logger.startProgress('Compiling $target to JavaScript...', timeout: null);
final int result = await webCompiler.compile(target: target);
status.stop();
return FlutterCommandResult(result == 0 ? ExitStatus.success : ExitStatus.fail);
if (result == 1) {
throwToolExit('Failed to compile $target to JavaScript.');
}
return null;
}
}
5 changes: 2 additions & 3 deletions packages/flutter_tools/lib/src/web/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class WebCompiler {
Future<int> compile({@required String target, bool minify = true, bool enabledAssertions = false}) async {
final String engineDartPath = artifacts.getArtifactPath(Artifact.engineDartBinary);
final String dart2jsPath = artifacts.getArtifactPath(Artifact.dart2jsSnapshot);
final String flutterPatchedSdkPath = artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath);
final String librariesPath = fs.path.join(flutterPatchedSdkPath, 'libraries.json');
final String flutterWebSdkPath = artifacts.getArtifactPath(Artifact.flutterWebSdk);
final String librariesPath = fs.path.join(flutterWebSdkPath, 'libraries.json');
final Directory outputDir = fs.directory(getWebBuildDirectory());
if (!outputDir.existsSync()) {
outputDir.createSync(recursive: true);
Expand All @@ -46,7 +46,6 @@ class WebCompiler {
'-o',
'$outputPath',
'--libraries-spec=$librariesPath',
'--platform-binaries=$flutterPatchedSdkPath',
];
if (minify) {
command.add('-m');
Expand Down
5 changes: 2 additions & 3 deletions packages/flutter_tools/test/web/compile_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ void main() {
const WebCompiler webCompiler = WebCompiler();
final String engineDartPath = artifacts.getArtifactPath(Artifact.engineDartBinary);
final String dart2jsPath = artifacts.getArtifactPath(Artifact.dart2jsSnapshot);
final String flutterPatchedSdkPath = artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath);
final String librariesPath = fs.path.join(flutterPatchedSdkPath, 'libraries.json');
final String flutterWebSdkPath = artifacts.getArtifactPath(Artifact.flutterWebSdk);
final String librariesPath = fs.path.join(flutterWebSdkPath, 'libraries.json');

when(mockProcess.stdout).thenAnswer((Invocation invocation) => const Stream<List<int>>.empty());
when(mockProcess.stderr).thenAnswer((Invocation invocation) => const Stream<List<int>>.empty());
Expand All @@ -41,7 +41,6 @@ void main() {
'-o',
outputPath,
'--libraries-spec=$librariesPath',
'--platform-binaries=$flutterPatchedSdkPath',
'-m',
])).called(1);
}, overrides: <Type, Generator>{
Expand Down

0 comments on commit 44b22c7

Please sign in to comment.