未验证 提交 cf7ef6e8 编写于 作者: R Rich Kadel 提交者: GitHub

Adds python3_action GN target (#27211)

Ninja runs `action` scripts using the default python interpretter, and
most flutter build scripts that use python currently require python2. In
order to support python3 scripts as well, the `python3_action` invokes a
wrapper python2-based script via GN `action` target, and the wrapper
invokes the python3 interpretter with the given script.

This new target is required to support flutter/engine#26880, but is
broken out to a separate PR (by request) to support other more immediate
use cases.
上级 6a1bf099
# Copyright 2021 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.
# A ninja action script that calls the given python script with `python3`
# instead of the default `python` (which might be `python2`).
#
# Example
#
# ```
# python3_action("run_this_guy_once") {
# script = "doprocessing.py"
# sources = [ "my_configuration.txt" ]
# outputs = [ "$target_gen_dir/insightful_output.txt" ]
#
# # Our script imports this Python file so we want to rebuild if it
# # changes.
# source_prereqs = [ "helper_library.py" ]
#
# # Note that we have to manually pass the sources to our script if
# # the script needs them as inputs.
# args = [ "--out", to_build_path(target_gen_dir) ] + sources
# }
# ```
#
# Parameters
# args
# data
# datadeps
# depfile
# deps
# inputs
# metadata
# outputs (required)
# script (required)
# source_prereqs
# sources
template("python3_action") {
assert(defined(invoker.outputs), "outputs is required")
assert(defined(invoker.script), "script is required")
action(target_name) {
forward_variables_from(invoker,
[
"data",
"datadeps",
"depfile",
"deps",
"inputs",
"metadata",
"outputs",
"source_prereqs",
"sources",
])
script = "//flutter/tools/python/run_python3_action.py"
args = [ rebase_path(invoker.script) ] + invoker.args
}
}
#!/usr/bin/env python
#
# Copyright 2021 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 os
import sys
os.execv('/usr/bin/python3', ['python3'] + sys.argv[1:])
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册