Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/flutter_tools/bin/macos_assemble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ RunCommand "${FLUTTER_ROOT}/bin/flutter" --suppress-analytics \
-dBuildMode="${build_mode}" \
--build-inputs="${build_inputs_path}" \
--build-outputs="${build_outputs_path}" \
--output="${ephemeral_dir}" \
"${build_mode}_macos_bundle_flutter_assets"
14 changes: 13 additions & 1 deletion packages/flutter_tools/lib/src/build_system/build_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class Environment {
/// defaults based on it.
factory Environment({
@required Directory projectDir,
@required Directory outputDir,
Directory buildDir,
Map<String, String> defines = const <String, String>{},
}) {
Expand All @@ -371,6 +372,7 @@ class Environment {
final Directory rootBuildDir = buildDir ?? projectDir.childDirectory('build');
final Directory buildDirectory = rootBuildDir.childDirectory(buildPrefix);
return Environment._(
outputDir: outputDir,
projectDir: projectDir,
buildDir: buildDirectory,
rootBuildDir: rootBuildDir,
Expand All @@ -381,6 +383,7 @@ class Environment {
}

Environment._({
@required this.outputDir,
@required this.projectDir,
@required this.buildDir,
@required this.rootBuildDir,
Expand All @@ -401,6 +404,9 @@ class Environment {
/// The [Source] value which is substituted with a path to the flutter root.
static const String kFlutterRootDirectory = '{FLUTTER_ROOT}';

/// The [Source] value which is substituted with a path to [outputDir].
static const String kOutputDirectory = '{OUTPUT_DIR}';

/// The `PROJECT_DIR` environment variable.
///
/// This should be root of the flutter project where a pubspec and dart files
Expand All @@ -424,6 +430,11 @@ class Environment {
/// Defaults to to the value of [Cache.flutterRoot].
final Directory flutterRootDir;

/// The `OUTPUT_DIR` environment variable.
///
/// Must be provided to configure the output location for the final artifacts.
final Directory outputDir;

/// Additional configuration passed to the build targets.
///
/// Setting values here forces a unique build directory to be chosen
Expand Down Expand Up @@ -464,6 +475,7 @@ class BuildSystem {
{ BuildSystemConfig buildSystemConfig = const BuildSystemConfig() }
) async {
environment.buildDir.createSync(recursive: true);
environment.outputDir.createSync(recursive: true);

// Load file hash store from previous builds.
final FileHashStore fileCache = FileHashStore(environment)
Expand All @@ -482,7 +494,7 @@ class BuildSystem {
}
// TODO(jonahwilliams): this is a bit of a hack, due to various parts of
// the flutter tool writing these files unconditionally. Since Xcode uses
// timestamps to track files, this leads to unecessary rebuilds if they
// timestamps to track files, this leads to unnecessary rebuilds if they
// are included. Once all the places that write these files have been
// tracked down and moved into assemble, these checks should be removable.
// We also remove files under .dart_tool, since these are intermediaries
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter_tools/lib/src/build_system/source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class SourceVisitor {
segments.addAll(
fs.path.split(environment.flutterRootDir.absolute.path));
break;
case Environment.kOutputDirectory:
segments.addAll(
fs.path.split(environment.outputDir.resolveSymbolicLinksSync()));
break;
default:
throw InvalidPatternException(pattern);
}
Expand Down
42 changes: 17 additions & 25 deletions packages/flutter_tools/lib/src/build_system/targets/macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ import '../../build_info.dart';
import '../../devfs.dart';
import '../../globals.dart';
import '../../macos/xcode.dart';
import '../../project.dart';
import '../build_system.dart';
import '../exceptions.dart';
import 'dart.dart';

const String _kOutputPrefix = '{PROJECT_DIR}/macos/Flutter/ephemeral/FlutterMacOS.framework';
const String _kOutputPrefix = '{OUTPUT_DIR}/FlutterMacOS.framework';

/// The copying logic for flutter assets in macOS.
// TODO(jonahwilliams): remove once build planning lands.
Expand Down Expand Up @@ -51,8 +50,7 @@ class MacOSAssetBehavior extends SourceBehavior {
manifestPath: environment.projectDir.childFile('pubspec.yaml').path,
packagesPath: environment.projectDir.childFile('.packages').path,
);
final FlutterProject flutterProject = FlutterProject.fromDirectory(environment.projectDir);
final String prefix = fs.path.join(flutterProject.macos.ephemeralDirectory.path,
final String prefix = fs.path.join(environment.outputDir.path,
'App.framework', 'Versions', 'A', 'Resources', 'flutter_assets');
final List<File> results = <File>[];
for (String key in assetBundle.entries.keys) {
Expand All @@ -65,7 +63,7 @@ class MacOSAssetBehavior extends SourceBehavior {

/// Copy the macOS framework to the correct copy dir by invoking 'cp -R'.
///
/// This class is abstract to share logic between the three conrete
/// This class is abstract to share logic between the three concrete
/// implementations. The shelling out is done to avoid complications with
/// preserving special files (e.g., symbolic links) in the framework structure.
///
Expand Down Expand Up @@ -121,9 +119,8 @@ abstract class UnpackMacOS extends Target {
}
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
final String basePath = artifacts.getArtifactPath(Artifact.flutterMacOSFramework, mode: buildMode);
final FlutterProject flutterProject = FlutterProject.fromDirectory(environment.projectDir);
final Directory targetDirectory = flutterProject.macos
.ephemeralDirectory
final Directory targetDirectory = environment
.outputDir
.childDirectory('FlutterMacOS.framework');
if (targetDirectory.existsSync()) {
targetDirectory.deleteSync(recursive: true);
Expand Down Expand Up @@ -247,15 +244,14 @@ class CompileMacOSFramework extends Target {
if (buildMode == BuildMode.debug) {
throw Exception('precompiled macOS framework only supported in release/profile builds.');
}
final FlutterProject flutterProject = FlutterProject.fromDirectory(environment.projectDir);
final int result = await AOTSnapshotter(reportTimings: false).build(
bitcode: false,
buildMode: buildMode,
mainPath: environment.buildDir.childFile('app.dill').path,
outputPath: environment.buildDir.path,
platform: TargetPlatform.darwin_x64,
darwinArch: DarwinArch.x86_64,
packagesPath: flutterProject.packagesFile.path
packagesPath: environment.projectDir.childFile('.packages').path,
);
if (result != 0) {
throw Exception('gen shapshot failed.');
Expand Down Expand Up @@ -298,11 +294,11 @@ abstract class MacOSBundleFlutterAssets extends Target {
@override
List<Source> get outputs => const <Source>[
Source.behavior(MacOSAssetBehavior()),
Source.pattern('{PROJECT_DIR}/macos/Flutter/ephemeral/App.framework/Versions/A/App'),
Source.pattern('{PROJECT_DIR}/macos/Flutter/ephemeral/App.framework/Versions/A/Resources/Info.plist'),
Source.pattern('{PROJECT_DIR}/macos/Flutter/ephemeral/App.framework/Versions/A/Resources/flutter_assets/AssetManifest.json'),
Source.pattern('{PROJECT_DIR}/macos/Flutter/ephemeral/App.framework/Versions/A/Resources/flutter_assets/FontManifest.json'),
Source.pattern('{PROJECT_DIR}/macos/Flutter/ephemeral/App.framework/Versions/A/Resources/flutter_assets/LICENSE'),
Source.pattern('{OUTPUT_DIR}/App.framework/Versions/A/App'),
Source.pattern('{OUTPUT_DIR}/App.framework/Versions/A/Resources/Info.plist'),
Source.pattern('{OUTPUT_DIR}/App.framework/Versions/A/Resources/flutter_assets/AssetManifest.json'),
Source.pattern('{OUTPUT_DIR}/App.framework/Versions/A/Resources/flutter_assets/FontManifest.json'),
Source.pattern('{OUTPUT_DIR}/App.framework/Versions/A/Resources/flutter_assets/LICENSE'),
];

@override
Expand All @@ -311,9 +307,8 @@ abstract class MacOSBundleFlutterAssets extends Target {
throw MissingDefineException(kBuildMode, 'compile_macos_framework');
}
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
final FlutterProject flutterProject = FlutterProject.fromDirectory(environment.projectDir);
final Directory frameworkRootDirectory = flutterProject.macos
.ephemeralDirectory
final Directory frameworkRootDirectory = environment
.outputDir
.childDirectory('App.framework');
final Directory outputDirectory = frameworkRootDirectory
.childDirectory('Versions')
Expand Down Expand Up @@ -420,7 +415,6 @@ abstract class MacOSBundleFlutterAssets extends Target {
if (!currentVersion.existsSync()) {
final String linkPath = fs.path.relative(outputDirectory.path,
from: outputDirectory.parent.path);
print(linkPath);
currentVersion.createSync('$linkPath${fs.path.separator}');
}
// Create symlink to current resources.
Expand All @@ -429,7 +423,6 @@ abstract class MacOSBundleFlutterAssets extends Target {
if (!currentResources.existsSync()) {
final String linkPath = fs.path.relative(fs.path.join(currentVersion.path, 'Resources'),
from: frameworkRootDirectory.path);
print(linkPath);
currentResources.createSync(linkPath);
}
// Create symlink to current binary.
Expand All @@ -438,12 +431,11 @@ abstract class MacOSBundleFlutterAssets extends Target {
if (!currentFramework.existsSync()) {
final String linkPath = fs.path.relative(fs.path.join(currentVersion.path, 'App'),
from: frameworkRootDirectory.path);
print(linkPath);
currentFramework.createSync(linkPath);
}
} on FileSystemException {
throw Exception('Failed to create symlinks for framework. try removing '
'the "${flutterProject.macos.ephemeralDirectory.path}" directory and rerunning');
'the "${environment.outputDir.path}" directory and rerunning');
}
}
}
Expand Down Expand Up @@ -473,9 +465,9 @@ class DebugMacOSBundleFlutterAssets extends MacOSBundleFlutterAssets {
@override
List<Source> get outputs => <Source>[
...super.outputs,
const Source.pattern('{PROJECT_DIR}/macos/Flutter/ephemeral/App.framework/Versions/A/Resources/flutter_assets/kernel_blob.bin'),
const Source.pattern('{PROJECT_DIR}/macos/Flutter/ephemeral/App.framework/Versions/A/Resources/flutter_assets/vm_snapshot_data'),
const Source.pattern('{PROJECT_DIR}/macos/Flutter/ephemeral/App.framework/Versions/A/Resources/flutter_assets/isolate_snapshot_data'),
const Source.pattern('{OUTPUT_DIR}/App.framework/Versions/A/Resources/flutter_assets/kernel_blob.bin'),
const Source.pattern('{OUTPUT_DIR}/App.framework/Versions/A/Resources/flutter_assets/vm_snapshot_data'),
const Source.pattern('{OUTPUT_DIR}/App.framework/Versions/A/Resources/flutter_assets/isolate_snapshot_data'),
];
}

Expand Down
13 changes: 13 additions & 0 deletions packages/flutter_tools/lib/src/commands/assemble.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class AssembleCommand extends FlutterCommand {
'separated file containing all outputs used will be written after a build.'
' This file is not included as a build input or output. This file is not'
' written if the build fails for any reason.');
argParser.addOption('output', abbr: 'o', help: 'A directory where output '
'files will be written. Must be either absolute or relative from the '
'root of the current Flutter project.',
);
argParser.addOption(
'resource-pool-size',
help: 'The maximum number of concurrent tasks the build system will run.'
Expand Down Expand Up @@ -83,7 +87,16 @@ class AssembleCommand extends FlutterCommand {
/// The environmental configuration for a build invocation.
Environment get environment {
final FlutterProject flutterProject = FlutterProject.current();
String output = argResults['output'];
if (output == null) {
throwToolExit('--output directory is required for assemble.');
}
// If path is relative, make it absolute from flutter project.
if (fs.path.isRelative(output)) {
output = fs.path.join(flutterProject.directory.path, output);
}
final Environment result = Environment(
outputDir: fs.directory(output),
buildDir: flutterProject.directory
.childDirectory('.dart_tool')
.childDirectory('flutter_build'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void main() {
testbed = Testbed(
setup: () {
environment = Environment(
outputDir: fs.currentDirectory,
projectDir: fs.currentDirectory,
);
fs.file('foo.dart')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void main() {
testbed = Testbed(setup: () {
fs.directory('build').createSync();
environment = Environment(
outputDir: fs.currentDirectory,
projectDir: fs.currentDirectory,
);
environment.buildDir.createSync(recursive: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ void main() {
setUp(() {
testbed = Testbed(setup: () {
fs.directory('cache').createSync();
final Directory outputs = fs.directory('outputs')
..createSync();
environment = Environment(
outputDir: outputs,
projectDir: fs.currentDirectory,
buildDir: fs.directory('build'),
);
Expand All @@ -45,6 +48,15 @@ void main() {
expect(visitor.sources.single.path, fs.path.absolute('foo'));
}));

test('can substitute {OUTPUT_DIR}/foo', () => testbed.run(() {
fs.file('foo').createSync();
const Source fooSource = Source.pattern('{OUTPUT_DIR}/foo');
fooSource.accept(visitor);

expect(visitor.sources.single.path, fs.path.absolute(fs.path.join('outputs', 'foo')));
}));


test('can substitute {BUILD_DIR}/bar', () => testbed.run(() {
final String path = fs.path.join(environment.buildDir.path, 'bar');
fs.file(path).createSync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void main() {
setUp(() {
testbed = Testbed(setup: () {
environment = Environment(
outputDir: fs.currentDirectory,
projectDir: fs.currentDirectory,
);
fs.file(fs.path.join('packages', 'flutter_tools', 'lib', 'src',
Expand Down Expand Up @@ -71,6 +72,7 @@ flutter:
..writeAsStringSync('name: foo\ndependencies:\n foo: any\n');

await const FlutterPlugins().build(<File>[], Environment(
outputDir: fs.currentDirectory,
projectDir: fs.currentDirectory,
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ void main() {
mockProcessManager = MockProcessManager();
testbed = Testbed(setup: () {
androidEnvironment = Environment(
outputDir: fs.currentDirectory,
projectDir: fs.currentDirectory,
defines: <String, String>{
kBuildMode: getNameForBuildMode(BuildMode.profile),
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
}
);
iosEnvironment = Environment(
outputDir: fs.currentDirectory,
projectDir: fs.currentDirectory,
defines: <String, String>{
kBuildMode: getNameForBuildMode(BuildMode.profile),
Expand Down Expand Up @@ -158,6 +160,7 @@ flutter_tools:lib/''');
});

await const KernelSnapshot().build(<File>[], Environment(
outputDir: fs.currentDirectory,
projectDir: fs.currentDirectory,
defines: <String, String>{
kBuildMode: 'debug',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void main() {
testbed = Testbed(setup: () {
Cache.flutterRoot = '';
environment = Environment(
outputDir: fs.currentDirectory,
projectDir: fs.currentDirectory,
);
fs.file('bin/cache/artifacts/engine/linux-x64/libflutter_linux_glfw.so').createSync(recursive: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import '../../../src/common.dart';
import '../../../src/testbed.dart';

const String _kInputPrefix = 'bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework';
const String _kOutputPrefix = 'macos/Flutter/ephemeral/FlutterMacOS.framework';
const String _kOutputPrefix = 'FlutterMacOS.framework';

final List<File> inputs = <File>[
fs.file('$_kInputPrefix/FlutterMacOS'),
Expand Down Expand Up @@ -68,6 +68,7 @@ void main() {
'vmservice_io.dart')).createSync(recursive: true);

environment = Environment(
outputDir: fs.currentDirectory,
projectDir: fs.currentDirectory,
defines: <String, String>{
kBuildMode: 'debug',
Expand Down Expand Up @@ -126,13 +127,11 @@ void main() {
'isolate_snapshot.bin')).createSync(recursive: true);
fs.file(fs.path.join(environment.buildDir.path, 'App.framework', 'App'))
..createSync(recursive: true);
final String frameworkPath = fs.path.join(environment.projectDir.path,
'macos', 'Flutter', 'ephemeral', 'App.framework');

final String inputKernel = fs.path.join(environment.buildDir.path, 'app.dill');
fs.directory(frameworkPath).createSync(recursive: true);
final String outputKernel = fs.path.join(frameworkPath, 'Versions', 'A', 'Resources',
final String outputKernel = fs.path.join('App.framework', 'Versions', 'A', 'Resources',
'flutter_assets', 'kernel_blob.bin');
final String outputPlist = fs.path.join(frameworkPath, 'Versions', 'A', 'Resources',
final String outputPlist = fs.path.join('App.framework', 'Versions', 'A', 'Resources',
'Info.plist');
fs.file(inputKernel)
..createSync(recursive: true)
Expand All @@ -151,14 +150,11 @@ void main() {
'isolate_snapshot.bin')).createSync(recursive: true);
fs.file(fs.path.join(environment.buildDir.path, 'App.framework', 'App'))
..createSync(recursive: true);
final String frameworkPath = fs.path.join(environment.projectDir.path,
'macos', 'Flutter', 'ephemeral', 'App.framework');
fs.directory(frameworkPath).createSync(recursive: true);
final String outputKernel = fs.path.join(frameworkPath, 'Resources',
final String outputKernel = fs.path.join('App.framework', 'Resources',
'flutter_assets', 'kernel_blob.bin');
final String precompiledVm = fs.path.join(frameworkPath, 'Resources',
final String precompiledVm = fs.path.join('App.framework', 'Resources',
'flutter_assets', 'vm_snapshot_data');
final String precompiledIsolate = fs.path.join(frameworkPath, 'Resources',
final String precompiledIsolate = fs.path.join('App.framework', 'Resources',
'flutter_assets', 'isolate_snapshot_data');
await const ProfileMacOSBundleFlutterAssets().build(<File>[], environment..defines[kBuildMode] = 'profile');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void main() {
when(platform.pathSeparator).thenReturn(r'\');
testbed = Testbed(setup: () {
environment = Environment(
outputDir: fs.currentDirectory,
projectDir: fs.currentDirectory,
);
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_export.h').createSync(recursive: true);
Expand Down
Loading