sandbox_darwin.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2017 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 build
  15. import (
  16. "os/exec"
  17. )
  18. type Sandbox string
  19. const (
  20. noSandbox = ""
  21. globalSandbox = "build/soong/ui/build/sandbox/darwin/global.sb"
  22. dumpvarsSandbox = globalSandbox
  23. soongSandbox = globalSandbox
  24. katiSandbox = globalSandbox
  25. ninjaSandbox = noSandbox
  26. )
  27. var sandboxExecPath string
  28. func init() {
  29. if p, err := exec.LookPath("sandbox-exec"); err == nil {
  30. sandboxExecPath = p
  31. }
  32. }
  33. func (c *Cmd) sandboxSupported() bool {
  34. if c.Sandbox == "" {
  35. return false
  36. } else if sandboxExecPath == "" {
  37. c.ctx.Verboseln("sandbox-exec not found, disabling sandboxing")
  38. return false
  39. }
  40. return true
  41. }
  42. func (c *Cmd) wrapSandbox() {
  43. homeDir, _ := c.Environment.Get("HOME")
  44. outDir := absPath(c.ctx, c.config.OutDir())
  45. distDir := absPath(c.ctx, c.config.DistDir())
  46. c.Args[0] = c.Path
  47. c.Path = sandboxExecPath
  48. c.Args = append([]string{
  49. "sandbox-exec", "-f", string(c.Sandbox),
  50. "-D", "HOME=" + homeDir,
  51. "-D", "OUT_DIR=" + outDir,
  52. "-D", "DIST_DIR=" + distDir,
  53. }, c.Args...)
  54. }