blob: 59474f53d7db1d8ec5ef8f98137da6de568e5d5a [file] [log] [blame]
Dan Willemsen1e704462016-08-21 15:17:17 -07001// 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 "context"
19 "io"
20 "os"
21
22 "android/soong/ui/logger"
23)
24
25type StdioInterface interface {
26 Stdin() io.Reader
27 Stdout() io.Writer
28 Stderr() io.Writer
29}
30
31type StdioImpl struct{}
32
33func (StdioImpl) Stdin() io.Reader { return os.Stdin }
34func (StdioImpl) Stdout() io.Writer { return os.Stdout }
35func (StdioImpl) Stderr() io.Writer { return os.Stderr }
36
37var _ StdioInterface = StdioImpl{}
38
39type customStdio struct {
40 stdin io.Reader
41 stdout io.Writer
42 stderr io.Writer
43}
44
45func NewCustomStdio(stdin io.Reader, stdout, stderr io.Writer) StdioInterface {
46 return customStdio{stdin, stdout, stderr}
47}
48
49func (c customStdio) Stdin() io.Reader { return c.stdin }
50func (c customStdio) Stdout() io.Writer { return c.stdout }
51func (c customStdio) Stderr() io.Writer { return c.stderr }
52
53var _ StdioInterface = customStdio{}
54
55// Context combines a context.Context, logger.Logger, and StdIO redirection.
56// These all are agnostic of the current build, and may be used for multiple
57// builds, while the Config objects contain per-build information.
58type Context *ContextImpl
59type ContextImpl struct {
60 context.Context
61 logger.Logger
62
63 StdioInterface
64}