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