util.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2021 The Android Open Source Project
  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 snapshot
  15. import "android/soong/android"
  16. func WriteStringToFileRule(ctx android.SingletonContext, content, out string) android.OutputPath {
  17. outPath := android.PathForOutput(ctx, out)
  18. android.WriteFileRule(ctx, outPath, content)
  19. return outPath
  20. }
  21. func CopyFileRule(pctx android.PackageContext, ctx android.SingletonContext, path android.Path, out string) android.OutputPath {
  22. outPath := android.PathForOutput(ctx, out)
  23. ctx.Build(pctx, android.BuildParams{
  24. Rule: android.Cp,
  25. Input: path,
  26. Output: outPath,
  27. Description: "copy " + path.String() + " -> " + out,
  28. Args: map[string]string{
  29. "cpFlags": "-f -L",
  30. },
  31. })
  32. return outPath
  33. }
  34. // zip snapshot
  35. func zipSnapshot(ctx android.SingletonContext, dir string, baseName string, snapshotOutputs android.Paths) android.OptionalPath {
  36. zipPath := android.PathForOutput(
  37. ctx, dir, baseName+".zip")
  38. zipRule := android.NewRuleBuilder(pctx, ctx)
  39. rspFile := android.PathForOutput(
  40. ctx, dir, baseName+"_list.rsp")
  41. zipRule.Command().
  42. BuiltTool("soong_zip").
  43. FlagWithOutput("-o ", zipPath).
  44. FlagWithArg("-C ", android.PathForOutput(ctx, dir).String()).
  45. FlagWithRspFileInputList("-r ", rspFile, snapshotOutputs)
  46. zipRule.Build(zipPath.String(), baseName+" snapshot "+zipPath.String())
  47. return android.OptionalPathForPath(zipPath)
  48. }