func TestReader(t *testing.T) { fake, cleanup := jiritest.NewFakeJiriRoot(t) defer cleanup() rd, err := profilesreader.NewReader(fake.X, profilesreader.UseProfiles, filepath.Join("testdata", "m2.xml")) if err != nil { t.Fatal(err) } rd.Vars = envvar.VarsFromOS() rd.Delete("CGO_CFLAGS") native, err := profiles.NewTarget("amd64-darwin", "") if err != nil { t.Fatal(err) } rd.MergeEnvFromProfiles(profilesreader.JiriMergePolicies(), native, "test::go", "test::syncbase") if got, want := rd.Get("CGO_CFLAGS"), "-IX -IY -IA -IB"; got != want { t.Errorf("got %v, want %v", got, want) } if got, want := rd.DebugString(), "Root: "+fake.X.Root+` Path: testdata/m2.xml test:go: [email protected] dir: --env= envvars:[CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin GOROOT=/goroot CGO_CFLAGS=-IX -IY] test:syncbase: amd64-darwin@1 dir: --env= envvars:[CGO_CFLAGS=-IA -IB CGO_LDFLAGS=-LA -LB] `; got != want { t.Errorf("got %v, want %v", got, want) } }
// RegisterReaderFlags registers the 'reader' flags (see below) // with the parent command. The values of the flags can be accessed via // the supplied ReaderFlagValues struct. // The reader flags are: // --skip-profiles // --profiles-db // --profiles // --merge-policies // --target and --env func RegisterReaderFlags(flags *flag.FlagSet, fv *ReaderFlagValues, defaultProfiles, defaultDBPath string) { flags.Var(&fv.ProfilesMode, "skip-profiles", "if set, no profiles will be used") RegisterDBPathFlag(flags, &fv.DBFilename, defaultDBPath) RegisterProfilesFlag(flags, defaultProfiles, &fv.Profiles) fv.MergePolicies = profilesreader.JiriMergePolicies() RegisterMergePoliciesFlag(flags, &fv.MergePolicies) profiles.RegisterTargetAndEnvFlags(flags, &fv.Target) }
func newReaderFlags() *ReaderFlagValues { return &ReaderFlagValues{MergePolicies: profilesreader.JiriMergePolicies()} }