Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Android/art/art/build/   (Android Betriebssystem Version 17©)  Datei vom 26.5.2026 mit Größe 5 kB image not shown  

Quelle  test_suite_data.go   Sprache: unbekannt

 
Spracherkennung für: .go vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

// Copyright (C) 2025 The Android Open Source Project
//
// 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 art

import (
 "path/filepath"
 "sort"
 "strings"

 "android/soong/android"
 "android/soong/cc/config"
)

func init() {
 android.RegisterModuleType("art_host_test_data", artHostTestDataFactory)
 android.RegisterParallelSingletonType("art_host_test_data_singleton", artHostTestDataSingletonFactory)
}

// artHostTestDataSingleton is a global singleton that collects test data from all relevant
// host modules and generates a single zip file. This approach is necessary because the data
// is spread across many modules, and a singleton is the only mechanism that can visit all
// modules to collect this information.
type artHostTestDataSingleton struct{}

func artHostTestDataSingletonFactory() android.Singleton {
 return &artHostTestDataSingleton{}
}

// getArtHostTestDataZipPath returns the well-known, predictable path for the zip file
// generated by the singleton. Both the singleton and the module use this function to ensure
// they refer to the same path.
func getArtHostTestDataZipPath(ctx android.PathContext, name string) android.WritablePath {
 return android.PathForOutput(ctx, "art", name+".zip")
}

func (s *artHostTestDataSingleton) GenerateBuildActions(ctx android.SingletonContext) {

 outputZip := getArtHostTestDataZipPath(ctx, "art_host_test_data")

 // A simple struct to hold the source path and its intended destination path inside the zip.
 type collectedFileInfo struct {
  SrcPath  android.Path
  DestPath string
 }

 // collectedFiles now simply stores a list of all files to be included in the zip.
 var collectedFiles []collectedFileInfo

 ctx.VisitAllModuleProxies(func(m android.ModuleProxy) {
  // Only consider host modules.
  commonInfo := android.OtherModuleProviderOrDefault(ctx, m, android.CommonModuleInfoProvider)
  if commonInfo.Target.Os.Class != android.Host {
   return
  }
  // Collect test case info from the art-specific provider.
  if provider, ok := android.OtherModuleProvider(ctx, m, testInstallInfoProvider); ok {
   for dest, src := range provider.Testcases {
    // Only accept source files from '.intermediates' directories.
    // This is a simplifying rule to resolve all duplication conflicts.
    if !strings.Contains(src.String(), ".intermediates") {
     continue // Skip this entry if it's not from an intermediates directory.
    }

    collectedFiles = append(collectedFiles, collectedFileInfo{
     SrcPath:  src,
     DestPath: filepath.Join("host/testcases/art_common/out/host/linux-x86/", dest),
    })
   }
  }
 })

 // Add prebuilt tools.
 // The original prebuilts directory is not accessible when running tests remotely.
 prebuiltToolsForTests := []string{
  "bin/clang",
  "bin/clang-real",
  "bin/llvm-addr2line",
  "bin/llvm-dwarfdump",
  "bin/llvm-objdump",
 }

 for _, tool := range prebuiltToolsForTests {
  src := config.ClangPath(ctx, tool).String()
  srcPath := android.ExistentPathForSource(ctx, src)
  if srcPath.Valid() {
   collectedFiles = append(collectedFiles, collectedFileInfo{
    SrcPath:  srcPath.Path(),
    DestPath: filepath.Join("host/testcases/art_common", src),
   })
  } else {
   // On some platforms (like Darwin), or when using older versions of clang,
   // the host prebuilt tools required for this test data zip may not exist.
   // Instead of breaking the build at Soong configuration time
   // (which would break CI builds that don't actually need this artifact),
   // we defer the failure to build execution time by creating an error rule.
   // This allows projects that do not depend on this target to build successfully.
   // For example, see b/449220418.
   android.ErrorRule(ctx, outputZip, "Error: ART host test data cannot be built because required prebuilt tool "+tool+" is missing.")
   return
  }
 }
 // If no data was collected, there's nothing to do.
 if len(collectedFiles) == 0 {
  return
 }

 rule := android.NewRuleBuilder(pctx, ctx)
 rule.SandboxDisabled()
 cmd := rule.Command().
  BuiltTool("soong_zip").
  Flag("-j").
  Flag("-symlinks=false"). // Dereference symlinks.
  FlagWithOutput("-o ", outputZip)

 // Sort the collected files by destination path for a deterministic command line.
 sort.Slice(collectedFiles, func(i, j int) bool {
  return collectedFiles[i].DestPath < collectedFiles[j].DestPath
 })

 for _, info := range collectedFiles {
  cmd.FlagWithArg("-e ", info.DestPath)
  cmd.FlagWithInput("-f ", info.SrcPath)
 }

 rule.Build(
  "create_art_host_data_zip",
  "Create "+outputZip.String(),
 )
}

// artHostTestDataModule acts as a "handle" or "proxy" to the zip file generated by the
// artHostTestDataSingleton. Other modules can depend on this module to get access to the zip.
// It does not generate any build rules itself; it only declares the output file that the
// singleton is responsible for creating.
type artHostTestDataModule struct {
 android.ModuleBase
 outputFile android.WritablePath
}

func artHostTestDataFactory() android.Module {
 module := &artHostTestDataModule{}
 android.InitAndroidModule(module)
 return module
}

func (m *artHostTestDataModule) DepsMutator(ctx android.BottomUpMutatorContext) {}

func (m *artHostTestDataModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
 // This module's output is the zip file generated by the singleton at the well-known path.
 // By setting this, we allow other modules to depend on this module and get the zip file.
 m.outputFile = getArtHostTestDataZipPath(ctx, m.Name())
 ctx.SetOutputFiles(android.Paths{m.outputFile}, "")
}

[Dauer der Verarbeitung: 0.21 Sekunden, vorverarbeitet 2026-06-29]