Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump third_party/pigweed/repo from d6b036c to 7c87569 #27068

Merged
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
4 changes: 0 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,3 @@ jobs:
run: |
git grep -n 'SuccessOrExit([^=)]*(' -- './*' ':(exclude).github/workflows/lint.yml' && exit 1 || exit 0

- name: Check that our hardcoded SHA for clang-format on ARM mac matches the pigweed SHA.
if: always()
run: |
./scripts/lints/clang-format-version-matches.py
43 changes: 0 additions & 43 deletions scripts/lints/clang-format-version-matches.py

This file was deleted.

13 changes: 0 additions & 13 deletions scripts/setup/clang.json

This file was deleted.

1 change: 0 additions & 1 deletion scripts/setup/environment.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"cipd_package_files": [
"third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/cipd_setup/arm.json",
"third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/cipd_setup/pigweed.json",
"scripts/setup/clang.json",
"scripts/setup/python.json",
"scripts/setup/zap.json"
],
Expand Down
87 changes: 65 additions & 22 deletions scripts/tools/zap/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import subprocess
import sys
import tempfile
import traceback
import urllib.request
from dataclasses import dataclass
from pathlib import Path
Expand Down Expand Up @@ -216,6 +217,59 @@ def runGeneration(cmdLineArgs):
extractGeneratedIdl(output_dir, zap_file)


def getClangFormatBinaryChoices():
"""
Returns an ordered list of paths that may be suitable clang-format versions
"""
PW_CLANG_FORMAT_PATH = 'cipd/packages/pigweed/bin/clang-format'

if 'PW_ENVIRONMENT_ROOT' in os.environ:
yield os.path.join(os.environ["PW_ENVIRONMENT_ROOT"], PW_CLANG_FORMAT_PATH)

dot_name = os.path.join(CHIP_ROOT_DIR, '.environment', PW_CLANG_FORMAT_PATH)
if os.path.exists(dot_name):
yield dot_name

os_name = shutil.which('clang-format')
if os_name:
yield os_name


def getClangFormatBinary():
"""Fetches the clang-format binary that is to be used for formatting.

Tries to figure out where the pigweed-provided binary is (via cipd)
"""
for binary in getClangFormatBinaryChoices():
# Running the binary with `--version` yields a string of the form:
# "Fuchsia clang-format version 17.0.0 (https://llvm.googlesource.com/llvm-project 6d667d4b261e81f325756fdfd5bb43b3b3d2451d)"
#
# the SHA at the end generally should match pigweed version

try:
version_string = subprocess.check_output([binary, '--version']).decode('utf8')

pigweed_config = json.load(
open(os.path.join(CHIP_ROOT_DIR, 'third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/cipd_setup/pigweed.json')))
clang_config = [p for p in pigweed_config['packages'] if p['path'].startswith('fuchsia/third_party/clang/')][0]

# Tags should be like:
# ['git_revision:895b55537870cdaf6e4c304a09f4bf01954ccbd6']
prefix, sha = clang_config['tags'][0].split(':')

if sha not in version_string:
print('WARNING: clang-format may not be the right version:')
print(' PIGWEED TAG: %s' % clang_config['tags'][0])
print(' ACTUAL VERSION: %s' % version_string)
except:
print("Failed to validate clang version.")
traceback.print_last()

return binary

raise Exception('Could not find a suitable clang-format')


def runClangPrettifier(templates_file, output_dir):
listOfSupportedFileExtensions = [
'.js', '.h', '.c', '.hpp', '.cpp', '.m', '.mm']
Expand All @@ -228,28 +282,17 @@ def runClangPrettifier(templates_file, output_dir):
filepath)[1] in listOfSupportedFileExtensions, outputs))

if len(clangOutputs) > 0:
# NOTE: clang-format may differ in time. Currently pigweed comes
# with clang-format 15. CI may have clang-format-10 installed
# on linux.
#
# We generally want consistent formatting, so
# at this point attempt to use clang-format 15.
clang_formats = ['clang-format-15', 'clang-format']
for clang_format in clang_formats:
args = [clang_format, '-i']
args.extend(clangOutputs)
try:
subprocess.check_call(args)
err = None
print('Formatted using %s (%s)' % (clang_format, subprocess.check_output([clang_format, '--version'])))
for outputName in clangOutputs:
print(' - %s' % outputName)
break
except Exception as thrown:
err = thrown
# Press on to the next binary name
if err is not None:
raise err
# NOTE: clang-format differs output in time. We generally would be
# compatible only with pigweed provided clang-format (which is
# tracking non-released clang).
clang_format = getClangFormatBinary()
args = [clang_format, '-i']
args.extend(clangOutputs)
subprocess.check_call(args)
err = None
print('Formatted using %s (%s)' % (clang_format, subprocess.check_output([clang_format, '--version'])))
for outputName in clangOutputs:
print(' - %s' % outputName)
except Exception as err:
print('clang-format error:', err)

Expand Down
Loading