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
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ group("flutter") {
public_deps += [
"//flutter/shell/testing",
"//flutter/tools/const_finder",
"//flutter/tools/engine_tool",
"//flutter/tools/font_subset",
]
}
Expand Down
114 changes: 114 additions & 0 deletions build/dart/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,117 @@ template("application_snapshot") {
}
}
}

# Generates an executable from Dart code using `dart compile exe`.
#
# This rule is primarily intended to be used to compile test targets for use
# by engine developers to build and run test code written in Dart in the engine
# repo, in particular via the `et` tool. It is NOT intended for use in
# generating production-ready user-facing binaries.
#
# See: //flutter/tools/engine_tool for more information on `et`.
#
# Arguments
# main_dart (required):
# The Dart entrypoint file.
#
# package_config (optional):
# The packages.json file for the Dart package (if any). Required when
# building libraries that are part of packages with Dart dependencies.
# Not needed when building standalone Dart code that is not part of a
# package.
#
# output (optional):
# The output executable name. By default, the target name. On Windows, an
# 'exe' is automatically appended.
#
# deps (optional):
# Additional dependencies. Dependencies on the frontend server and
# Flutter's platform.dill are included by default. This rule creates and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't create a depfile as written =)

# uses a depfile, so listing all Dart sources is not necessary.
template("dart_executable") {
assert(defined(invoker.main_dart), "Must specify 'main_dart'")

main_dart = invoker.main_dart

name = target_name

extra_deps = []
if (defined(invoker.deps)) {
extra_deps += invoker.deps
}
extra_inputs = [ main_dart ]
if (defined(invoker.inputs)) {
extra_inputs += invoker.inputs
}
if (defined(invoker.package_config)) {
package_config = rebase_path(invoker.package_config, root_build_dir)
extra_inputs += [ package_config ]
}

ext = ""
if (is_win) {
ext = ".exe"
}
output = "$target_gen_dir/$name$ext"
if (defined(invoker.output)) {
output = invoker.output
}

exe_vm_args = [ "--deterministic" ]
if (defined(invoker.vm_args)) {
exe_vm_args += invoker.vm_args
}

abs_output = rebase_path(output, root_build_dir)
exe_vm_args += [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how it's spelled, but we'll want to pass the flag here that disables analytics/telemetry.

"compile",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does dart compile exe run pub? If so, we'll need a way to keep it from touching the network.

Does dart compile exe have a flag that causes it to dump a depfile like flutter_frontend_server does? See https://github.com/flutter/engine/blob/main/build/dart/rules.gni#L71. Without that, GN won't do dependency tracking correctly. You might be able to see that in this PR by editing et source files, and seeing that rebuilds might not happen when you need them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does dart compile exe run pub?

That's a good question. I haven't looked at the implementation. My guess is probably, which we should avoid. Will take a look.

Does dart compile exe have a flag that causes it to dump a depfile like flutter_frontend_server does?

Not one that's documented (even with -v -v set). This patch is still a draft experiment to test the general concept/tool integration. It should work even if we swap out the implementation with an invocation of dart_snapshot (wrapped with a launch script) instead, that approach does support --depfile (and is already implemented above). Will play with that a little.

"exe",
"--output=$abs_output",
]
if (defined(package_config)) {
exe_vm_args += [ "--packages=$package_config" ]
}

if (flutter_prebuilt_dart_sdk) {
action(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
deps = extra_deps
script = "//build/gn_run_binary.py"
inputs = extra_inputs
outputs = [ output ]
pool = "//flutter/build/dart:dart_pool"

dart = rebase_path("$host_prebuilt_dart_sdk/bin/dart$ext", root_build_dir)

args = [ dart ]
args += exe_vm_args
args += [ rebase_path(main_dart) ]
metadata = {
action_type = [ "dart_executable" ]
}
}
} else {
dart_action(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
script = main_dart
pool = "//flutter/build/dart:dart_pool"
deps = extra_deps
inputs = extra_inputs
outputs = [ output ]
vm_args = exe_vm_args
args = []
metadata = {
action_type = [ "dart_executable" ]
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to send a patch upstream to copy this over onto the underlying action target in the dart_action template.

}
}
}
100 changes: 100 additions & 0 deletions tools/engine_tool/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//flutter/build/dart/rules.gni")

dart_executable("engine_tool") {
main_dart = "bin/et.dart"
output = "$root_out_dir/et"
}

group("tests") {
testonly = true
public_deps = [
":build_command_test",
":entry_point_test",
":fetch_command_test",
":format_command_test",
":gn_utils_test",
":lint_command_test",
":logger_test",
":proc_utils_test",
":query_command_test",
":run_command_test",
":test_command_test",
":worker_pool_test",
]
}

dart_executable("build_command_test") {
testonly = true
main_dart = "test/build_command_test.dart"
package_config = ".dart_tool/package_config.json"
}

dart_executable("entry_point_test") {
testonly = true
main_dart = "test/entry_point_test.dart"
package_config = ".dart_tool/package_config.json"
}

dart_executable("fetch_command_test") {
testonly = true
main_dart = "test/fetch_command_test.dart"
package_config = ".dart_tool/package_config.json"
}

dart_executable("format_command_test") {
testonly = true
main_dart = "test/format_command_test.dart"
package_config = ".dart_tool/package_config.json"
}

dart_executable("gn_utils_test") {
testonly = true
main_dart = "test/gn_utils_test.dart"
package_config = ".dart_tool/package_config.json"
}

dart_executable("lint_command_test") {
testonly = true
main_dart = "test/lint_command_test.dart"
package_config = ".dart_tool/package_config.json"
}

dart_executable("logger_test") {
testonly = true
main_dart = "test/logger_test.dart"
package_config = ".dart_tool/package_config.json"
}

dart_executable("proc_utils_test") {
testonly = true
main_dart = "test/proc_utils_test.dart"
package_config = ".dart_tool/package_config.json"
}

dart_executable("query_command_test") {
testonly = true
main_dart = "test/query_command_test.dart"
package_config = ".dart_tool/package_config.json"
}

dart_executable("run_command_test") {
testonly = true
main_dart = "test/run_command_test.dart"
package_config = ".dart_tool/package_config.json"
}

dart_executable("test_command_test") {
testonly = true
main_dart = "test/test_command_test.dart"
package_config = ".dart_tool/package_config.json"
}

dart_executable("worker_pool_test") {
testonly = true
main_dart = "test/worker_pool_test.dart"
package_config = ".dart_tool/package_config.json"
}