bldy.build/build@v0.0.0-20181002085557-d04b29acc6a7/skylark/action_run.go (about)

     1  package skylark
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"bldy.build/build/executor"
     8  )
     9  
    10  // Run represents a ctx.actions.run functions in bazel land.
    11  // https://docs.bazel.build/versions/master/skylark/lib/actions.html#run
    12  type run struct {
    13  	Outputs               []string          // List of the output files of the action.
    14  	Files                 []string          // List of the input files of the action.
    15  	Executable            string            // The executable file to be called by the action.
    16  	Arguments             []string          // Command line arguments of the action. Must be a list of strings or actions.args() objects.
    17  	Mnemonic              string            // A one-word description of the action, for example, CppCompile or GoLink.
    18  	ProgressMessage       string            // Progress message to show to the user during the build, for example, "Compiling foo.cc to create foo.o".
    19  	UseDefaultShellEnv    bool              // Whether the action should use the built in shell environment or not.
    20  	Env                   map[string]string // Sets the dictionary of environment variables.
    21  	ExecutionRequirements map[string]string // Information for scheduling the action. See tags for useful keys.
    22  }
    23  
    24  func (r *run) Do(e *executor.Executor) error {
    25  	env := os.Environ()
    26  	if !r.UseDefaultShellEnv {
    27  		env = []string{}
    28  	}
    29  	for k, v := range r.Env {
    30  		env = append(env, fmt.Sprintf("%s=%s", k, v))
    31  	}
    32  	e.Println(r.ProgressMessage)
    33  	return e.Exec(r.Executable, env, r.Arguments)
    34  }