Skip to content

Commit

Permalink
third_party: Copybara script for importing fit::function from Fuchsia
Browse files Browse the repository at this point in the history
pw::Function's implementation will be replaced with fit::function from
Fuchsia. fit::function is more advanced than pw::Function and supports
features like dynamic allocation and sharing callables between multiple
fit::function instances.

This copy.bara.sky script will be used to import the fit::function
sources and transform them as needed.

Change-Id: Iab420eb4c9fca13278f4a0cd19d88c17eea4456b
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/103548
Pigweed-Auto-Submit: Wyatt Hepler <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Reviewed-by: Vadim Spivak <[email protected]>
Reviewed-by: Ted Pudlik <[email protected]>
  • Loading branch information
255 authored and CQ Bot Account committed Jul 29, 2022
1 parent cc9adfe commit 1d411dc
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion pw_presubmit/py/pw_presubmit/format_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -347,6 +351,7 @@ def extensions(self):
PYTHON_FORMAT,
GN_FORMAT,
BAZEL_FORMAT,
COPYBARA_FORMAT,
CMAKE_FORMAT,
RST_FORMAT,
MARKDOWN_FORMAT,
Expand Down Expand Up @@ -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."""
Expand Down
21 changes: 21 additions & 0 deletions third_party/fuchsia/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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" ]
}
72 changes: 72 additions & 0 deletions third_party/fuchsia/copy.bara.sky
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"),
transformations = replace_builtin_abort + [
core.move("", "third_party/fuchsia/repo"),
metadata.replace_message("third_party/fuchsia: Copybara import of fit library"),
],
)
55 changes: 55 additions & 0 deletions third_party/fuchsia/docs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.. _module-pw_third_party_fuchsia:

=================
Fuchsia libraries
=================
`Fuchsia <https://fuchsia.dev/>`_ 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 <https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/lib/fit/>`_ --
Portable library of low-level C++ features.
- `stdcompat <https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/lib/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
<https://fuchsia.googlesource.com/fuchsia>`_ and the `Pigweed repository
<https://pigweed.googlesource.com/pigweed/pigweed>`_ using the
`third_party/fuchsia/copy.bara.sky
<https://cs.opensource.google/pigweed/pigweed/+/main:third_party/fuchsia/copy.bara.sky>`_)
`Copybara <https://github.com/google/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.

0 comments on commit 1d411dc

Please sign in to comment.