1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

Fix recursive globbing in tools/format.py

And use third_party/depot_tools/gn.
This commit is contained in:
Ryan Dahl 2018-07-23 12:44:27 -04:00
parent 1de16af1f3
commit 7baf8a0fd1
2 changed files with 27 additions and 12 deletions

View file

@ -1,8 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import os import os
from glob import glob from util import run, find_exts
from util import run
root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
third_party_path = os.path.join(root_path, "third_party") third_party_path = os.path.join(root_path, "third_party")
@ -12,15 +10,19 @@ tools_path = os.path.join(root_path, "tools")
rustfmt_config = os.path.join(tools_path, "rustfmt.toml") rustfmt_config = os.path.join(tools_path, "rustfmt.toml")
os.chdir(root_path) os.chdir(root_path)
# TODO(ry) Install clang-format in third_party.
run(["clang-format", "-i", "-style", "Google"] + glob("src/*.cc") + # TODO(ry) Use third_party/depot_tools/clang-format.
glob("src/*.h")) run(["clang-format", "-i", "-style", "Google"] + find_exts("src", ".cc", ".h"))
for fn in ["BUILD.gn", ".gn"] + glob("build_extra/**/*.gn*"):
run(["gn", "format", fn]) for fn in ["BUILD.gn", ".gn"] + find_exts("build_extra", ".gn", ".gni"):
run(["third_party/depot_tools/gn", "format", fn])
# TODO(ry) Install yapf in third_party. # TODO(ry) Install yapf in third_party.
run(["yapf", "-i"] + glob("tools/*.py") + glob("build_extra/**/*.py")) run(["yapf", "-i"] + find_exts("tools/", ".py") +
run(["node", prettier, "--write"] + glob("js/*.js") + glob("js/*.ts") + find_exts("build_extra", ".py"))
["tsconfig.json"] + ["tslint.json"])
run(["node", prettier, "--write"] + find_exts("js/", ".js", ".ts") +
["tsconfig.json", "tslint.json"])
# Set RUSTFMT_FLAGS for extra flags. # Set RUSTFMT_FLAGS for extra flags.
rustfmt_extra_args = [] rustfmt_extra_args = []
@ -29,4 +31,4 @@ if 'RUSTFMT_FLAGS' in os.environ:
run([ run([
"rustfmt", "--config-path", rustfmt_config, "--error-on-unformatted", "rustfmt", "--config-path", rustfmt_config, "--error-on-unformatted",
"--write-mode", "overwrite" "--write-mode", "overwrite"
] + rustfmt_extra_args + glob("src/*.rs")) ] + rustfmt_extra_args + find_exts("src/", ".rs"))

View file

@ -55,3 +55,16 @@ def touch(fname):
os.utime(fname, None) os.utime(fname, None)
else: else:
open(fname, 'a').close() open(fname, 'a').close()
# Recursive search for files of certain extensions.
# (Recursive glob doesn't exist in python 2.7.)
def find_exts(directory, *extensions):
matches = []
for root, dirnames, filenames in os.walk(directory):
for filename in filenames:
for ext in extensions:
if filename.endswith(ext):
matches.append(os.path.join(root, filename))
break
return matches