• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package main
6
7import (
8	"os"
9)
10
11func processGomaCccFlags(builder *commandBuilder) (gomaUsed bool, err error) {
12	gomaPath := ""
13	nextArgIsGomaPath := false
14	builder.transformArgs(func(arg builderArg) string {
15		if arg.fromUser {
16			if arg.value == "--gomacc-path" {
17				nextArgIsGomaPath = true
18				return ""
19			}
20			if nextArgIsGomaPath {
21				gomaPath = arg.value
22				nextArgIsGomaPath = false
23				return ""
24			}
25		}
26		return arg.value
27	})
28	if nextArgIsGomaPath {
29		return false, newUserErrorf("--gomacc-path given without value")
30	}
31	if gomaPath == "" {
32		gomaPath, _ = builder.env.getenv("GOMACC_PATH")
33	}
34	if gomaPath != "" {
35		if _, err := os.Lstat(gomaPath); err == nil {
36			builder.wrapPath(gomaPath)
37			return true, nil
38		}
39	}
40	return false, nil
41}
42