Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  defs.go   Sprache: unbekannt

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

// Copyright 2015 Google Inc. All rights reserved.
//
// 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 android

import (
 "fmt"
 "path/filepath"
 "strings"
 "unicode"

 "github.com/google/blueprint"
 "github.com/google/blueprint/proptools"
)

var (
 pctx = NewPackageContext("android/soong/android")

 cpPreserveSymlinks = pctx.VariableConfigMethod("cpPreserveSymlinks",
  Config.CpPreserveSymlinksFlags)

 HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", Config.PrebuiltOS)

 // A phony rule that is not the built-in Ninja phony rule.  The built-in
 // phony rule has special behavior that is sometimes not desired.  See the
 // Ninja docs for more details.
 Phony = pctx.AndroidStaticRule("Phony",
  blueprint.RuleParams{
   Command2:    blueprint.NewCommand("# phony $out"),
   Description: "phony $out",
  })

 // GeneratedFile is a rule for indicating that a given file was generated
 // while running soong.  This allows the file to be cleaned up if it ever
 // stops being generated by soong.
 GeneratedFile = pctx.AndroidStaticRule("GeneratedFile",
  blueprint.RuleParams{
   Command2:        blueprint.NewCommand("# generated $out"),
   Description:     "generated $out",
   Generator:       true,
   SandboxDisabled: true,
  })

 // A copy rule.
 CpRule = pctx.AndroidStaticRule("CpRule",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    Rm, " -f $out && ", Cp, " $cpPreserveSymlinks $cpFlags $in $out$extraCmds"),
   Description: "cp $out",
  },
  "cpFlags", "extraCmds")

 // A copy rule wrapped with bash.
 CpWithBash = pctx.AndroidStaticRule("CpWithBash",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    "/bin/bash -c \"rm -f $out && cp $cpFlags $cpPreserveSymlinks $in $out$extraCmds\""),
   Description:     "cp $out",
   SandboxDisabled: true,
  },
  "cpFlags", "extraCmds")

 // A copy rule that doesn't preserve symlinks.
 CpNoPreserveSymlink = pctx.AndroidStaticRule("CpNoPreserveSymlink",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    Rm, " -f $out && ", Cp, " $cpFlags $in $out$extraCmds"),
   Description: "cp $out",
  },
  "cpFlags", "extraCmds")

 // A copy rule that only updates the output if it changed.
 CpIfChangedRule = pctx.AndroidStaticRule("CpIfChanged",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    "if ! ", Cmp, " -s $in $out; then ", Cp, " $in $out; fi"),
   Description: "cp if changed $out",
   Restat:      true,
  })

 CpExecutable = pctx.AndroidStaticRule("CpExecutable",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    Rm, " -f $out && ", Cp, " $cpFlags $in $out && ", Chmod, " +x $out$extraCmds"),
   Description: "cp $out",
  },
  "cpFlags", "extraCmds")

 // A copy executable rule wrapped with bash
 CpExecutableWithBash = pctx.AndroidStaticRule("CpExecutableWithBash",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    "/bin/bash -c \"(", Rm, " -f $out && ", Cp, " $cpFlags $cpPreserveSymlinks $in $out ) && (", Chmod, " +x $out$extraCmds )\""),
   Description: "cp $out",
  },
  "cpFlags", "extraCmds")

 // A timestamp touch rule.
 TouchRule = pctx.AndroidStaticRule("TouchRule",
  blueprint.RuleParams{
   Command2:    blueprint.NewCommand(Touch, " $out"),
   Description: "touch $out",
  })

 // A symlink rule.
 Symlink = pctx.AndroidStaticRule("Symlink",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    Rm, " -f $out && ", Ln, " -f -s $fromPath $out"),
   Description: "symlink $out",
  },
  "fromPath")

 // A symlink rule wrapped with bash
 SymlinkWithBash = pctx.AndroidStaticRule("SymlinkWithBash",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    "/bin/bash -c \"", Rm, " -f $out && ", Ln, " -sfn $fromPath $out\""),
   Description:     "symlink $out",
   SandboxDisabled: true,
  },
  "fromPath")

 // A rule that verifies that $in is not a symlink. Touches a stamp file when done.
 VerifyNotSymlinkRule = pctx.AndroidStaticRule("VerifyNotSymlink",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    Rm, " -rf $out && ( ! ", Test, " -L $in ) && ", Touch, " $out"),
   Description: "verify not a symlink: $in",
  })

 // A rule that always fails at execution time with the given error message.
 // The error message must be passed through proptools.NinjaAndShellEscape() first.
 // Calling ErrorRule() will do that for you and use this rule.
 errorRule = pctx.AndroidStaticRule("Error",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    Echo, " $error && false"),
   Description: "error building $out",
  },
  "error")

 CatRule = pctx.AndroidStaticRule("CatRule",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    Rm, " -f $out && ", Cat, " $in > $out"),
   Description: "concatenate files to $out",
  })

 CatAndSort = pctx.AndroidStaticRule("CatAndSort",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    Rm, " -f $out && ", Cat, " $in > $out && ", Sort, " -o $out $out"),
   Description: "concatenate sorted file contents to $out",
  })

 CatAndSortAndUnique = pctx.AndroidStaticRule("CatAndSortAndUnique",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    Rm, " -f $out && ", Cat, " $in > $out && ", Sort, " -u -o $out $out"),
   Description: "concatenate sorted file contents to $out",
  })

 MergeZipsRule = pctx.AndroidStaticRule("MergeZips",
  blueprint.RuleParams{
   Command2:        blueprint.NewCommand(MergeZips, " -s $out $in"),
   SandboxDisabled: true,
  })

 AssembleVintfRule = pctx.StaticRule("AssembleVintfRule", blueprint.RuleParams{
  Command2: blueprint.NewCommand(
   Rm, " -f $out && VINTF_IGNORE_TARGET_FCM_VERSION=true ", assembleVintf, " -i $in -o $out"),
  Description: "run assemble_vintf",
 })

 depfileVerifierRule = pctx.AndroidStaticRule("DepfileVerifierRule",
  blueprint.RuleParams{
   Command2: blueprint.NewCommand(
    Rm, " -f $out && ", DepfileVerifier, " $in && ", Touch, " $out"),
   Description: "verify depfile",
  })

 // Used only when USE_REWRAPPER=true is set, to restrict non-RBE jobs to the local parallelism value
 localPool = blueprint.NewBuiltinPool("local_pool")

 // Used only by RuleBuilder to identify remoteable rules. Does not actually get created in ninja.
 remotePool = blueprint.NewBuiltinPool("remote_pool")

 // Used for processes that need significant RAM to ensure there are not too many running in parallel.
 highmemPool = blueprint.NewBuiltinPool("highmem_pool")
)

var (
 initToyboxTool = func(name string) func(PathContext) blueprint.HostToolParams {
  return func(pc PathContext) blueprint.HostToolParams {
   varName := string(unicode.ToUpper(rune(name[0]))) + name[1:]
   depsName := varName + "-deps"
   return blueprint.HostToolParams{
    Value: fmt.Sprintf("prebuilts/build-tools/path/%s/%s", pc.Config().PrebuiltOS(), name),
    Deps:  []string{depsName},
   }
  }
 }

 Basename  = pctx.HostToolFunc(initToyboxTool("basename"))
 Cat       = pctx.HostToolFunc(initToyboxTool("cat"))
 Chmod     = pctx.HostToolFunc(initToyboxTool("chmod"))
 Cmp       = pctx.HostToolFunc(initToyboxTool("cmp"))
 Comm      = pctx.HostToolFunc(initToyboxTool("comm"))
 Cp        = pctx.HostToolFunc(initToyboxTool("cp"))
 Cut       = pctx.HostToolFunc(initToyboxTool("cut"))
 Date      = pctx.HostToolFunc(initToyboxTool("date"))
 Dd        = pctx.HostToolFunc(initToyboxTool("dd"))
 Dirname   = pctx.HostToolFunc(initToyboxTool("dirname"))
 Dos2unix  = pctx.HostToolFunc(initToyboxTool("dos2unix"))
 Du        = pctx.HostToolFunc(initToyboxTool("du"))
 Echo      = pctx.HostToolFunc(initToyboxTool("echo"))
 Egrep     = pctx.HostToolFunc(initToyboxTool("egrep"))
 Env       = pctx.HostToolFunc(initToyboxTool("env"))
 File      = pctx.HostToolFunc(initToyboxTool("file"))
 Find      = pctx.HostToolFunc(initToyboxTool("find"))
 Getconf   = pctx.HostToolFunc(initToyboxTool("getconf"))
 Getopt    = pctx.HostToolFunc(initToyboxTool("getopt"))
 Grep      = pctx.HostToolFunc(initToyboxTool("grep"))
 Gzip      = pctx.HostToolFunc(initToyboxTool("gzip"))
 Head      = pctx.HostToolFunc(initToyboxTool("head"))
 Id        = pctx.HostToolFunc(initToyboxTool("id"))
 Install   = pctx.HostToolFunc(initToyboxTool("install"))
 Ln        = pctx.HostToolFunc(initToyboxTool("ln"))
 Ls        = pctx.HostToolFunc(initToyboxTool("ls"))
 Md5sum    = pctx.HostToolFunc(initToyboxTool("md5sum"))
 Mkdir     = pctx.HostToolFunc(initToyboxTool("mkdir"))
 Mktemp    = pctx.HostToolFunc(initToyboxTool("mktemp"))
 Mv        = pctx.HostToolFunc(initToyboxTool("mv"))
 Nl        = pctx.HostToolFunc(initToyboxTool("nl"))
 Od        = pctx.HostToolFunc(initToyboxTool("od"))
 Paste     = pctx.HostToolFunc(initToyboxTool("paste"))
 Patch     = pctx.HostToolFunc(initToyboxTool("patch"))
 Printf    = pctx.HostToolFunc(initToyboxTool("printf"))
 Pwd       = pctx.HostToolFunc(initToyboxTool("pwd"))
 Readlink  = pctx.HostToolFunc(initToyboxTool("readlink"))
 Realpath  = pctx.HostToolFunc(initToyboxTool("realpath"))
 Rm        = pctx.HostToolFunc(initToyboxTool("rm"))
 Rmdir     = pctx.HostToolFunc(initToyboxTool("rmdir"))
 Sed       = pctx.HostToolFunc(initToyboxTool("sed"))
 Seq       = pctx.HostToolFunc(initToyboxTool("seq"))
 Setsid    = pctx.HostToolFunc(initToyboxTool("setsid"))
 Sha1sum   = pctx.HostToolFunc(initToyboxTool("sha1sum"))
 Sha256sum = pctx.HostToolFunc(initToyboxTool("sha256sum"))
 Sha512sum = pctx.HostToolFunc(initToyboxTool("sha512sum"))
 Sleep     = pctx.HostToolFunc(initToyboxTool("sleep"))
 Sort      = pctx.HostToolFunc(initToyboxTool("sort"))
 Stat      = pctx.HostToolFunc(initToyboxTool("stat"))
 Tail      = pctx.HostToolFunc(initToyboxTool("tail"))
 Tar       = pctx.HostToolFunc(initToyboxTool("tar"))
 Tee       = pctx.HostToolFunc(initToyboxTool("tee"))
 Test      = pctx.HostToolFunc(initToyboxTool("test"))
 Timeout   = pctx.HostToolFunc(initToyboxTool("timeout"))
 Touch     = pctx.HostToolFunc(initToyboxTool("touch"))
 Tr        = pctx.HostToolFunc(initToyboxTool("tr"))
 True      = pctx.HostToolFunc(initToyboxTool("true"))
 Truncate  = pctx.HostToolFunc(initToyboxTool("truncate"))
 Uname     = pctx.HostToolFunc(initToyboxTool("uname"))
 Uniq      = pctx.HostToolFunc(initToyboxTool("uniq"))
 Unix2dos  = pctx.HostToolFunc(initToyboxTool("unix2dos"))
 Wc        = pctx.HostToolFunc(initToyboxTool("wc"))
 Which     = pctx.HostToolFunc(initToyboxTool("which"))
 Whoami    = pctx.HostToolFunc(initToyboxTool("whoami"))
 Xargs     = pctx.HostToolFunc(initToyboxTool("xargs"))
 Xxd       = pctx.HostToolFunc(initToyboxTool("xxd"))

 DepfileVerifier = pctx.HostTool("depfile_verifier")
 assembleVintf   = pctx.HostTool("assemble_vintf")
 SoongZip        = pctx.HostTool("soong_zip")
 MergeZips       = pctx.HostTool("merge_zips")
 ZipSync         = pctx.HostTool("zipsync")
 CpIfChanged     = pctx.HostTool("cp_if_changed")
 Zip2zip         = pctx.HostTool("zip2zip")

 // prebuiltSymlinkHostTool returns a function that resolves a host tool symlink
 // and its underlying real binary, ensuring both are added to the Ninja dependencies.
 prebuiltSymlinkHostTool = func(symlinkName, realBinName string) func(ctx PathContext) blueprint.HostToolParams {
  return func(ctx PathContext) blueprint.HostToolParams {
   symlink := filepath.Join("prebuilts/build-tools/path", ctx.Config().PrebuiltOS(), symlinkName)
   realBin := ctx.Config().PrebuiltBuildTool(ctx, realBinName).String()

   return blueprint.HostToolParams{
    Value: symlink,
    Deps:  []string{symlink, realBin},
   }
  }
 }

 Awk     = pctx.HostToolFunc(prebuiltSymlinkHostTool("awk", "one-true-awk"))
 Python3 = pctx.HostToolFunc(prebuiltSymlinkHostTool("python3", "py3-cmd"))
 ZipInfo = pctx.HostToolFunc(prebuiltSymlinkHostTool("zipinfo", "ziptool"))
)

var commonToyboxSymlinks = map[string]struct{}{
 "basename":  {},
 "cat":       {},
 "chmod":     {},
 "cmp":       {},
 "comm":      {},
 "cp":        {},
 "cut":       {},
 "date":      {},
 "dd":        {},
 "dirname":   {},
 "dos2unix":  {},
 "du":        {},
 "echo":      {},
 "egrep":     {},
 "env":       {},
 "file":      {},
 "find":      {},
 "getconf":   {},
 "getopt":    {},
 "grep":      {},
 "gzip":      {},
 "head":      {},
 "id":        {},
 "install":   {},
 "ln":        {},
 "ls":        {},
 "md5sum":    {},
 "mkdir":     {},
 "mktemp":    {},
 "mv":        {},
 "nl":        {},
 "od":        {},
 "paste":     {},
 "patch":     {},
 "printf":    {},
 "pwd":       {},
 "readlink":  {},
 "realpath":  {},
 "rm":        {},
 "rmdir":     {},
 "sed":       {},
 "seq":       {},
 "setsid":    {},
 "sha1sum":   {},
 "sha256sum": {},
 "sha512sum": {},
 "sleep":     {},
 "sort":      {},
 "stat":      {},
 "tail":      {},
 "tar":       {},
 "tee":       {},
 "test":      {},
 "timeout":   {},
 "touch":     {},
 "tr":        {},
 "true":      {},
 "truncate":  {},
 "uname":     {},
 "uniq":      {},
 "unix2dos":  {},
 "wc":        {},
 "which":     {},
 "whoami":    {},
 "xargs":     {},
 "xxd":       {},
}

func init() {
 pctx.Import("github.com/google/blueprint/bootstrap")

 pctx.VariableFunc("RBEWrapper", func(ctx PackageVarContext) string {
  return ctx.Config().RBEWrapper()
 })

 pctx.SourcePathVariable("toybox", "prebuilts/build-tools/${HostPrebuiltTag}/bin/toybox")

 InitRegistrationContext.RegisterParallelSingletonType("toybox_phonies_singleton", toyboxPhoniesSingletonFactory)
}

// CopyFileRule creates a ninja rule to copy path to outPath.
func CopyFileRule(ctx ModuleContext, path Path, outPath WritablePath, validations ...Path) {
 ctx.Build(pctx, BuildParams{
  Rule:        CpRule,
  Input:       path,
  Output:      outPath,
  Description: "copy " + outPath.Base(),
  Validations: validations,
 })
}

// ErrorRule creates a ninja action that fails to build the given file, failing with the
// provided error message.
func ErrorRule(ctx BuilderContext, path WritablePath, msg string) {
 ctx.Build(pctx, BuildParams{
  Rule:   errorRule,
  Output: path,
  Args: map[string]string{
   "error": proptools.NinjaAndShellEscape(msg),
  },
 })
}

// IsErrorRule returns true if the given rule was created by ErrorRuleFunc. Intended for use
// in tests.
func IsErrorRule(rule blueprint.Rule) bool {
 return rule == errorRule
}

// DepfileVerifierRule creates a rule that will check that all the inputs in the given depfile
// are also listed in the given inputs. It will touch an empty outPath if successful. This can
// be used as a validation action for
func DepfileVerifierRule(ctx ModuleContext, outPath WritablePath, depfile Path, inputs Paths) {
 inputsFile := outPath.AddExtension(ctx, "inputs_list")
 var inputsFileContents strings.Builder
 for _, input := range inputs {
  inputsFileContents.WriteString(input.String())
  inputsFileContents.WriteString("\n")
 }
 WriteFileRuleVerbatim(ctx, inputsFile, inputsFileContents.String())

 ctx.Build(pctx, BuildParams{
  Rule:   depfileVerifierRule,
  Inputs: Paths{depfile, inputsFile},
  Output: outPath,
 })
}

type toyboxPhoniesSingleton struct{}

func toyboxPhoniesSingletonFactory() Singleton {
 return &toyboxPhoniesSingleton{}
}

// Generate the phonies for the deps in a singleton, as blueprint currently doesn't have
// a way to create phonies from the init() function.
func (t *toyboxPhoniesSingleton) GenerateBuildActions(ctx SingletonContext) {
 for _, name := range SortedKeys(commonToyboxSymlinks) {
  varName := string(unicode.ToUpper(rune(name[0]))) + name[1:]
  binary := PathForSource(ctx, fmt.Sprintf("prebuilts/build-tools/%s/bin/toybox", ctx.Config().PrebuiltOS()))
  symlink := PathForSource(ctx, fmt.Sprintf("prebuilts/build-tools/path/%s/%s", ctx.Config().PrebuiltOS(), name))
  ctx.Build(pctx, BuildParams{
   Rule:   blueprint.Phony,
   Output: PathForPhony(ctx, varName+"-deps"),
   Inputs: []Path{binary, symlink},
  })
 }
}

[Dauer der Verarbeitung: 0.24 Sekunden, vorverarbeitet 2026-06-28]

                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik