blob: 3b211063b0627dc8655e91a0b98fccd650da6fb8 [file] [log] [blame]
Colin Cross43f08db2018-11-12 10:13:39 -08001// Copyright 2018 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
15// The dexpreopt package converts a global dexpreopt config and a module dexpreopt config into rules to perform
16// dexpreopting and to strip the dex files from the APK or JAR.
17//
18// It is used in two places; in the dexpeopt_gen binary for modules defined in Make, and directly linked into Soong.
19//
20// For Make modules it is built into the dexpreopt_gen binary, which is executed as a Make rule using global config and
21// module config specified in JSON files. The binary writes out two shell scripts, only updating them if they have
22// changed. One script takes an APK or JAR as an input and produces a zip file containing any outputs of preopting,
23// in the location they should be on the device. The Make build rules will unzip the zip file into $(PRODUCT_OUT) when
24// installing the APK, which will install the preopt outputs into $(PRODUCT_OUT)/system or $(PRODUCT_OUT)/system_other
25// as necessary. The zip file may be empty if preopting was disabled for any reason. The second script takes an APK or
26// JAR as an input and strips the dex files in it as necessary.
27//
28// The intermediate shell scripts allow changes to this package or to the global config to regenerate the shell scripts
29// but only require re-executing preopting if the script has changed.
30//
31// For Soong modules this package is linked directly into Soong and run from the java package. It generates the same
32// commands as for make, using athe same global config JSON file used by make, but using a module config structure
33// provided by Soong. The generated commands are then converted into Soong rule and written directly to the ninja file,
34// with no extra shell scripts involved.
35package dexpreopt
36
37import (
38 "fmt"
39 "path/filepath"
40 "strings"
41
42 "github.com/google/blueprint/pathtools"
43)
44
45const SystemPartition = "/system/"
46const SystemOtherPartition = "/system_other/"
47
48// GenerateStripRule generates a set of commands that will take an APK or JAR as an input and strip the dex files if
49// they are no longer necessary after preopting.
50func GenerateStripRule(global GlobalConfig, module ModuleConfig) (rule *Rule, err error) {
51 defer func() {
52 if r := recover(); r != nil {
53 if e, ok := r.(error); ok {
54 err = e
55 rule = nil
56 } else {
57 panic(r)
58 }
59 }
60 }()
61
62 tools := global.Tools
63
64 rule = &Rule{}
65
66 strip := shouldStripDex(module, global)
67
68 if strip {
69 // Only strips if the dex files are not already uncompressed
70 rule.Command().
71 Textf(`if (zipinfo %s '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, module.StripInputPath).
72 Tool(tools.Zip2zip).FlagWithInput("-i ", module.StripInputPath).FlagWithOutput("-o ", module.StripOutputPath).
73 FlagWithArg("-x ", `"classes*.dex"`).
74 Textf(`; else cp -f %s %s; fi`, module.StripInputPath, module.StripOutputPath)
75 } else {
76 rule.Command().Text("cp -f").Input(module.StripInputPath).Output(module.StripOutputPath)
77 }
78
79 return rule, nil
80}
81
82// GenerateDexpreoptRule generates a set of commands that will preopt a module based on a GlobalConfig and a
83// ModuleConfig. The produced files and their install locations will be available through rule.Installs().
84func GenerateDexpreoptRule(global GlobalConfig, module ModuleConfig) (rule *Rule, err error) {
85 defer func() {
86 if r := recover(); r != nil {
87 if e, ok := r.(error); ok {
88 err = e
89 rule = nil
90 } else {
91 panic(r)
92 }
93 }
94 }()
95
96 rule = &Rule{}
97
98 dexpreoptDisabled := contains(global.DisablePreoptModules, module.Name)
99
100 if contains(global.BootJars, module.Name) {
101 // Don't preopt individual boot jars, they will be preopted together
102 dexpreoptDisabled = true
103 }
104
105 // If OnlyPreoptBootImageAndSystemServer=true and module is not in boot class path skip
106 // Also preopt system server jars since selinux prevents system server from loading anything from
107 // /data. If we don't do this they will need to be extracted which is not favorable for RAM usage
108 // or performance. If PreoptExtractedApk is true, we ignore the only preopt boot image options.
109 if global.OnlyPreoptBootImageAndSystemServer && !contains(global.BootJars, module.Name) &&
110 !contains(global.SystemServerJars, module.Name) && !module.PreoptExtractedApk {
111 dexpreoptDisabled = true
112 }
113
114 generateProfile := module.ProfileClassListing != "" && !global.DisableGenerateProfile
115
116 var profile string
117 if generateProfile {
118 profile = profileCommand(global, module, rule)
119 }
120
121 if !dexpreoptDisabled {
122 appImage := (generateProfile || module.ForceCreateAppImage || global.DefaultAppImages) &&
123 !module.NoCreateAppImage
124
125 generateDM := shouldGenerateDM(module, global)
126
127 for _, arch := range module.Archs {
128 imageLocation := module.DexPreoptImageLocation
129 if imageLocation == "" {
130 imageLocation = global.DefaultDexPreoptImageLocation[arch]
131 }
132 dexpreoptCommand(global, module, rule, profile, arch, imageLocation, appImage, generateDM)
133 }
134 }
135
136 return rule, nil
137}
138
139func profileCommand(global GlobalConfig, module ModuleConfig, rule *Rule) string {
140 profilePath := filepath.Join(filepath.Dir(module.BuildPath), "profile.prof")
141 profileInstalledPath := module.DexLocation + ".prof"
142
143 if !module.ProfileIsTextListing {
144 rule.Command().FlagWithOutput("touch ", profilePath)
145 }
146
147 cmd := rule.Command().
148 Text(`ANDROID_LOG_TAGS="*:e"`).
149 Tool(global.Tools.Profman)
150
151 if module.ProfileIsTextListing {
152 // The profile is a test listing of classes (used for framework jars).
153 // We need to generate the actual binary profile before being able to compile.
154 cmd.FlagWithInput("--create-profile-from=", module.ProfileClassListing)
155 } else {
156 // The profile is binary profile (used for apps). Run it through profman to
157 // ensure the profile keys match the apk.
158 cmd.
159 Flag("--copy-and-update-profile-key").
160 FlagWithInput("--profile-file=", module.ProfileClassListing)
161 }
162
163 cmd.
164 FlagWithInput("--apk=", module.DexPath).
165 Flag("--dex-location="+module.DexLocation).
166 FlagWithOutput("--reference-profile-file=", profilePath)
167
168 if !module.ProfileIsTextListing {
169 cmd.Text(fmt.Sprintf(`|| echo "Profile out of date for %s"`, module.DexPath))
170 }
171 rule.Install(profilePath, profileInstalledPath)
172
173 return profilePath
174}
175
176func dexpreoptCommand(global GlobalConfig, module ModuleConfig, rule *Rule, profile, arch, bootImageLocation string,
177 appImage, generateDM bool) {
178
179 // HACK: make soname in Soong-generated .odex files match Make.
180 base := filepath.Base(module.DexLocation)
181 if filepath.Ext(base) == ".jar" {
182 base = "javalib.jar"
183 } else if filepath.Ext(base) == ".apk" {
184 base = "package.apk"
185 }
186
187 toOdexPath := func(path string) string {
188 return filepath.Join(
189 filepath.Dir(path),
190 "oat",
191 arch,
192 pathtools.ReplaceExtension(filepath.Base(path), "odex"))
193 }
194
195 odexPath := toOdexPath(filepath.Join(filepath.Dir(module.BuildPath), base))
196 odexInstallPath := toOdexPath(module.DexLocation)
197 if odexOnSystemOther(module, global) {
198 odexInstallPath = strings.Replace(odexInstallPath, SystemPartition, SystemOtherPartition, 1)
199 }
200
201 vdexPath := pathtools.ReplaceExtension(odexPath, "vdex")
202 vdexInstallPath := pathtools.ReplaceExtension(odexInstallPath, "vdex")
203
Alex Light5de41962018-12-18 15:16:26 -0800204 invocationPath := pathtools.ReplaceExtension(odexPath, "invocation")
205
Colin Cross43f08db2018-11-12 10:13:39 -0800206 // bootImageLocation is $OUT/dex_bootjars/system/framework/boot.art, but dex2oat actually reads
207 // $OUT/dex_bootjars/system/framework/arm64/boot.art
208 var bootImagePath string
209 if bootImageLocation != "" {
210 bootImagePath = filepath.Join(filepath.Dir(bootImageLocation), arch, filepath.Base(bootImageLocation))
211 }
212
213 // Lists of used and optional libraries from the build config to be verified against the manifest in the APK
214 var verifyUsesLibs []string
215 var verifyOptionalUsesLibs []string
216
217 // Lists of used and optional libraries from the build config, with optional libraries that are known to not
218 // be present in the current product removed.
219 var filteredUsesLibs []string
220 var filteredOptionalUsesLibs []string
221
222 // The class loader context using paths in the build
223 var classLoaderContextHost []string
224
225 // The class loader context using paths as they will be on the device
226 var classLoaderContextTarget []string
227
228 // Extra paths that will be appended to the class loader if the APK manifest has targetSdkVersion < 28
Nicolas Geoffray05aa7d22018-12-18 14:15:12 +0000229 var conditionalClassLoaderContextHost28 []string
230 var conditionalClassLoaderContextTarget28 []string
231
232 // Extra paths that will be appended to the class loader if the APK manifest has targetSdkVersion < 29
233 var conditionalClassLoaderContextHost29 []string
234 var conditionalClassLoaderContextTarget29 []string
Colin Cross43f08db2018-11-12 10:13:39 -0800235
236 if module.EnforceUsesLibraries {
237 verifyUsesLibs = copyOf(module.UsesLibraries)
238 verifyOptionalUsesLibs = copyOf(module.OptionalUsesLibraries)
239
240 filteredOptionalUsesLibs = filterOut(global.MissingUsesLibraries, module.OptionalUsesLibraries)
241 filteredUsesLibs = append(copyOf(module.UsesLibraries), filteredOptionalUsesLibs...)
242
243 // Create class loader context for dex2oat from uses libraries and filtered optional libraries
244 for _, l := range filteredUsesLibs {
245
246 classLoaderContextHost = append(classLoaderContextHost,
247 pathForLibrary(module, l))
248 classLoaderContextTarget = append(classLoaderContextTarget,
249 filepath.Join("/system/framework", l+".jar"))
250 }
251
252 const httpLegacy = "org.apache.http.legacy"
253 const httpLegacyImpl = "org.apache.http.legacy.impl"
254
255 // Fix up org.apache.http.legacy.impl since it should be org.apache.http.legacy in the manifest.
256 replace(verifyUsesLibs, httpLegacyImpl, httpLegacy)
257 replace(verifyOptionalUsesLibs, httpLegacyImpl, httpLegacy)
258
259 if !contains(verifyUsesLibs, httpLegacy) && !contains(verifyOptionalUsesLibs, httpLegacy) {
Nicolas Geoffray05aa7d22018-12-18 14:15:12 +0000260 conditionalClassLoaderContextHost28 = append(conditionalClassLoaderContextHost28,
Colin Cross43f08db2018-11-12 10:13:39 -0800261 pathForLibrary(module, httpLegacyImpl))
Nicolas Geoffray05aa7d22018-12-18 14:15:12 +0000262 conditionalClassLoaderContextTarget28 = append(conditionalClassLoaderContextTarget28,
Colin Cross43f08db2018-11-12 10:13:39 -0800263 filepath.Join("/system/framework", httpLegacyImpl+".jar"))
264 }
Nicolas Geoffray05aa7d22018-12-18 14:15:12 +0000265
266 const hidlBase = "android.hidl.base-V1.0-java"
267 const hidlManager = "android.hidl.manager-V1.0-java"
268
269 conditionalClassLoaderContextHost29 = append(conditionalClassLoaderContextHost29,
Alex Light5de41962018-12-18 15:16:26 -0800270 pathForLibrary(module, hidlManager))
Nicolas Geoffray05aa7d22018-12-18 14:15:12 +0000271 conditionalClassLoaderContextTarget29 = append(conditionalClassLoaderContextTarget29,
272 filepath.Join("/system/framework", hidlManager+".jar"))
273 conditionalClassLoaderContextHost29 = append(conditionalClassLoaderContextHost29,
Alex Light5de41962018-12-18 15:16:26 -0800274 pathForLibrary(module, hidlBase))
Nicolas Geoffray05aa7d22018-12-18 14:15:12 +0000275 conditionalClassLoaderContextTarget29 = append(conditionalClassLoaderContextTarget29,
276 filepath.Join("/system/framework", hidlBase+".jar"))
Colin Cross43f08db2018-11-12 10:13:39 -0800277 } else {
278 // Pass special class loader context to skip the classpath and collision check.
279 // This will get removed once LOCAL_USES_LIBRARIES is enforced.
280 // Right now LOCAL_USES_LIBRARIES is opt in, for the case where it's not specified we still default
281 // to the &.
282 classLoaderContextHost = []string{`\&`}
283 }
284
285 rule.Command().FlagWithArg("mkdir -p ", filepath.Dir(odexPath))
286 rule.Command().FlagWithOutput("rm -f ", odexPath)
287 // Set values in the environment of the rule. These may be modified by construct_context.sh.
288 rule.Command().FlagWithArg("class_loader_context_arg=--class-loader-context=",
289 strings.Join(classLoaderContextHost, ":"))
290 rule.Command().Text(`stored_class_loader_context_arg=""`)
291
292 if module.EnforceUsesLibraries {
Colin Cross43f08db2018-11-12 10:13:39 -0800293 rule.Command().Textf(`uses_library_names="%s"`, strings.Join(verifyUsesLibs, " "))
294 rule.Command().Textf(`optional_uses_library_names="%s"`, strings.Join(verifyOptionalUsesLibs, " "))
295 rule.Command().Textf(`aapt_binary="%s"`, global.Tools.Aapt)
Alex Light5de41962018-12-18 15:16:26 -0800296 rule.Command().Textf(`dex_preopt_host_libraries="%s"`, strings.Join(classLoaderContextHost, " "))
Nicolas Geoffray05aa7d22018-12-18 14:15:12 +0000297 rule.Command().Textf(`dex_preopt_target_libraries="%s"`, strings.Join(classLoaderContextTarget, " "))
298 rule.Command().Textf(`conditional_host_libs_28="%s"`, strings.Join(conditionalClassLoaderContextHost28, " "))
299 rule.Command().Textf(`conditional_target_libs_28="%s"`, strings.Join(conditionalClassLoaderContextTarget28, " "))
300 rule.Command().Textf(`conditional_host_libs_29="%s"`, strings.Join(conditionalClassLoaderContextHost29, " "))
301 rule.Command().Textf(`conditional_target_libs_29="%s"`, strings.Join(conditionalClassLoaderContextTarget29, " "))
Colin Cross43f08db2018-11-12 10:13:39 -0800302 rule.Command().Text("source").Tool(global.Tools.VerifyUsesLibraries).Input(module.DexPath)
Nicolas Geoffray05aa7d22018-12-18 14:15:12 +0000303 rule.Command().Text("source").Tool(global.Tools.ConstructContext)
Colin Cross43f08db2018-11-12 10:13:39 -0800304 }
305
306 cmd := rule.Command().
307 Text(`ANDROID_LOG_TAGS="*:e"`).
308 Tool(global.Tools.Dex2oat).
309 Flag("--avoid-storing-invocation").
Alex Light5de41962018-12-18 15:16:26 -0800310 FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
Colin Cross43f08db2018-11-12 10:13:39 -0800311 Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatXms).
312 Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatXmx).
313 Flag("${class_loader_context_arg}").
314 Flag("${stored_class_loader_context_arg}").
315 FlagWithArg("--boot-image=", bootImageLocation).Implicit(bootImagePath).
316 FlagWithInput("--dex-file=", module.DexPath).
317 FlagWithArg("--dex-location=", module.DexLocation).
318 FlagWithOutput("--oat-file=", odexPath).ImplicitOutput(vdexPath).
319 // Pass an empty directory, dex2oat shouldn't be reading arbitrary files
320 FlagWithArg("--android-root=", global.EmptyDirectory).
321 FlagWithArg("--instruction-set=", arch).
322 FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch]).
323 FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch]).
324 Flag("--no-generate-debug-info").
325 Flag("--generate-build-id").
326 Flag("--abort-on-hard-verifier-error").
327 Flag("--force-determinism").
328 FlagWithArg("--no-inline-from=", "core-oj.jar")
329
330 var preoptFlags []string
331 if len(module.PreoptFlags) > 0 {
332 preoptFlags = module.PreoptFlags
333 } else if len(global.PreoptFlags) > 0 {
334 preoptFlags = global.PreoptFlags
335 }
336
337 if len(preoptFlags) > 0 {
338 cmd.Text(strings.Join(preoptFlags, " "))
339 }
340
341 if module.UncompressedDex {
342 cmd.FlagWithArg("--copy-dex-files=", "false")
343 }
344
345 if !anyHavePrefix(preoptFlags, "--compiler-filter=") {
346 var compilerFilter string
347 if contains(global.SystemServerJars, module.Name) {
348 // Jars of system server, use the product option if it is set, speed otherwise.
349 if global.SystemServerCompilerFilter != "" {
350 compilerFilter = global.SystemServerCompilerFilter
351 } else {
352 compilerFilter = "speed"
353 }
354 } else if contains(global.SpeedApps, module.Name) || contains(global.SystemServerApps, module.Name) {
355 // Apps loaded into system server, and apps the product default to being compiled with the
356 // 'speed' compiler filter.
357 compilerFilter = "speed"
358 } else if profile != "" {
359 // For non system server jars, use speed-profile when we have a profile.
360 compilerFilter = "speed-profile"
361 } else if global.DefaultCompilerFilter != "" {
362 compilerFilter = global.DefaultCompilerFilter
363 } else {
364 compilerFilter = "quicken"
365 }
366 cmd.FlagWithArg("--compiler-filter=", compilerFilter)
367 }
368
369 if generateDM {
370 cmd.FlagWithArg("--copy-dex-files=", "false")
371 dmPath := filepath.Join(filepath.Dir(module.BuildPath), "generated.dm")
372 dmInstalledPath := pathtools.ReplaceExtension(module.DexLocation, "dm")
373 tmpPath := filepath.Join(filepath.Dir(module.BuildPath), "primary.vdex")
374 rule.Command().Text("cp -f").Input(vdexPath).Output(tmpPath)
375 rule.Command().Tool(global.Tools.SoongZip).
376 FlagWithArg("-L", "9").
377 FlagWithOutput("-o", dmPath).
378 Flag("-j").
379 Input(tmpPath)
380 rule.Install(dmPath, dmInstalledPath)
381 }
382
383 // By default, emit debug info.
384 debugInfo := true
385 if global.NoDebugInfo {
386 // If the global setting suppresses mini-debug-info, disable it.
387 debugInfo = false
388 }
389
390 // PRODUCT_SYSTEM_SERVER_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO.
391 // PRODUCT_OTHER_JAVA_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO.
392 if contains(global.SystemServerJars, module.Name) {
393 if global.AlwaysSystemServerDebugInfo {
394 debugInfo = true
395 } else if global.NeverSystemServerDebugInfo {
396 debugInfo = false
397 }
398 } else {
399 if global.AlwaysOtherDebugInfo {
400 debugInfo = true
401 } else if global.NeverOtherDebugInfo {
402 debugInfo = false
403 }
404 }
405
406 // Never enable on eng.
407 if global.IsEng {
408 debugInfo = false
409 }
410
411 if debugInfo {
412 cmd.Flag("--generate-mini-debug-info")
413 } else {
414 cmd.Flag("--no-generate-mini-debug-info")
415 }
416
417 // Set the compiler reason to 'prebuilt' to identify the oat files produced
418 // during the build, as opposed to compiled on the device.
419 cmd.FlagWithArg("--compilation-reason=", "prebuilt")
420
421 if appImage {
422 appImagePath := pathtools.ReplaceExtension(odexPath, "art")
423 appImageInstallPath := pathtools.ReplaceExtension(odexInstallPath, "art")
424 cmd.FlagWithOutput("--app-image-file=", appImagePath).
425 FlagWithArg("--image-format=", "lz4")
426 rule.Install(appImagePath, appImageInstallPath)
427 }
428
429 if profile != "" {
430 cmd.FlagWithArg("--profile-file=", profile)
431 }
432
433 rule.Install(odexPath, odexInstallPath)
434 rule.Install(vdexPath, vdexInstallPath)
435}
436
437// Return if the dex file in the APK should be stripped. If an APK is found to contain uncompressed dex files at
438// dex2oat time it will not be stripped even if strip=true.
439func shouldStripDex(module ModuleConfig, global GlobalConfig) bool {
440 strip := !global.DefaultNoStripping
441
442 // Don't strip modules that are not on the system partition in case the oat/vdex version in system ROM
443 // doesn't match the one in other partitions. It needs to be able to fall back to the APK for that case.
444 if !strings.HasPrefix(module.DexLocation, SystemPartition) {
445 strip = false
446 }
447
448 // system_other isn't there for an OTA, so don't strip if module is on system, and odex is on system_other.
449 if odexOnSystemOther(module, global) {
450 strip = false
451 }
452
453 if module.HasApkLibraries {
454 strip = false
455 }
456
457 // Don't strip with dex files we explicitly uncompress (dexopt will not store the dex code).
458 if module.UncompressedDex {
459 strip = false
460 }
461
462 if shouldGenerateDM(module, global) {
463 strip = false
464 }
465
466 if module.PresignedPrebuilt {
467 // Only strip out files if we can re-sign the package.
468 strip = false
469 }
470
471 return strip
472}
473
474func shouldGenerateDM(module ModuleConfig, global GlobalConfig) bool {
475 // Generating DM files only makes sense for verify, avoid doing for non verify compiler filter APKs.
476 // No reason to use a dm file if the dex is already uncompressed.
477 return global.GenerateDMFiles && !module.UncompressedDex &&
478 contains(module.PreoptFlags, "--compiler-filter=verify")
479}
480
481func odexOnSystemOther(module ModuleConfig, global GlobalConfig) bool {
482 if !global.HasSystemOther {
483 return false
484 }
485
486 if global.SanitizeLite {
487 return false
488 }
489
490 if contains(global.SpeedApps, module.Name) || contains(global.SystemServerApps, module.Name) {
491 return false
492 }
493
494 for _, f := range global.PatternsOnSystemOther {
495 if makefileMatch(filepath.Join(SystemPartition, f), module.DexLocation) {
496 return true
497 }
498 }
499
500 return false
501}
502
503func pathForLibrary(module ModuleConfig, lib string) string {
504 path := module.LibraryPaths[lib]
505 if path == "" {
506 panic(fmt.Errorf("unknown library path for %q", lib))
507 }
508 return path
509}
510
511func makefileMatch(pattern, s string) bool {
512 percent := strings.IndexByte(pattern, '%')
513 switch percent {
514 case -1:
515 return pattern == s
516 case len(pattern) - 1:
517 return strings.HasPrefix(s, pattern[:len(pattern)-1])
518 default:
519 panic(fmt.Errorf("unsupported makefile pattern %q", pattern))
520 }
521}
522
523func contains(l []string, s string) bool {
524 for _, e := range l {
525 if e == s {
526 return true
527 }
528 }
529 return false
530}
531
532// remove all elements in a from b, returning a new slice
533func filterOut(a []string, b []string) []string {
534 var ret []string
535 for _, x := range b {
536 if !contains(a, x) {
537 ret = append(ret, x)
538 }
539 }
540 return ret
541}
542
543func replace(l []string, from, to string) {
544 for i := range l {
545 if l[i] == from {
546 l[i] = to
547 }
548 }
549}
550
551func copyOf(l []string) []string {
552 return append([]string(nil), l...)
553}
554
555func anyHavePrefix(l []string, prefix string) bool {
556 for _, x := range l {
557 if strings.HasPrefix(x, prefix) {
558 return true
559 }
560 }
561 return false
562}