blob: 6c6bc959f3ac9cf29656ca12a6d5cf163aacce1f [file] [log] [blame]
"""Copybara config to export files from google3 to gRPC repo in gBMC
Validate the config in terms of syntax:
copybara validate third_party/gbmcweb/copy.bara.sky
Test the transformation (add --init-history --squash for the first run)
1. Run the workflow in dry-run mode
alias copybara='/google/bin/releases/copybara/public/copybara/copybara'
copybara third_party/gbmcweb/copy.bara.sky gbmcweb_presubmit_piper_to_gerrit 12345 --dry-run --ignore-noop
2. Format patch (get the GIT_DIR from the copybara output)
GIT_DIR=/usr/local/google/home/$USER/copybara/cache/git_repos/rpc%3A%2F%2Fgbmc%2Fgbmcweb git format-patch -1 \
&& cp 0001-DO-NOT-SUBMIT.patch /path/to/gbmcweb
3. Apply the patch and test there.
"""
load("//devtools/copybara/library/feedback", "critique_findings_to_gerrit")
load("//devtools/copybara/library/scrubbing", "cc_scrub", "doc_scrub", "message_scrub_google_block", "proto_scrub")
load("//devtools/copybara/library/workflow", "piper_sot_to_gerrit")
###################################################################################
# Do not modify this file from GoB. This file should only be modified in google3. #
###################################################################################
########################
# Private definitions
########################
# all c++ source files under current directory recrusively in google3
_g3_cc_files = ["**.h", "**.cc"]
# all c++ source files under current directory recrusively in GoB
_gob_cc_files = ["**.h", "**.cpp", "**.hpp", "**.cc"]
# Common files like OWNERS, METADATA, etc are excluded
_excluded_meta_files = [
"google3/third_party/gbmcweb/BUILD",
"google3/third_party/gbmcweb/bluze.textproto",
"google3/third_party/gbmcweb/METADATA",
"google3/third_party/gbmcweb/third_party.gbmcweb.blueprint",
"google3/third_party/gbmcweb/OWNERS",
"google3/third_party/gbmcweb/demo/**",
"google3/third_party/gbmcweb/**/BUILD",
]
_all_gbmcweb_google3_files = [
# go/keep-sorted start
"google3/third_party/gbmcweb/LICENSE",
"google3/third_party/gbmcweb/config/bmcweb_config.h.in",
"google3/third_party/gbmcweb/config/meson.build",
"google3/third_party/gbmcweb/config/meson_options.txt",
"google3/third_party/gbmcweb/http/common.h",
#"google3/third_party/gbmcweb/**",
"google3/third_party/gbmcweb/http/logging.h",
"google3/third_party/gbmcweb/http/utility.cc",
"google3/third_party/gbmcweb/http/utility.h",
"google3/third_party/gbmcweb/http/utility_test.cc",
"google3/third_party/gbmcweb/http/verb.h",
"google3/third_party/gbmcweb/http/verb_test.cc",
"google3/third_party/gbmcweb/redfish_core/include/utils/hex_utils.h",
"google3/third_party/gbmcweb/redfish_core/include/utils/hex_utils_test.cc",
# go/keep-sorted end
]
_git_files = [
# go/keep-sorted start
"LICENSE",
"config/bmcweb_config.h.in",
"config/meson.build",
"http/common.hpp",
"http/logging.hpp",
"http/utility.cpp",
"http/utility.hpp",
"http/verb.hpp",
"meson_options.txt",
"redfish-core/include/utils/hex_utils.hpp",
"test/http/utility_test.cpp",
"test/http/verb_test.cpp",
"test/redfish-core/include/utils/hex_utils_test.cpp",
# go/keep-sorted end
]
# copy.bara.sky is g3 origin file only for piper to gob workflow
# copy.bara.sky is excluded from g3 destination file in reverse workflow to avoid any edit from gob
_google3_files_for_origin = glob(
include = [
"google3/third_party/gbmcweb/copy.bara.sky",
] + _all_gbmcweb_google3_files,
exclude = _excluded_meta_files,
)
_google3_files_for_destination = glob(
include = _all_gbmcweb_google3_files,
exclude = _excluded_meta_files,
)
# copy.bara.sky is gob destination file only for piper to gob workflow
# copy.bara.sky is excluded from gob origin file in reverse workflow to avoid any edit from gob
_git_files_for_destination = glob(
include = [
"copy.bara.sky",
] + _git_files,
exclude = [".gitignore"],
)
_git_files_for_origin = glob(
include = _git_files,
exclude = [".gitignore"],
)
_allowed_authors = {
"haoooamazing": "Hao Zhou <haoooamazing@google.com>",
"nanzhou": "Nan Zhou <nanzhou@google.com>",
}
########################
# Transformations
########################
_transformations = [
###############################
# common scrubs
###############################
cc_scrub(),
proto_scrub(),
doc_scrub(),
###############################
# common headers
###############################
core.replace(
# tranformation for all boost header
before = "third_party/boost/do_not_include_from_google3_only_third_party/boost/boost",
after = "boost",
paths = glob(_g3_cc_files),
),
core.replace(
before = "third_party/gbmcweb/http/verb.h",
after = "verb.hpp",
paths = glob(_g3_cc_files),
),
core.replace(
before = "#include \"third_party/json/include/nlohmann/json.hpp\"",
after = "#include <nlohmann/json.hpp>",
paths = glob(_g3_cc_files),
),
core.replace(
before = "third_party/gbmcweb/http/utility.h",
after = "utility.hpp",
paths = glob(_g3_cc_files),
),
core.replace(
# CRYPTO_memcmp
before = "<openssl/mem.h>",
after = "<openssl/crypto.h>",
paths = glob(_g3_cc_files),
),
core.replace(
before = "third_party/gbmcweb/config/bmcweb_config.h",
after = "bmcweb_config.h",
paths = glob(_g3_cc_files),
),
core.replace(
before = "third_party/gbmcweb/redfish_core/include/utils/hex_utils.h",
after = "utils/hex_utils.hpp",
paths = glob(_g3_cc_files),
),
core.replace(
before = "#include \"testing/base/public/gunit.h\"",
after = "#include <gtest/gtest.h>",
paths = glob(_g3_cc_files),
),
core.replace(
before = "#include \"testing/base/public/gmock.h\"",
after = "#include <gmock/gmock.h>",
paths = glob(_g3_cc_files),
),
###############################
# move
###############################
# Operations are in sequence.
core.move(
before = "google3/third_party/gbmcweb/http/verb.h",
after = "http/verb.hpp",
),
core.move(
before = "google3/third_party/gbmcweb/http/verb_test.cc",
after = "test/http/verb_test.cpp",
),
core.move(
before = "google3/third_party/gbmcweb/http/logging.h",
after = "http/logging.hpp",
),
core.move(
before = "google3/third_party/gbmcweb/http/utility.cc",
after = "http/utility.cpp",
),
core.move(
before = "google3/third_party/gbmcweb/http/utility.h",
after = "http/utility.hpp",
),
core.move(
before = "google3/third_party/gbmcweb/http/utility_test.cc",
after = "test/http/utility_test.cpp",
),
core.move(
before = "google3/third_party/gbmcweb/http/common.h",
after = "http/common.hpp",
),
core.move(
before = "google3/third_party/gbmcweb/config/bmcweb_config.h.in",
after = "config/bmcweb_config.h.in",
),
core.move(
before = "google3/third_party/gbmcweb/config/meson.build",
after = "config/meson.build",
),
core.move(
before = "google3/third_party/gbmcweb/config/meson_options.txt",
after = "meson_options.txt",
),
core.move(
before = "google3/third_party/gbmcweb/redfish_core/include/utils/hex_utils.h",
after = "redfish-core/include/utils/hex_utils.hpp",
),
core.move(
before = "google3/third_party/gbmcweb/redfish_core/include/utils/hex_utils_test.cc",
after = "test/redfish-core/include/utils/hex_utils_test.cpp",
),
core.move(
before = "google3/third_party/gbmcweb/copy.bara.sky",
after = "copy.bara.sky",
),
core.move(
before = "google3/third_party/gbmcweb/LICENSE",
after = "LICENSE",
),
########################
# Check for leaks after last transform
########################
leakr.check(),
]
_reverse_transformations = [
###############################
# common headers
###############################
# Operations are in sequence.
core.replace(
before = "#include \"boost",
after = "#include \"third_party/boost/do_not_include_from_google3_only_third_party/boost/boost",
paths = glob(_gob_cc_files),
),
core.replace(
before = "#include \"verb.hpp\"",
after = "#include \"third_party/gbmcweb/http/verb.h\"",
paths = glob(_gob_cc_files),
),
core.replace(
before = "#include <nlohmann/json.hpp>",
after = "#include \"third_party/json/include/nlohmann/json.hpp\"",
paths = glob(_gob_cc_files),
),
core.replace(
before = "utility.hpp",
after = "third_party/gbmcweb/http/utility.h",
paths = glob(_gob_cc_files),
),
core.replace(
# CRYPTO_memcmp
before = "<openssl/crypto.h>",
after = "<openssl/mem.h>",
paths = glob(_gob_cc_files),
),
core.replace(
before = "bmcweb_config.h",
after = "third_party/gbmcweb/config/bmcweb_config.h",
paths = glob(_gob_cc_files),
),
core.replace(
before = "utils/hex_utils.hpp",
after = "third_party/gbmcweb/redfish_core/include/utils/hex_utils.h",
paths = glob(_gob_cc_files),
),
core.replace(
before = "#include <gtest/gtest.h>",
after = "#include \"testing/base/public/gunit.h\"",
paths = glob(_gob_cc_files),
),
core.replace(
before = "#include <gmock/gmock.h>",
after = "#include \"testing/base/public/gmock.h\"",
paths = glob(_gob_cc_files),
),
###############################
# move
###############################
# Operations are in sequence.
core.move(
before = "http/verb.hpp",
after = "google3/third_party/gbmcweb/http/verb.h",
),
core.move(
before = "test/http/verb_test.cpp",
after = "google3/third_party/gbmcweb/http/verb_test.cc",
),
core.move(
before = "http/logging.hpp",
after = "google3/third_party/gbmcweb/http/logging.h",
),
core.move(
before = "http/utility.cpp",
after = "google3/third_party/gbmcweb/http/utility.cc",
),
core.move(
before = "http/utility.hpp",
after = "google3/third_party/gbmcweb/http/utility.h",
),
core.move(
before = "test/http/utility_test.cpp",
after = "google3/third_party/gbmcweb/http/utility_test.cc",
),
core.move(
before = "http/common.hpp",
after = "google3/third_party/gbmcweb/http/common.h",
),
core.move(
before = "config/bmcweb_config.h.in",
after = "google3/third_party/gbmcweb/config/bmcweb_config.h.in",
),
core.move(
before = "config/meson.build",
after = "google3/third_party/gbmcweb/config/meson.build",
),
core.move(
before = "meson_options.txt",
after = "google3/third_party/gbmcweb/config/meson_options.txt",
),
core.move(
before = "redfish-core/include/utils/hex_utils.hpp",
after = "google3/third_party/gbmcweb/redfish_core/include/utils/hex_utils.h",
),
core.move(
before = "test/redfish-core/include/utils/hex_utils_test.cpp",
after = "google3/third_party/gbmcweb/redfish_core/include/utils/hex_utils_test.cc",
),
core.move(
before = "LICENSE",
after = "google3/third_party/gbmcweb/LICENSE",
),
########################
# Check for leaks after last transform
########################
leakr.check(),
]
########################
# Workflows
########################
piper_sot_to_gerrit(
name_prefix = "gbmcweb",
google3_files = _google3_files_for_origin,
default_author = "gBMC Team <gbmc-core@google.com>",
allowed_authors = _allowed_authors,
contact_email = "gbmc-core+copybara@google.com",
url = "rpc://gbmc/gbmcweb",
branch = "master",
transformations = _transformations,
owner_mdb = "gbmc-git-approvers",
ci_labels = ["Presubmit"],
common_flags = {
# "--ignore-noop": [],
"--read-config-from-change": [],
},
git_files = _git_files_for_destination,
metadata_scrubber = message_scrub_google_block(),
)
# Workflow for moving changes from gerrit to google3
core.workflow(
name = "gbmcweb_gob_to_piper_reverse_workflow",
origin = git.gerrit_origin(
url = "rpc://gbmc/gbmcweb",
branch = "master",
import_wip_changes = False,
),
origin_files = _git_files_for_origin,
destination = piper.destination(
mode = "AUTO_SUBMIT",
reviewers = [
"haoooamazing@google.com",
"nanzhou@google.com",
],
cc = [
"haoooamazing@google.com",
],
),
destination_files = _google3_files_for_destination,
mode = "CHANGE_REQUEST",
# cannot pass through since vendor will not have access to google3
authoring = authoring.allowed(
default = "gBMC Team <gbmc-core@google.com>",
allowlist = [
"haoooamazing",
],
),
transformations = _reverse_transformations,
)
# automate reverse workflow
service.migration(
migration_name = "gbmcweb_gob_to_piper_reverse_workflow",
owner_mdb = "gbmc-git-approvers",
contact_email = "gbmc-core+copybara@google.com",
cns_mdb = "copybara-freebie",
notifications = service.notifications(
on_error = [service.email(address = "gbmc-core+copybara@google.com")],
),
state = "ACTIVE",
)
# feedback from critique to gerrit
critique_findings_to_gerrit(
name = "gbmcweb_piper_sot_findings_to_gerrit",
description = "Post presubmit TAP findings from Critique to the original Gerrit review",
categories = ["Presubmit:Tests:CheckGbmcwebTap"],
gob_url = "rpc://gbmc/gbmcweb",
label = "Google-Verified",
checker = leakr.check(),
piper_files = _google3_files_for_destination,
)
# automate feedback (critique -> gerrit) for reverse workflow (gob->piper)
service.migration(
migration_name = "gbmcweb_piper_sot_findings_to_gerrit",
owner_mdb = "gbmc-git-approvers",
contact_email = "gbmc-core+copybara@google.com",
cns_mdb = "copybara-freebie",
notifications = service.notifications(
on_error = [service.email(address = "gbmc-core+copybara@google.com")],
),
state = "ACTIVE",
)