// Copyright 2021 Google Inc. All rights reserved. // // 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 // // http://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. package cc import ( "fmt" "path/filepath" "strings" "android/soong/android" "android/soong/bazel" "github.com/google/blueprint/proptools" ) // staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties -- // properties which apply to either the shared or static version of a cc_library module. type staticOrSharedAttributes struct { Srcs bazel.LabelListAttribute Srcs_c bazel.LabelListAttribute Srcs_as bazel.LabelListAttribute Copts bazel.StringListAttribute Static_deps bazel.LabelListAttribute Dynamic_deps bazel.LabelListAttribute Whole_archive_deps bazel.LabelListAttribute System_dynamic_deps bazel.LabelListAttribute } func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelListAttribute) (cppSrcs, cSrcs, asSrcs bazel.LabelListAttribute) { // Branch srcs into three language-specific groups. // C++ is the "catch-all" group, and comprises generated sources because we don't // know the language of these sources until the genrule is executed. // TODO(b/190006308): Handle language detection of sources in a Bazel rule. isCSrcOrFilegroup := func(s string) bool { return strings.HasSuffix(s, ".c") || strings.HasSuffix(s, "_c_srcs") } isAsmSrcOrFilegroup := func(s string) bool { return strings.HasSuffix(s, ".S") || strings.HasSuffix(s, ".s") || strings.HasSuffix(s, "_as_srcs") } // Check that a module is a filegroup type named