util.go 4.0 KB

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