Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
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
56 changes: 54 additions & 2 deletions tools/engine_tool/lib/src/build_plan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import 'build_utils.dart';
import 'environment.dart';
import 'logger.dart';

const _flagBuildDart = 'build-dart';
const _flagBuildDartFull = 'build-dart-full';
const _flagConfig = 'config';
const _flagConcurrency = 'concurrency';
const _flagStrategy = 'build-strategy';
Expand Down Expand Up @@ -65,6 +67,15 @@ final class BuildPlan {
}
return !build.gn.contains('--no-lto');
}(),
buildDart: () {
if (args.flag(_flagBuildDartFull)) {
return BuildDart.buildFull;
}
if (args.flag(_flagBuildDart)) {
return BuildDart.build;
}
return BuildDart.prebuilt;
}(),
concurrency: () {
final value = args.option(_flagConcurrency);
if (value == null) {
Expand All @@ -84,6 +95,7 @@ final class BuildPlan {
required this.useRbe,
required this.useLto,
required this.concurrency,
required this.buildDart,
}) {
if (!useRbe && strategy == BuildStrategy.remote) {
throw FatalError(
Expand Down Expand Up @@ -156,6 +168,16 @@ final class BuildPlan {
}(),
);

/// Adds the --build-dart and --build-dart-full flags.
parser.addFlag(
_flagBuildDart,
help: 'Build Dart from source.',
);
parser.addFlag(
_flagBuildDartFull,
help: 'Build the full Dart SDK from source.',
);

// Add --build-strategy.
parser.addOption(
_flagStrategy,
Expand Down Expand Up @@ -201,19 +223,30 @@ final class BuildPlan {
/// Whether to build with LTO (link-time optimization).
final bool useLto;

/// Whether to build Dart from source or not.
final BuildDart buildDart;

@override
bool operator ==(Object other) {
return other is BuildPlan &&
build.name == other.build.name &&
strategy == other.strategy &&
useRbe == other.useRbe &&
useLto == other.useLto &&
concurrency == other.concurrency;
concurrency == other.concurrency &&
buildDart == other.buildDart;
}

@override
int get hashCode {
return Object.hash(build.name, strategy, useRbe, useLto, concurrency);
return Object.hash(
build.name,
strategy,
useRbe,
useLto,
concurrency,
buildDart,
);
}

/// Converts this build plan to its equivalent [RbeConfig].
Expand All @@ -236,6 +269,12 @@ final class BuildPlan {
return [
if (!useRbe) '--no-rbe',
if (useLto) '--lto' else '--no-lto',
if (buildDart == BuildDart.build)
'--no-prebuilt-dart-sdk'
else if (buildDart == BuildDart.buildFull) ...[
'--no-prebuilt-dart-sdk',
'--full-dart-sdk',
],
];
}

Expand All @@ -246,6 +285,7 @@ final class BuildPlan {
buffer.writeln(' build: ${build.name}');
buffer.writeln(' useLto: $useLto');
buffer.writeln(' useRbe: $useRbe');
buffer.writeln(' build dart: ${buildDart.name}');
buffer.writeln(' strategy: $strategy');
buffer.writeln(' concurrency: $concurrency');
buffer.write('>');
Expand Down Expand Up @@ -277,3 +317,15 @@ enum BuildStrategy {
const BuildStrategy(this._help);
final String _help;
}

/// Whether to build Dart from source or not.
enum BuildDart {
/// Use the prebuilt Dart.
prebuilt,

/// Build Dart from source.
build,

/// Build the full Dart SDK from source.
buildFull,
}
1 change: 1 addition & 0 deletions tools/engine_tool/lib/src/commands/build_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ et build //flutter/fml:fml_benchmarks # Build a specific target in `//flutter/f
environment,
plan.build,
enableRbe: plan.useRbe,
extraGnArgs: plan.toGnArgs(),
)) {
return 1;
}
Expand Down
1 change: 1 addition & 0 deletions tools/engine_tool/lib/src/commands/query_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ et query targets //flutter/fml/... # List all targets under `//flutter/fml`
environment,
plan.build,
enableRbe: plan.useRbe,
extraGnArgs: plan.toGnArgs(),
)) {
return 1;
}
Expand Down
2 changes: 2 additions & 0 deletions tools/engine_tool/lib/src/commands/test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
environment,
plan.build,
enableRbe: plan.useRbe,
extraGnArgs: plan.toGnArgs(),
)) {
return 1;
}
Expand Down Expand Up @@ -96,6 +97,7 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
targets: testTargets.map((target) => target.label).toList(),
enableRbe: plan.useRbe,
rbeConfig: plan.toRbeConfig(),
extraGnArgs: plan.toGnArgs(),
);
if (buildExitCode != 0) {
return buildExitCode;
Expand Down
123 changes: 123 additions & 0 deletions tools/engine_tool/test/build_plan_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,129 @@ void main() {
);
});

test('dart build defaults to prebuilt', () {
final testEnv = TestEnvironment.withTestEngine(
withRbe: true,
);
addTearDown(testEnv.cleanup);

final testConfig = TestBuilderConfig();
testConfig.addBuild(
name: 'linux/host_debug',
dimension: TestDroneDimension.linux,
);

final parser = ArgParser();
final builds = BuildPlan.configureArgParser(
parser,
testEnv.environment,
configs: {
'linux_test_config': testConfig.buildConfig(
path: 'ci/builders/linux_test_config.json',
),
},
help: false,
);

final plan = BuildPlan.fromArgResults(
parser.parse([]),
testEnv.environment,
builds: builds,
);

expect(plan.buildDart, BuildDart.prebuilt);
expect(
plan.toGnArgs(),
isNot(contains('--no-prebuilt-dart-sdk')),
);
expect(
plan.toGnArgs(),
isNot(contains('--full-dart-sdk')),
);
});

test('dart build can be set to from source', () {
final testEnv = TestEnvironment.withTestEngine(
withRbe: true,
);
addTearDown(testEnv.cleanup);

final testConfig = TestBuilderConfig();
testConfig.addBuild(
name: 'linux/host_debug',
dimension: TestDroneDimension.linux,
);

final parser = ArgParser();
final builds = BuildPlan.configureArgParser(
parser,
testEnv.environment,
configs: {
'linux_test_config': testConfig.buildConfig(
path: 'ci/builders/linux_test_config.json',
),
},
help: false,
);

final plan = BuildPlan.fromArgResults(
parser.parse(['--build-dart']),
testEnv.environment,
builds: builds,
);

expect(plan.buildDart, BuildDart.build);
expect(
plan.toGnArgs(),
contains('--no-prebuilt-dart-sdk'),
);
expect(
plan.toGnArgs(),
isNot(contains('--full-dart-sdk')),
);
});

test('dart build can be set to full', () {
final testEnv = TestEnvironment.withTestEngine(
withRbe: true,
);
addTearDown(testEnv.cleanup);

final testConfig = TestBuilderConfig();
testConfig.addBuild(
name: 'linux/host_debug',
dimension: TestDroneDimension.linux,
);

final parser = ArgParser();
final builds = BuildPlan.configureArgParser(
parser,
testEnv.environment,
configs: {
'linux_test_config': testConfig.buildConfig(
path: 'ci/builders/linux_test_config.json',
),
},
help: false,
);

final plan = BuildPlan.fromArgResults(
parser.parse(['--build-dart-full']),
testEnv.environment,
builds: builds,
);

expect(plan.buildDart, BuildDart.buildFull);
expect(
plan.toGnArgs(),
contains('--no-prebuilt-dart-sdk'),
);
expect(
plan.toGnArgs(),
contains('--full-dart-sdk'),
);
});

test('build defaults to host_debug', () {
final testEnv = TestEnvironment.withTestEngine(
withRbe: true,
Expand Down