| """Copybara config to export file from google3 / safepower_agent to gPowerD |
| |
| Validate the config in terms of syntax: |
| copybara validate copy.bara.sky |
| |
| 1. Run the workflow in dry-run mode |
| alias copybara='/google/bin/releases/copybara/public/copybara/copybara' |
| gPowerD: copybara copy.bara.sky gpowerd_presubmit_piper_to_gerrit 12345 --dry-run --ignore-noop |
| 2. Format patch (get the GIT_DIR from the copybara output) |
| b) gPowerD: GIT_DIR=/usr/local/google/home/$USER/copybara/cache/git_repos/rpc%3A%2F%2Fgbmc%2FgPowerD git format-patch -1 \ |
| && cp 0001-DO-NOT-SUBMIT.patch /path/to/gPowerD |
| 3. Apply the patch and test there. |
| |
| """ |
| |
| load("//devtools/copybara/library/scrubbing", "cc_scrub", "message_scrub_google_block", "proto_scrub") |
| load("//devtools/copybara/library/workflow", "get_service_config", "piper_sot_to_gerrit") |
| |
| ####################### |
| # Private definitions |
| ######################## |
| _cc_files = ["**.h", "**.cc", "**.in"] |
| _proto_files = ["**.proto", "**.textproto"] |
| _meson_files = ["**.build", "**meson_options.txt"] |
| _copybara_config = [ |
| "copy.bara.sky", |
| ] |
| |
| _proto_files.append("google3/production/borg_mgmt/node_proxy/safepower/utils.proto") |
| |
| _gpowerd_codebase_lib = [ |
| # go/keep-sorted start |
| "action_context.cc", |
| "action_context.h", |
| "action_hash.h", |
| "action_validation.cc", |
| "action_validation.h", |
| "bmc/address_lookup.cc", |
| "bmc/address_lookup.h", |
| "bmc/address_resolver.cc", |
| "bmc/address_resolver.h", |
| "bmc/auth.cc", |
| "bmc/auth.h", |
| "bmc/auth_file_helper.cc", |
| "bmc/auth_file_helper.h", |
| "bmc/auth_file_helper_test.cc", |
| "bmc/auth_loas3.h", |
| "bmc/auth_test.cc", |
| "bmc/convert_status.h", |
| "bmc/daemon_context_bmc.cc", |
| "bmc/daemon_context_bmc.h", |
| "bmc/daemon_context_bmc_test.cc", |
| "bmc/event_queue_thread.cc", |
| "bmc/event_queue_thread_test.cc", |
| "bmc/gmi_reader.cc", |
| "bmc/gmi_reader.h", |
| "bmc/gmi_reader_test.cc", |
| "bmc/gnic_monitor.cc", |
| "bmc/gnic_monitor.h", |
| "bmc/gpowerd.cc", |
| "bmc/health_state_ping.cc", |
| "bmc/health_state_ping.h", |
| "bmc/http_connection.cc", |
| "bmc/http_connection.h", |
| "bmc/http_connection_test.cc", |
| "bmc/machine_configs/embedded_data.h", |
| "bmc/machine_configs/example.textproto", |
| "bmc/machine_configs/meson.build", |
| "bmc/machine_configs/setup_configs.cc", |
| "bmc/machine_configs/setup_configs.h", |
| "bmc/machine_configs/setup_configs_test.cc", |
| "bmc/meson.build", |
| "bmc/mock_address_resolver.h", |
| "bmc/mock_server.h", |
| "bmc/redfish.cc", |
| "bmc/redfish.h", |
| "bmc/redfish_test.cc", |
| "bmc/register_actions_bmc.cc", |
| "bmc/register_actions_bmc.h", |
| "bmc/register_actions_bmc_test.cc", |
| "bmc/remote_state_monitor.cc", |
| "bmc/remote_state_monitor.h", |
| "bmc/remote_state_ping.cc", |
| "bmc/remote_state_ping.h", |
| "bmc/scheduler_bmc.cc", |
| "bmc/scheduler_bmc.h", |
| "bmc/scheduler_bmc_test.cc", |
| "bmc/state_monitor_bmc.cc", |
| "bmc/state_monitor_bmc.h", |
| "bmc/status_macros.h", |
| "bmc/test_util.h", |
| "callback_manager.cc", |
| "callback_manager.h", |
| "condition.cc", |
| "condition.h", |
| "convert_proto.cc", |
| "convert_proto.h", |
| "daemon_context.cc", |
| "daemon_context.h", |
| "disruption_manager.cc", |
| "disruption_manager.h", |
| "event.h", |
| "event_queue.h", |
| "flight_record.cc", |
| "flight_record.h", |
| "gpowerd_build_config.h.in", |
| "internal_boot_counter.cc", |
| "internal_boot_counter.h", |
| "internal_boot_counter_test.cc", |
| "log_throttler.h", |
| "meson.build", |
| "meson_options.txt", |
| "parse_text_proto.cc", |
| "parse_text_proto.h", |
| "persistent_storage.h", |
| "persistent_storage_impl.cc", |
| "persistent_storage_impl.h", |
| "persistent_storage_impl_test.cc", |
| "polling_scheduler.cc", |
| "polling_scheduler.h", |
| "polling_state.h", |
| "polling_state_monitor.cc", |
| "polling_state_monitor.h", |
| "proto/action.proto", |
| "proto/meson.build", |
| "proto/safepower_agent.proto", |
| "proto/safepower_agent_config.proto", |
| "proto/state_persistence.proto", |
| "proto/system_state.proto", |
| "proto_reader.cc", |
| "proto_reader.h", |
| "proto_reader_test.cc", |
| "safepower_agent.cc", |
| "safepower_agent.h", |
| "scheduler_interface.h", |
| "service_impl.cc", |
| "service_impl.h", |
| "state_change_reactor.h", |
| "state_fields.h", |
| "state_merge.cc", |
| "state_merge.h", |
| "state_updater.h", |
| "static_state.cc", |
| "static_state.h", |
| "google3/production/borg_mgmt/node_proxy/safepower/utils.proto", |
| # go/keep-sorted end |
| ] |
| |
| _all_gpowerd_google3_files = glob( |
| include = |
| _gpowerd_codebase_lib + _copybara_config, |
| ) |
| |
| _all_gob_files = glob( |
| include = ["**"], |
| ) |
| |
| allowed_authors = { |
| "jebr": "John Broadbent <jebr@google.com>", |
| "shounak": "Shounak Mitra <shounak@google.com>", |
| "arunsa": "Arun Satyanarayana <arunsa@google.com>", |
| "jainrish": "Rishabh Jain <jainrish@google.com>", |
| "sruthiganti": "Sruthi Ganti <sruthiganti@google.com>", |
| "dcbourgeois": "Daniel Bourgeois <dcbourgeois@google.com>", |
| } |
| |
| def _write_piper_cl_impl(ctx): |
| cl = ctx.find_label("COPYBARA_CURRENT_REV") |
| if not cl: |
| ctx.console.warn("COPYBARA_CURRENT_REV is missing. Defaulting to '0'.") |
| cl = "0" |
| elif not cl.isdigit(): |
| ctx.console.warn("Piper origin CL is not a digit: '" + cl + "'. Defaulting to '0'.") |
| cl = "0" |
| path = ctx.new_path("piper_cl.txt") |
| ctx.write_path(path, cl + "\n") |
| |
| write_piper_cl = core.transform( |
| [core.dynamic_transform(impl = _write_piper_cl_impl)], |
| reversal = [core.remove(paths = glob(["piper_cl.txt"]))], |
| ignore_noop = True, |
| ) |
| |
| _transformations = [ |
| ############################### |
| # common scrubs |
| ############################### |
| cc_scrub(), |
| proto_scrub(), |
| leakr.check(), |
| write_piper_cl, |
| ############################### |
| # common headers |
| ############################### |
| core.replace( |
| before = "third_party/absl", |
| after = "absl", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "third_party/grpc/google_specific/include/", |
| after = "", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "third_party/grpc/include/", |
| after = "", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "third_party/protobuf/", |
| after = "google/protobuf/", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "third_party/json/include/nlohmann", |
| after = "nlohmann", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "", |
| after = "", |
| ), |
| core.replace( |
| before = "platforms/gbmc/hal/", |
| after = "", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "${proto_file}.proto.h", |
| after = "${proto_file}.pb.h", |
| regex_groups = { |
| "proto_file": "\\w+", |
| }, |
| ), |
| core.replace( |
| before = "google/protobuf/${proto_file}.proto.h", |
| after = "google/protobuf/${proto_file}.pb.h", |
| regex_groups = { |
| "proto_file": "\\w+", |
| }, |
| ), |
| core.replace( |
| before = "gmi/machine_identity.pb.h", |
| after = "gmi/machine_identity.pb.h", |
| ), |
| core.replace( |
| before = "", |
| after = "", |
| ), |
| core.replace( |
| before = "utils.pb.h", |
| after = "utils.pb.h", |
| ), |
| core.replace( |
| before = "", |
| after = "", |
| ), |
| core.replace( |
| before = "", |
| after = "", |
| ), |
| core.replace( |
| before = "bmc/convert_status.h", |
| after = "bmc/convert_status.h", |
| ), |
| core.replace( |
| before = "bmc/status_macros.h", |
| after = "bmc/status_macros.h", |
| ), |
| core.replace( |
| before = "bmc/status_macros.h", |
| after = "bmc/status_macros.h", |
| ), |
| core.replace( |
| before = "third_party/milotic/internal/cc/authn/generate_self_signed_cert.h", |
| after = "zatar/generate_self_signed_cert.h", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "platforms/uhm/node_entities/proto/${proto_file}.proto.h", |
| after = "one/${proto_file}.pb.h", |
| paths = glob(_cc_files), |
| regex_groups = { |
| "proto_file": "\\w+", |
| }, |
| ), |
| core.replace( |
| before = "production/msv/node_entities/public/offline_node_entities.h", |
| after = "one/public_offline_node_entities.h", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "net/model/unm/proto/${proto_file}.proto.h", |
| after = "one/${proto_file}.pb.h", |
| paths = glob(_cc_files), |
| regex_groups = { |
| "proto_file": "\\w+", |
| }, |
| ), |
| core.replace( |
| before = "platforms/uhm/node_entities/proto/${proto_file}.proto.h", |
| after = "one/${proto_file}.pb.h", |
| paths = glob(_cc_files), |
| regex_groups = { |
| "proto_file": "\\w+", |
| }, |
| ), |
| core.replace( |
| before = "proto2::", |
| after = "google::protobuf::", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "testing/base/public/gunit.h", |
| after = "gtest/gtest.h", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "testing/base/public/gmock.h", |
| after = "gmock/gmock.h", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "absl/types/source_location.h", |
| after = "source_location", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "absl::SourceLocation", |
| after = "std::source_location", |
| paths = glob(_cc_files), |
| ), |
| core.replace( |
| before = "production/borg_mgmt/node_proxy/safepower/utils.proto", |
| after = "utils.proto", |
| paths = glob(_proto_files), |
| ), |
| ############################### |
| # move |
| ############################### |
| core.move( |
| before = "", |
| after = "", |
| paths = glob(_cc_files), |
| ), |
| core.move( |
| before = "", |
| after = "", |
| paths = glob(_proto_files), |
| ), |
| core.move( |
| before = "", |
| after = "", |
| paths = glob(_meson_files), |
| ), |
| core.move( |
| before = "subprojects/", |
| after = "subprojects/", |
| ), |
| # Move the copy.bara.sky file to the root of the repo so that changes to it are copied to the |
| |
| # destination and trigger CI. |
| core.move( |
| before = "copy.bara.sky", |
| after = "copy.bara.sky", |
| ), |
| core.move( |
| before = "google3/production/borg_mgmt/node_proxy/safepower/", |
| after = "proto/", |
| paths = glob(_proto_files), |
| ), |
| # , , and are not yet present in the |
| # version of absl gBMC is using. Not all annotations may be present in our code yet, so ignore |
| # noop changes for these replacements. |
| # TODO: b/381875619 - Remove these when absl is bumped to 48f0f91 or newer. |
| core.transform([ |
| core.replace( |
| before = "", |
| after = "", |
| ), |
| core.replace( |
| before = "", |
| after = "", |
| ), |
| core.replace( |
| before = "", |
| after = "", |
| ), |
| ], ignore_noop = True), |
| ] |
| |
| piper_sot_to_gerrit( |
| name_prefix = "gpowerd", |
| google3_files = _all_gpowerd_google3_files, |
| git_files = _all_gob_files, |
| default_author = "gBMC Team <gbmc-core@google.com>", |
| allowed_authors = allowed_authors, |
| url = "rpc://gbmc/gPowerD", |
| transformations = _transformations, |
| ci_labels = ["Presubmit"], |
| metadata_scrubber = core.transform([ |
| metadata.scrubber( |
| regex = r"(?m)^WANT_LGTM=.*\n?", |
| replacement = "", |
| ), |
| metadata.scrubber( |
| regex = r"(?m)^READABILITY_MENTOR_ASSIGNEE=.*\n?", |
| replacement = "", |
| ), |
| message_scrub_google_block(), |
| ]), |
| multiple_gerrit_workflows = True, |
| branch = "master", |
| service_config = get_service_config( |
| owner_prod_group = "safepower-dev-team", |
| contact_email = "safepower-dev+copybara@google.com", |
| common_flags = { |
| "--ignore-noop": [], |
| }, |
| ), |
| ) |
| |
| # This is just for testing. |
| # Run this workflow to verify `_transformations` locally from a google3 directory: |
| # copybara copy.bara.sky test_local .. \ |
| # --folder-dir /tmp/copybara_out_full --force --ignore-noop |
| # The output will be in `/tmp/copybara_out_full`. |
| core.workflow( |
| name = "test_local", |
| origin = folder.origin(), |
| origin_files = _all_gpowerd_google3_files, |
| destination = folder.destination(), |
| authoring = authoring.pass_thru("Nobody <nobody@google.com>"), |
| transformations = _transformations, |
| ) |