blob: 40374bff7c15528d60913e8ac89ae67e019787ca [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18 "fmt"
Logan Chien031d2b32018-07-26 00:19:50 +080019 "path/filepath"
Colin Cross3f40fa42015-01-30 17:27:36 -080020 "regexp"
21 "strings"
Colin Crossc0b06f12015-04-08 13:03:43 -070022
Colin Cross635c3b02016-05-18 15:37:25 -070023 "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -080024)
25
26// Efficiently converts a list of include directories to a single string
27// of cflags with -I prepended to each directory.
Colin Cross635c3b02016-05-18 15:37:25 -070028func includeDirsToFlags(dirs android.Paths) string {
29 return android.JoinWithPrefix(dirs.Strings(), "-I")
Colin Cross3f40fa42015-01-30 17:27:36 -080030}
31
32func ldDirsToFlags(dirs []string) string {
Colin Cross635c3b02016-05-18 15:37:25 -070033 return android.JoinWithPrefix(dirs, "-L")
Colin Cross3f40fa42015-01-30 17:27:36 -080034}
35
36func libNamesToFlags(names []string) string {
Colin Cross635c3b02016-05-18 15:37:25 -070037 return android.JoinWithPrefix(names, "-l")
Colin Cross3f40fa42015-01-30 17:27:36 -080038}
39
Colin Crossb4330e22017-12-22 15:47:09 -080040var indexList = android.IndexList
41var inList = android.InList
42var filterList = android.FilterList
43var removeListFromList = android.RemoveListFromList
44var removeFromList = android.RemoveFromList
Colin Cross16b23492016-01-06 14:41:07 -080045
Colin Cross3f40fa42015-01-30 17:27:36 -080046var libNameRegexp = regexp.MustCompile(`^lib(.*)$`)
47
48func moduleToLibName(module string) (string, error) {
49 matches := libNameRegexp.FindStringSubmatch(module)
50 if matches == nil {
51 return "", fmt.Errorf("Library module name %s does not start with lib", module)
52 }
53 return matches[1], nil
54}
55
Colin Crossca860ac2016-01-04 14:34:37 -080056func flagsToBuilderFlags(in Flags) builderFlags {
Colin Cross3f40fa42015-01-30 17:27:36 -080057 return builderFlags{
Colin Cross6d88dba2019-11-06 07:06:58 -080058 globalCommonFlags: strings.Join(in.Global.CommonFlags, " "),
59 globalAsFlags: strings.Join(in.Global.AsFlags, " "),
60 globalYasmFlags: strings.Join(in.Global.YasmFlags, " "),
61 globalCFlags: strings.Join(in.Global.CFlags, " "),
62 globalToolingCFlags: strings.Join(in.Global.ToolingCFlags, " "),
63 globalToolingCppFlags: strings.Join(in.Global.ToolingCppFlags, " "),
64 globalConlyFlags: strings.Join(in.Global.ConlyFlags, " "),
65 globalCppFlags: strings.Join(in.Global.CppFlags, " "),
66 globalLdFlags: strings.Join(in.Global.LdFlags, " "),
67
68 localCommonFlags: strings.Join(in.Local.CommonFlags, " "),
69 localAsFlags: strings.Join(in.Local.AsFlags, " "),
70 localYasmFlags: strings.Join(in.Local.YasmFlags, " "),
71 localCFlags: strings.Join(in.Local.CFlags, " "),
72 localToolingCFlags: strings.Join(in.Local.ToolingCFlags, " "),
73 localToolingCppFlags: strings.Join(in.Local.ToolingCppFlags, " "),
74 localConlyFlags: strings.Join(in.Local.ConlyFlags, " "),
75 localCppFlags: strings.Join(in.Local.CppFlags, " "),
76 localLdFlags: strings.Join(in.Local.LdFlags, " "),
Colin Cross4af21ed2019-11-04 09:37:55 -080077
78 aidlFlags: strings.Join(in.aidlFlags, " "),
79 rsFlags: strings.Join(in.rsFlags, " "),
80 libFlags: strings.Join(in.libFlags, " "),
81 extraLibFlags: strings.Join(in.extraLibFlags, " "),
82 tidyFlags: strings.Join(in.TidyFlags, " "),
83 sAbiFlags: strings.Join(in.SAbiFlags, " "),
84 toolchain: in.Toolchain,
Oliver Nguyen04526782020-04-21 12:40:27 -070085 gcovCoverage: in.GcovCoverage,
Colin Cross4af21ed2019-11-04 09:37:55 -080086 tidy: in.Tidy,
87 sAbiDump: in.SAbiDump,
88 emitXrefs: in.EmitXrefs,
Colin Cross18c0c5a2016-12-01 14:45:23 -080089
Colin Crossc3199482017-03-30 15:03:04 -070090 systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),
91
Dan Willemsen98ab3112019-08-27 21:20:40 -070092 assemblerWithCpp: in.AssemblerWithCpp,
93 groupStaticLibs: in.GroupStaticLibs,
Dan Willemsen60e62f02018-11-16 21:05:32 -080094
Colin Cross19878da2019-03-28 14:45:07 -070095 proto: in.proto,
Dan Willemsen60e62f02018-11-16 21:05:32 -080096 protoC: in.protoC,
97 protoOptionsFile: in.protoOptionsFile,
Dan Willemsen4e0aa232019-04-10 22:59:54 -070098
99 yacc: in.Yacc,
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200100 lex: in.Lex,
Colin Cross3f40fa42015-01-30 17:27:36 -0800101 }
102}
Dan Willemsen110a89d2016-01-14 15:17:19 -0800103
ThiƩbaud Weksteend4587452020-08-19 14:53:01 +0200104func flagsToStripFlags(in Flags) StripFlags {
105 return StripFlags{Toolchain: in.Toolchain}
106}
107
Dan Willemsen20acc5c2016-05-25 14:47:21 -0700108func addPrefix(list []string, prefix string) []string {
109 for i := range list {
110 list[i] = prefix + list[i]
111 }
112 return list
113}
Jiyong Parkab0fd5f2017-08-03 21:22:50 +0900114
115func addSuffix(list []string, suffix string) []string {
116 for i := range list {
117 list[i] = list[i] + suffix
118 }
119 return list
120}
Logan Chien031d2b32018-07-26 00:19:50 +0800121
Jiyong Parkf1194352019-02-25 11:05:47 +0900122// linkDirOnDevice/linkName -> target
123func makeSymlinkCmd(linkDirOnDevice string, linkName string, target string) string {
124 dir := filepath.Join("$(PRODUCT_OUT)", linkDirOnDevice)
125 return "mkdir -p " + dir + " && " +
126 "ln -sf " + target + " " + filepath.Join(dir, linkName)
127}