aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/sysroot_flag.go
blob: 501fb20e2123ca4463cebde60f6319cd2dc1f27b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package main

import (
	"path/filepath"
	"strings"
)

func processSysrootFlag(builder *commandBuilder) {
	fromUser := false
	for _, arg := range builder.args {
		if arg.fromUser && strings.HasPrefix(arg.value, "--sysroot=") {
			fromUser = true
			break
		}
	}
	sysroot, syrootPresent := builder.env.getenv("SYSROOT")
	if syrootPresent {
		builder.updateEnv("SYSROOT=")
	}
	if sysroot == "" {
		// Use the bundled sysroot by default.
		sysroot = filepath.Join(builder.rootPath, "usr", builder.target.target)
	}
	if !fromUser {
		builder.addPreUserArgs("--sysroot=" + sysroot)
	}
}