aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/sysroot_flag_test.go
blob: 1c757276381d26a3cd3c27f0f4d3aacc44297871 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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"
	"testing"
)

func TestOmitSysrootGivenUserDefinedSysroot(t *testing.T) {
	withTestContext(t, func(ctx *testContext) {
		runWithCompiler := func(compiler string) {
			cmd := ctx.must(callCompiler(ctx, ctx.cfg,
				ctx.newCommand(compiler, "--sysroot=/somepath", mainCc)))
			if err := verifyArgOrder(cmd, "--sysroot=/somepath", mainCc); err != nil {
				t.Error(err)
			}
			if err := verifyArgCount(cmd, 1, "--sysroot.*"); err != nil {
				t.Error(err)
			}
		}

		runWithCompiler(gccX86_64)
		runWithCompiler(clangX86_64)
	})
}

func TestSetSysrootFlagFromEnv(t *testing.T) {
	withTestContext(t, func(ctx *testContext) {
		ctx.env = []string{"SYSROOT=/envpath"}
		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
			ctx.newCommand(gccX86_64, mainCc)))
		if err := verifyArgOrder(cmd, "--sysroot=/envpath", mainCc); err != nil {
			t.Error(err)
		}
	})
}

func TestSetSysrootRelativeToWrapperPath(t *testing.T) {
	withTestContext(t, func(ctx *testContext) {
		ctx.cfg.rootRelPath = "somepath"
		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
			ctx.newCommand(gccX86_64, mainCc)))
		if err := verifyArgOrder(cmd,
			"--sysroot="+ctx.tempDir+"/somepath/usr/x86_64-cros-linux-gnu", mainCc); err != nil {
			t.Error(err)
		}
	})
}

func TestSetSysrootRelativeToSymlinkedWrapperPath(t *testing.T) {
	withTestContext(t, func(ctx *testContext) {
		ctx.cfg.rootRelPath = "somepath"
		linkedWrapperPath := path.Join(ctx.tempDir, "a/linked/path/x86_64-cros-linux-gnu-gcc")
		ctx.symlink(path.Join(ctx.tempDir, gccX86_64), linkedWrapperPath)

		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
			ctx.newCommand(linkedWrapperPath, mainCc)))
		if err := verifyArgOrder(cmd,
			"--sysroot="+ctx.tempDir+"/somepath/usr/x86_64-cros-linux-gnu", mainCc); err != nil {
			t.Error(err)
		}
	})
}