<commit_before>// Copyright 2015-2017 the u-root 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 (
	"flag"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"
	"strings"
)

func getenv(e, d string) string {
	v := os.Getenv(e)
	if v == "" {
		v = d
	}
	return v
}

// TODO: put this in the uroot package
// It's annoying asking them to set lots of things. So let's try to figure it out.
func guessgoroot() {
	config.Goroot = os.Getenv("GOROOT")
	if config.Goroot != "" {
		log.Printf("Using %v as GOROOT from environment variable", config.Goroot)
		config.Gosrcroot = filepath.Dir(config.Goroot)
		return
	}
	log.Print("Goroot is not set, trying to find a go binary")
	p := os.Getenv("PATH")
	paths := strings.Split(p, ":")
	for _, v := range paths {
		g := filepath.Join(v, "go")
		if _, err := os.Stat(g); err == nil {
			config.Goroot = filepath.Dir(filepath.Dir(v))
			config.Gosrcroot = filepath.Dir(config.Goroot)
			log.Printf("Guessing that goroot is %v", config.Goroot)
			return
		}
	}
	log.Printf("GOROOT is not set and can't find a go binary in %v", p)
	config.Fail = true
}

func guessgopath() {
	defer func() {
		config.Gosrcroot = filepath.Dir(config.Goroot)
	}()
	gopath := os.Getenv("GOPATH")
	if gopath != "" {
		config.Gopath = filepath.Clean(gopath)<commit_msg>uroot/root.go: modify/extend it for more complex roots<commit_after>// Copyright 2015-2017 the u-root 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 (
	"flag"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"
	"strings"
)

func getenv(e, d string) string {
	v := os.Getenv(e)
	if v == "" {
		v = d
	}
	return v
}

// TODO: put this in the uroot package
// It's annoying asking them to set lots of things. So let's try to figure it out.
func guessgoroot() {
	config.Goroot = os.Getenv("GOROOT")
	if config.Goroot != "" {
		log.Printf("Using %v as GOROOT from environment variable", config.Goroot)
		config.Gosrcroot = filepath.Dir(config.Goroot)
		return
	}
	log.Print("Goroot is not set, trying to find a go binary")
	p := os.Getenv("PATH")
	paths := strings.Split(p, ":")
	for _, v := range paths {
		g := filepath.Join(v, "go")
		if _, err := os.Stat(g); err == nil {
			config.Goroot = filepath.Dir(filepath.Dir(v))
			config.Gosrcroot = filepath.Dir(config.Goroot)
			log.Printf("Guessing that goroot is %v", config.Goroot)
			return
		}
	}
	log.Printf("GOROOT is not set and can't find a go binary in %v", p)
	config.Fail = true
}

func guessgopath() {
	defer func() {
		config.Gosrcroot = filepath.Dir(config.Goroot)
	}()
	var gopath string
	config.Gopaths = strings.Split(getenv("GOPATH", ""), ":")
	if len(config.Gopaths) > 0 {
		gopath = config.Gopaths[0]
	}
	if gopath != "" {
		config.Gopath = filepath.Clean(gopath)
{'fraction_non_alphanumeric': 0.14418444597384722, 'fraction_numerical': 0.006194081211286993, 'mean_word_length': 3.486111111111111, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5643113', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1108, 'n_words': 321}