go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/luciexe/legacy/annotee/annotation/execution.go (about) 1 // Copyright 2015 The LUCI Authors. 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 15 package annotation 16 17 import ( 18 "os" 19 20 "go.chromium.org/luci/common/system/environ" 21 ) 22 23 // Execution describes the high-level execution metadata. 24 type Execution struct { 25 Name string 26 Command []string 27 Dir string 28 Env map[string]string 29 } 30 31 // ProbeExecution loads Execution parameters by probing the current runtime 32 // environment. 33 func ProbeExecution(argv, env []string, cwd string) *Execution { 34 if env == nil { 35 env = os.Environ() 36 } 37 if cwd == "" { 38 cwd, _ = os.Getwd() 39 } 40 return probeExecutionImpl(argv, env, cwd) 41 } 42 43 func probeExecutionImpl(argv []string, env []string, cwd string) *Execution { 44 e := &Execution{ 45 Dir: cwd, 46 47 // Unique-ify the environment variables. 48 Env: environ.New(env).Map(), 49 } 50 e.Command = make([]string, len(argv)) 51 copy(e.Command, argv) 52 53 return e 54 }