blob: 34739b756bafe920b966c3a6deeaac8c5b4c8dd5 [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 main
16
17import (
18 "context"
19 "os"
20 "path/filepath"
21 "strconv"
22 "strings"
23 "time"
24
25 "android/soong/ui/build"
26 "android/soong/ui/logger"
27)
28
29func indexList(s string, list []string) int {
30 for i, l := range list {
31 if l == s {
32 return i
33 }
34 }
35
36 return -1
37}
38
39func inList(s string, list []string) bool {
40 return indexList(s, list) != -1
41}
42
43func main() {
44 log := logger.New(os.Stderr)
45 defer log.Cleanup()
46
47 if len(os.Args) < 2 || !inList("--make-mode", os.Args) {
48 log.Fatalln("The `soong` native UI is not yet available.")
49 }
50
Dan Willemsen1e704462016-08-21 15:17:17 -070051 ctx, cancel := context.WithCancel(context.Background())
52 defer cancel()
53
54 build.SetupSignals(log, cancel, log.Cleanup)
55
56 buildCtx := &build.ContextImpl{
57 Context: ctx,
58 Logger: log,
59 StdioInterface: build.StdioImpl{},
60 }
61 config := build.NewConfig(buildCtx, os.Args[1:]...)
62
63 log.SetVerbose(config.IsVerbose())
64 if err := os.MkdirAll(config.OutDir(), 0777); err != nil {
65 log.Fatalf("Error creating out directory: %v", err)
66 }
67 log.SetOutput(filepath.Join(config.OutDir(), "build.log"))
68
69 if start, ok := os.LookupEnv("TRACE_BEGIN_SOONG"); ok {
70 if !strings.HasSuffix(start, "N") {
71 if start_time, err := strconv.ParseUint(start, 10, 64); err == nil {
72 log.Verbosef("Took %dms to start up.",
73 time.Since(time.Unix(0, int64(start_time))).Nanoseconds()/time.Millisecond.Nanoseconds())
74 }
75 }
76 }
77
78 build.Build(buildCtx, config, build.BuildAll)
79}