• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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	"path/filepath"
19	"strings"
20
21	"android/soong/android"
22	"android/soong/snapshot"
23)
24
25// Efficiently converts a list of include directories to a single string
26// of cflags with -I prepended to each directory.
27func includeDirsToFlags(dirs android.Paths) string {
28	return android.JoinWithPrefix(dirs.Strings(), "-I")
29}
30
31var indexList = android.IndexList
32var inList = android.InList
33var filterList = android.FilterList
34var removeListFromList = android.RemoveListFromList
35var removeFromList = android.RemoveFromList
36
37func flagsToBuilderFlags(in Flags) builderFlags {
38	return builderFlags{
39		globalCommonFlags:     strings.Join(in.Global.CommonFlags, " "),
40		globalAsFlags:         strings.Join(in.Global.AsFlags, " "),
41		globalYasmFlags:       strings.Join(in.Global.YasmFlags, " "),
42		globalCFlags:          strings.Join(in.Global.CFlags, " "),
43		globalToolingCFlags:   strings.Join(in.Global.ToolingCFlags, " "),
44		globalToolingCppFlags: strings.Join(in.Global.ToolingCppFlags, " "),
45		globalConlyFlags:      strings.Join(in.Global.ConlyFlags, " "),
46		globalCppFlags:        strings.Join(in.Global.CppFlags, " "),
47		globalLdFlags:         strings.Join(in.Global.LdFlags, " "),
48
49		localCommonFlags:     strings.Join(in.Local.CommonFlags, " "),
50		localAsFlags:         strings.Join(in.Local.AsFlags, " "),
51		localYasmFlags:       strings.Join(in.Local.YasmFlags, " "),
52		localCFlags:          strings.Join(in.Local.CFlags, " "),
53		localToolingCFlags:   strings.Join(in.Local.ToolingCFlags, " "),
54		localToolingCppFlags: strings.Join(in.Local.ToolingCppFlags, " "),
55		localConlyFlags:      strings.Join(in.Local.ConlyFlags, " "),
56		localCppFlags:        strings.Join(in.Local.CppFlags, " "),
57		localLdFlags:         strings.Join(in.Local.LdFlags, " "),
58
59		aidlFlags:     strings.Join(in.aidlFlags, " "),
60		rsFlags:       strings.Join(in.rsFlags, " "),
61		libFlags:      strings.Join(in.libFlags, " "),
62		extraLibFlags: strings.Join(in.extraLibFlags, " "),
63		tidyFlags:     strings.Join(in.TidyFlags, " "),
64		sAbiFlags:     strings.Join(in.SAbiFlags, " "),
65		toolchain:     in.Toolchain,
66		gcovCoverage:  in.GcovCoverage,
67		tidy:          in.Tidy,
68		needTidyFiles: in.NeedTidyFiles,
69		sAbiDump:      in.SAbiDump,
70		emitXrefs:     in.EmitXrefs,
71
72		systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),
73
74		assemblerWithCpp: in.AssemblerWithCpp,
75
76		proto:            in.proto,
77		protoC:           in.protoC,
78		protoOptionsFile: in.protoOptionsFile,
79
80		yacc: in.Yacc,
81		lex:  in.Lex,
82	}
83}
84
85func flagsToStripFlags(in Flags) StripFlags {
86	return StripFlags{Toolchain: in.Toolchain}
87}
88
89func addPrefix(list []string, prefix string) []string {
90	for i := range list {
91		list[i] = prefix + list[i]
92	}
93	return list
94}
95
96// linkDirOnDevice/linkName -> target
97func makeSymlinkCmd(linkDirOnDevice string, linkName string, target string) string {
98	dir := filepath.Join("$(PRODUCT_OUT)", linkDirOnDevice)
99	return "mkdir -p " + dir + " && " +
100		"ln -sf " + target + " " + filepath.Join(dir, linkName)
101}
102
103// Dump a map to a list file as:
104//
105// {key1} {value1}
106// {key2} {value2}
107// ...
108func installMapListFileRule(ctx android.SingletonContext, m map[string]string, path string) android.OutputPath {
109	var txtBuilder strings.Builder
110	for idx, k := range android.SortedKeys(m) {
111		if idx > 0 {
112			txtBuilder.WriteString("\n")
113		}
114		txtBuilder.WriteString(k)
115		txtBuilder.WriteString(" ")
116		txtBuilder.WriteString(m[k])
117	}
118	return snapshot.WriteStringToFileRule(ctx, txtBuilder.String(), path)
119}
120