diff --git a/docs/BUILD.gn b/docs/BUILD.gn index 1fa76299c6..473d05c3c7 100644 --- a/docs/BUILD.gn +++ b/docs/BUILD.gn @@ -78,6 +78,7 @@ group("third_party_docs") { deps = [ "$dir_pigweed/third_party/boringssl:docs", "$dir_pigweed/third_party/freertos:docs", + "$dir_pigweed/third_party/fuchsia:docs", "$dir_pigweed/third_party/googletest:docs", "$dir_pigweed/third_party/nanopb:docs", "$dir_pigweed/third_party/tinyusb:docs", diff --git a/pw_presubmit/py/pw_presubmit/format_code.py b/pw_presubmit/py/pw_presubmit/format_code.py index ebe3c804f4..82ca0036b7 100755 --- a/pw_presubmit/py/pw_presubmit/format_code.py +++ b/pw_presubmit/py/pw_presubmit/format_code.py @@ -320,11 +320,15 @@ def extensions(self): GN_FORMAT: CodeFormat = CodeFormat('GN', FileFilter(endswith=('.gn', '.gni')), check_gn_format, fix_gn_format) -# TODO(pwbug/191): Add real code formatting support for Bazel and CMake BAZEL_FORMAT: CodeFormat = CodeFormat( 'Bazel', FileFilter(endswith=('BUILD', '.bazel', '.bzl')), check_bazel_format, fix_bazel_format) +COPYBARA_FORMAT: CodeFormat = CodeFormat('Copybara', + FileFilter(endswith=('.bara.sky', )), + check_bazel_format, fix_bazel_format) + +# TODO(b/234881054): Add real code formatting support for CMake CMAKE_FORMAT: CodeFormat = CodeFormat( 'CMake', FileFilter(endswith=('CMakeLists.txt', '.cmake')), check_trailing_space, fix_trailing_space) @@ -347,6 +351,7 @@ def extensions(self): PYTHON_FORMAT, GN_FORMAT, BAZEL_FORMAT, + COPYBARA_FORMAT, CMAKE_FORMAT, RST_FORMAT, MARKDOWN_FORMAT, @@ -407,7 +412,12 @@ def __init__(self, for path in self.paths: for code_format in code_formats: if code_format.filter.matches(path): + _LOG.debug('Formatting %s as %s', path, + code_format.language) self._formats[code_format].append(path) + break + else: + _LOG.debug('No formatter found for %s', path) def check(self) -> Dict[Path, str]: """Returns {path: diff} for files with incorrect formatting.""" diff --git a/third_party/fuchsia/BUILD.gn b/third_party/fuchsia/BUILD.gn new file mode 100644 index 0000000000..8f46908072 --- /dev/null +++ b/third_party/fuchsia/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright 2022 The Pigweed Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +import("//build_overrides/pigweed.gni") + +import("$dir_pw_docgen/docs.gni") + +pw_doc_group("docs") { + sources = [ "docs.rst" ] +} diff --git a/third_party/fuchsia/copy.bara.sky b/third_party/fuchsia/copy.bara.sky new file mode 100644 index 0000000000..25ac7c54bb --- /dev/null +++ b/third_party/fuchsia/copy.bara.sky @@ -0,0 +1,72 @@ +# Copyright 2022 The Pigweed Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +fuchsia_repo_files = [ + ".clang-format", + # fit + "sdk/lib/fit/include/lib/fit/function.h", + "sdk/lib/fit/include/lib/fit/function_internal.h", + "sdk/lib/fit/include/lib/fit/nullable.h", + "sdk/lib/fit/include/lib/fit/traits.h", + "sdk/lib/fit/include/lib/fit/utility_internal.h", + # stdcompat + "sdk/lib/stdcompat/include/lib/stdcompat/optional.h", + "sdk/lib/stdcompat/include/lib/stdcompat/type_traits.h", + "sdk/lib/stdcompat/include/lib/stdcompat/utility.h", + "sdk/lib/stdcompat/include/lib/stdcompat/version.h", + "sdk/lib/stdcompat/include/lib/stdcompat/internal/constructors.h", + "sdk/lib/stdcompat/include/lib/stdcompat/internal/exception.h", + "sdk/lib/stdcompat/include/lib/stdcompat/internal/storage.h", + "sdk/lib/stdcompat/include/lib/stdcompat/internal/type_traits.h", + "sdk/lib/stdcompat/include/lib/stdcompat/internal/utility.h", +] + +# Replace __builtin_abort with PW_ASSERT. +replace_builtin_abort_paths = glob([ + "sdk/lib/fit/include/lib/fit/function_internal.h", +]) + +replace_builtin_abort = [ + core.replace( + paths = replace_builtin_abort_paths, + before = "namespace fit {", + after = "#include \"pw_assert/assert.h\"\n\nnamespace fit {", + ), + core.replace( + paths = replace_builtin_abort_paths, + before = "__builtin_abort()", + after = "PW_ASSERT(false)", + ), +] + +core.workflow( + name = "default", + description = "Imports files from Fuchsia's fit library", + origin = git.origin( + url = "https://fuchsia.googlesource.com/fuchsia", + ref = "main", + ), + destination = git.gerrit_destination( + url = "https://pigweed.googlesource.com/pigweed/pigweed", + fetch = "main", + checker = leakr.disable_check("Syncing between OSS projects"), + ), + origin_files = glob(fuchsia_repo_files), + destination_files = glob(["third_party/fuchsia/repo/**"]), + authoring = authoring.pass_thru("Fuchsia Authors "), + transformations = replace_builtin_abort + [ + core.move("", "third_party/fuchsia/repo"), + metadata.replace_message("third_party/fuchsia: Copybara import of fit library"), + ], +) diff --git a/third_party/fuchsia/docs.rst b/third_party/fuchsia/docs.rst new file mode 100644 index 0000000000..390a13bcdc --- /dev/null +++ b/third_party/fuchsia/docs.rst @@ -0,0 +1,55 @@ +.. _module-pw_third_party_fuchsia: + +================= +Fuchsia libraries +================= +`Fuchsia `_ is a modern open source operating system +developed by Google. + +Pigweed does not use the Fuchsia operating system itself, but uses some +low-level libraries developed for it. + +-------- +Features +-------- +Parts of two Fuchsia libraries are used in Pigweed: + +- `FIT `_ -- + Portable library of low-level C++ features. +- `stdcompat `_ -- + Implements newer C++ features for older standards. + +-------------------- +Code synchronization +-------------------- +Unlike other third party libraries used by Pigweed, some Fuchsia source code is +included in tree. A few factors drove this decision: + +- Core Pigweed features like :cpp:type:`pw::Function` depend on these Fuchsia + libraries. Including the source in-tree avoids having Pigweed require an + an external repository. +- The Fuchsia repository is too large to require downstream projects to clone. + +If Fuchsia moves ``stdcompat`` and ``fit`` to separate repositories, the +decision to include Fuchsia code in tree may be reconsidered. + +Process +======= +Code is synchronized between the `Fuchsia repository +`_ and the `Pigweed repository +`_ using the +`third_party/fuchsia/copy.bara.sky +`_) +`Copybara `_ script. + +To synchronize with the Fuchsia repository, run the ``copybara`` tool with the +script: + +.. code-block:: bash + + copybara third_party/fuchsia/copy.bara.sky + +That creates a Gerrit change with updates from the Fuchsia repo, if any. + +Files are synced from Fuchsia repository to their original paths under the +``third_party/fuchsia/repo`` directory in Pigweed.