Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Adds a python formatter #33797

Merged
merged 2 commits into from
Jun 3, 2022
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
11 changes: 11 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[style]
based_on_style = yapf
# Defined in https://github.com/google/yapf/blob/20d0c8f1774cf3843f4032f3e9ab02338bf98c75/yapf/yapflib/style.py#L326
# Docs and full list of knobs:
# https://github.com/google/yapf#knobs
split_before_first_argument = true
blank_line_before_module_docstring = true
# dedent_closing_brackets is required by coalesce_brackets
dedent_closing_brackets = true
coalesce_brackets = true
each_dict_entry_on_separate_line = false
3 changes: 3 additions & 0 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ deps = {
'src/third_party/boringssl':
Var('github_git') + '/dart-lang/boringssl_gen.git' + '@' + Var('dart_boringssl_gen_rev'),

'src/third_party/yapf':
Var('github_git') + '/google/yapf' + '@' + '212c5b5ad8e172d2d914ae454c121c89cccbcb35',

'src/third_party/boringssl/src':
'https://boringssl.googlesource.com/boringssl.git' + '@' + Var('dart_boringssl_rev'),

Expand Down
9 changes: 7 additions & 2 deletions build/android_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ def cp_files(args):

def main():
parser = argparse.ArgumentParser()
parser.add_argument('-i', dest='input_pairs', nargs=2, action='append',
help='The input file and its destination.')
parser.add_argument(
'-i',
dest='input_pairs',
nargs=2,
action='append',
help='The input file and its destination.'
)
cp_files(parser.parse_args())
return 0

Expand Down
44 changes: 35 additions & 9 deletions build/copy_info_plist.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,60 @@
import git_revision
import os

def GetClangVersion(bitcode) :
clang_executable = str(os.path.join("..", "..", "buildtools", "mac-x64", "clang", "bin", "clang++"))

def GetClangVersion(bitcode):
clang_executable = str(
os.path.join(
"..", "..", "buildtools", "mac-x64", "clang", "bin", "clang++"
)
)
if bitcode:
clang_executable = "clang++"
version = subprocess.check_output([clang_executable, "--version"])
return version.splitlines()[0]


def main():

parser = argparse.ArgumentParser(
description='Copies the Info.plist and adds extra fields to it like the git hash of the engine')
description='Copies the Info.plist and adds extra fields to it like the git hash of the engine'
)

parser.add_argument('--source', help='Path to Info.plist source template', type=str, required=True)
parser.add_argument('--destination', help='Path to destination Info.plist', type=str, required=True)
parser.add_argument('--bitcode', help='Built with bitcode', action='store_true')
parser.add_argument('--minversion', help='Minimum device OS version like "9.0"', type=str)
parser.add_argument(
'--source',
help='Path to Info.plist source template',
type=str,
required=True
)
parser.add_argument(
'--destination',
help='Path to destination Info.plist',
type=str,
required=True
)
parser.add_argument(
'--bitcode', help='Built with bitcode', action='store_true'
)
parser.add_argument(
'--minversion', help='Minimum device OS version like "9.0"', type=str
)

args = parser.parse_args()

text = open(args.source).read()
engine_path = os.path.join(os.getcwd(), "..", "..", "flutter")
revision = git_revision.GetRepositoryVersion(engine_path)
bitcode = args.bitcode is not None;
bitcode = args.bitcode is not None
clang_version = GetClangVersion(bitcode)
text = text.format(revision = revision, clang_version = clang_version, min_version = args.minversion)
text = text.format(
revision=revision,
clang_version=clang_version,
min_version=args.minversion
)

with open(args.destination, "w") as outfile:
outfile.write(text)


if __name__ == "__main__":
main()
20 changes: 13 additions & 7 deletions build/dart/tools/dart_package_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import os
import sys


# TODO(johnmccutchan): Use the yaml package to parse.
def PackageName(line):
assert line.startswith("name:")
return line.split(":")[1].strip()


def main(pubspec_file):
source_file = open(pubspec_file, "r")
for line in source_file:
Expand All @@ -25,15 +27,19 @@ def main(pubspec_file):
# Couldn't find it.
return -1


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="This script outputs the package name specified in the"
"pubspec.yaml")
parser.add_argument("--pubspec",
dest="pubspec_file",
metavar="<pubspec-file>",
type=str,
required=True,
help="Path to pubspec file")
"pubspec.yaml"
)
parser.add_argument(
"--pubspec",
dest="pubspec_file",
metavar="<pubspec-file>",
type=str,
required=True,
help="Path to pubspec file"
)
args = parser.parse_args()
sys.exit(main(args.pubspec_file))
156 changes: 93 additions & 63 deletions build/dart/tools/dart_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

USE_LINKS = sys.platform != "win32"

DART_ANALYZE = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"dart_analyze.py")
DART_ANALYZE = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "dart_analyze.py"
)


def dart_filter(path):
if os.path.isdir(path):
Expand Down Expand Up @@ -142,7 +144,7 @@ def remove_broken_symlinks(root_dir):


def analyze_entrypoints(dart_sdk, package_root, entrypoints):
cmd = [ "python", DART_ANALYZE ]
cmd = ["python", DART_ANALYZE]
cmd.append("--dart-sdk")
cmd.append(dart_sdk)
cmd.append("--entrypoints")
Expand All @@ -161,60 +163,84 @@ def analyze_entrypoints(dart_sdk, package_root, entrypoints):

def main():
parser = argparse.ArgumentParser(description='Generate a dart-pkg')
parser.add_argument('--dart-sdk',
action='store',
metavar='dart_sdk',
help='Path to the Dart SDK.')
parser.add_argument('--package-name',
action='store',
metavar='package_name',
help='Name of package',
required=True)
parser.add_argument('--pkg-directory',
metavar='pkg_directory',
help='Directory where dart_pkg should go',
required=True)
parser.add_argument('--package-root',
metavar='package_root',
help='packages/ directory',
required=True)
parser.add_argument('--stamp-file',
metavar='stamp_file',
help='timestamp file',
required=True)
parser.add_argument('--entries-file',
metavar='entries_file',
help='script entries file',
required=True)
parser.add_argument('--package-sources',
metavar='package_sources',
help='Package sources',
nargs='+')
parser.add_argument('--package-entrypoints',
metavar='package_entrypoints',
help='Package entry points for analyzer',
nargs='*',
default=[])
parser.add_argument('--sdk-ext-directories',
metavar='sdk_ext_directories',
help='Directory containing .dart sources',
nargs='*',
default=[])
parser.add_argument('--sdk-ext-files',
metavar='sdk_ext_files',
help='List of .dart files that are part of sdk_ext.',
nargs='*',
default=[])
parser.add_argument('--sdk-ext-mappings',
metavar='sdk_ext_mappings',
help='Mappings for SDK extension libraries.',
nargs='*',
default=[])
parser.add_argument('--read_only',
action='store_true',
dest='read_only',
help='Package is a read only package.',
default=False)
parser.add_argument(
'--dart-sdk',
action='store',
metavar='dart_sdk',
help='Path to the Dart SDK.'
)
parser.add_argument(
'--package-name',
action='store',
metavar='package_name',
help='Name of package',
required=True
)
parser.add_argument(
'--pkg-directory',
metavar='pkg_directory',
help='Directory where dart_pkg should go',
required=True
)
parser.add_argument(
'--package-root',
metavar='package_root',
help='packages/ directory',
required=True
)
parser.add_argument(
'--stamp-file',
metavar='stamp_file',
help='timestamp file',
required=True
)
parser.add_argument(
'--entries-file',
metavar='entries_file',
help='script entries file',
required=True
)
parser.add_argument(
'--package-sources',
metavar='package_sources',
help='Package sources',
nargs='+'
)
parser.add_argument(
'--package-entrypoints',
metavar='package_entrypoints',
help='Package entry points for analyzer',
nargs='*',
default=[]
)
parser.add_argument(
'--sdk-ext-directories',
metavar='sdk_ext_directories',
help='Directory containing .dart sources',
nargs='*',
default=[]
)
parser.add_argument(
'--sdk-ext-files',
metavar='sdk_ext_files',
help='List of .dart files that are part of sdk_ext.',
nargs='*',
default=[]
)
parser.add_argument(
'--sdk-ext-mappings',
metavar='sdk_ext_mappings',
help='Mappings for SDK extension libraries.',
nargs='*',
default=[]
)
parser.add_argument(
'--read_only',
action='store_true',
dest='read_only',
help='Package is a read only package.',
default=False
)
args = parser.parse_args()

# We must have a pubspec.yaml.
Expand All @@ -233,14 +259,16 @@ def main():
sdkext_path = os.path.join(lib_path, '_sdkext')
if mappings:
with open(sdkext_path, 'w') as stream:
json.dump(mappings, stream, sort_keys=True,
indent=2, separators=(',', ': '))
json.dump(
mappings, stream, sort_keys=True, indent=2, separators=(',', ': ')
)
else:
remove_if_exists(sdkext_path)

# Copy or symlink package sources into pkg directory.
common_source_prefix = os.path.dirname(os.path.commonprefix(
args.package_sources))
common_source_prefix = os.path.dirname(
os.path.commonprefix(args.package_sources)
)
for source in args.package_sources:
relative_source = os.path.relpath(source, common_source_prefix)
target = os.path.join(target_dir, relative_source)
Expand All @@ -263,8 +291,9 @@ def main():
target = os.path.join(sdk_ext_dir, relative_source)
copy_or_link(source, target)

common_source_prefix = os.path.dirname(os.path.commonprefix(
args.sdk_ext_files))
common_source_prefix = os.path.dirname(
os.path.commonprefix(args.sdk_ext_files)
)
for source in args.sdk_ext_files:
relative_source = os.path.relpath(source, common_source_prefix)
target = os.path.join(sdk_ext_dir, relative_source)
Expand Down Expand Up @@ -293,5 +322,6 @@ def main():

return 0


if __name__ == '__main__':
sys.exit(main())
Loading