Ver Fonte

remove old build code

Darien Raymond há 8 anos atrás
pai
commit
b17f89cf57

+ 0 - 59
tools/build/archive.go

@@ -1,59 +0,0 @@
-package main
-
-import (
-	"archive/zip"
-	"io"
-	"os"
-	"path/filepath"
-)
-
-type ZipWorker struct {
-	zipWriter *zip.Writer
-	root      string
-}
-
-func NewZipWorker(zipFile io.Writer, root string) *ZipWorker {
-	return &ZipWorker{
-		zipWriter: zip.NewWriter(zipFile),
-		root:      root,
-	}
-}
-
-func (worker *ZipWorker) run() error {
-	defer worker.close()
-	return filepath.Walk(worker.root, worker.zipAllFiles)
-}
-
-func (worker *ZipWorker) zipAllFiles(path string, info os.FileInfo, err error) error {
-	if info.IsDir() {
-		return nil
-	}
-	fileWriter, err := worker.zipWriter.Create(path)
-	if err != nil {
-		return err
-	}
-	fileReader, err := os.Open(path)
-	if err != nil {
-		return err
-	}
-	_, err = io.Copy(fileWriter, fileReader)
-	return err
-}
-
-func (worker *ZipWorker) close() {
-	worker.zipWriter.Close()
-}
-
-func zipFolder(folder string, file string) error {
-	if _, err := os.Stat(file); err == nil {
-		os.Remove(file)
-	}
-
-	zipFile, err := os.Create(file)
-	if err != nil {
-		return err
-	}
-	defer zipFile.Close()
-
-	return NewZipWorker(zipFile, folder).run()
-}

+ 0 - 127
tools/build/build.go

@@ -1,127 +0,0 @@
-package main
-
-import (
-	"flag"
-	"fmt"
-	"os"
-	"path/filepath"
-	"runtime"
-)
-
-var (
-	flagTargetDir    = flag.String("dir", "", "Directory to put generated files.")
-	flagTargetOS     = flag.String("os", runtime.GOOS, "Target OS of this build.")
-	flagTargetArch   = flag.String("arch", runtime.GOARCH, "Target CPU arch of this build.")
-	flagArchive      = flag.Bool("zip", false, "Whether to make an archive of files or not.")
-	flagMetadataFile = flag.String("metadata", "metadata.txt", "File to store metadata info of released packages.")
-	flagSignBinary   = flag.Bool("sign", false, "Whether or not to sign the binaries.")
-
-	binPath string
-)
-
-func createTargetDirectory(version string, goOS GoOS, goArch GoArch) (string, error) {
-	var targetDir string
-	if len(*flagTargetDir) > 0 {
-		targetDir = *flagTargetDir
-	} else {
-		suffix := getSuffix(goOS, goArch)
-
-		targetDir = filepath.Join(binPath, "v2ray-"+version+suffix)
-		if version != "custom" {
-			os.RemoveAll(targetDir)
-		}
-	}
-
-	err := os.MkdirAll(targetDir, os.ModeDir|0777)
-	return targetDir, err
-}
-
-func getTargetFile(goOS GoOS) string {
-	suffix := ""
-	if goOS == Windows {
-		suffix += ".exe"
-	}
-	return "v2ray" + suffix
-}
-
-func getBinPath() string {
-	GOPATH := os.Getenv("GOPATH")
-	return filepath.Join(GOPATH, "bin")
-}
-
-func main() {
-	flag.Parse()
-	binPath = getBinPath()
-	build(*flagTargetOS, *flagTargetArch, *flagArchive, "", *flagMetadataFile)
-}
-
-func build(targetOS, targetArch string, archive bool, version string, metadataFile string) {
-	v2rayOS := parseOS(targetOS)
-	v2rayArch := parseArch(targetArch)
-
-	if len(version) == 0 {
-		version = os.Getenv("TRAVIS_TAG")
-	}
-
-	if len(version) == 0 {
-		version = "custom"
-	}
-
-	fmt.Printf("Building V2Ray (%s) for %s %s\n", version, v2rayOS, v2rayArch)
-
-	targetDir, err := createTargetDirectory(version, v2rayOS, v2rayArch)
-	if err != nil {
-		fmt.Println("Unable to create directory " + targetDir + ": " + err.Error())
-	}
-
-	targetFile := getTargetFile(v2rayOS)
-	targetFileFull := filepath.Join(targetDir, targetFile)
-	if err := buildV2Ray(targetFileFull, version, v2rayOS, v2rayArch, ""); err != nil {
-		fmt.Println("Unable to build V2Ray: " + err.Error())
-	}
-	if v2rayOS == Windows {
-		if err := buildV2Ray(filepath.Join(targetDir, "w"+targetFile), version, v2rayOS, v2rayArch, "-H windowsgui"); err != nil {
-			fmt.Println("Unable to build V2Ray no console: " + err.Error())
-		}
-	}
-
-	if *flagSignBinary {
-		if err := signFile(targetFileFull); err != nil {
-			fmt.Println("Unable to sign V2Ray binary: " + err.Error())
-		}
-
-		if v2rayOS == Windows {
-			if err := signFile(filepath.Join(targetDir, "w"+targetFile)); err != nil {
-				fmt.Println("Unable to sign V2Ray no console: " + err.Error())
-			}
-		}
-	}
-
-	if err := copyConfigFiles(targetDir, v2rayOS); err != nil {
-		fmt.Println("Unable to copy config files: " + err.Error())
-	}
-
-	if archive {
-		if err := os.Chdir(binPath); err != nil {
-			fmt.Printf("Unable to switch to directory (%s): %v\n", binPath, err)
-		}
-		suffix := getSuffix(v2rayOS, v2rayArch)
-		zipFile := "v2ray" + suffix + ".zip"
-		root := filepath.Base(targetDir)
-		err = zipFolder(root, zipFile)
-		if err != nil {
-			fmt.Printf("Unable to create archive (%s): %v\n", zipFile, err)
-		}
-
-		metadataWriter, err := os.OpenFile(filepath.Join(binPath, metadataFile), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
-		if err != nil {
-			fmt.Printf("Unable to create metadata file (%s): %v\n", metadataFile, err)
-		}
-		defer metadataWriter.Close()
-
-		err = CalcMetadata(zipFile, metadataWriter)
-		if err != nil {
-			fmt.Printf("Failed to calculate metadata for file (%s): %v", zipFile, err)
-		}
-	}
-}

+ 0 - 57
tools/build/build_test.go

@@ -1,57 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"io/ioutil"
-	"os"
-	"path/filepath"
-	"testing"
-
-	"v2ray.com/core/testing/assert"
-)
-
-func fileExists(file string) bool {
-	_, err := os.Stat(file)
-	return err == nil
-}
-
-func allFilesExists(files ...string) bool {
-	for _, file := range files {
-		fullPath := filepath.Join(binPath, file)
-		if !fileExists(fullPath) {
-			fmt.Println(fullPath + " doesn't exist.")
-			return false
-		}
-	}
-	return true
-}
-
-func TestBuildMacOS(t *testing.T) {
-	assert := assert.On(t)
-	tmpPath, err := ioutil.TempDir("", "v2ray")
-	assert.Error(err).IsNil()
-
-	binPath = tmpPath
-
-	build("macos", "amd64", true, "test", "metadata.txt")
-	assert.Bool(allFilesExists(
-		"v2ray-macos.zip",
-		"v2ray-test-macos",
-		filepath.Join("v2ray-test-macos", "config.json"),
-		filepath.Join("v2ray-test-macos", "v2ray"))).IsTrue()
-
-	build("windows", "amd64", true, "test", "metadata.txt")
-	assert.Bool(allFilesExists(
-		"v2ray-windows-64.zip",
-		"v2ray-test-windows-64",
-		filepath.Join("v2ray-test-windows-64", "config.json"),
-		filepath.Join("v2ray-test-windows-64", "v2ray.exe"))).IsTrue()
-
-	build("linux", "amd64", true, "test", "metadata.txt")
-	assert.Bool(allFilesExists(
-		"v2ray-linux-64.zip",
-		"v2ray-test-linux-64",
-		filepath.Join("v2ray-test-linux-64", "vpoint_socks_vmess.json"),
-		filepath.Join("v2ray-test-linux-64", "vpoint_vmess_freedom.json"),
-		filepath.Join("v2ray-test-linux-64", "v2ray"))).IsTrue()
-}

+ 0 - 81
tools/build/config.go

@@ -1,81 +0,0 @@
-package main
-
-import (
-	"io/ioutil"
-	"os"
-	"path/filepath"
-	"strings"
-)
-
-func copyConfigFile(src, dest string, goOS GoOS, format bool) error {
-	content, err := ioutil.ReadFile(src)
-	if err != nil {
-		return err
-	}
-	if format {
-		str := string(content)
-		str = strings.Replace(str, "\r\n", "\n", -1)
-		if goOS == Windows {
-			str = strings.Replace(str, "\n", "\r\n", -1)
-		}
-		content = []byte(str)
-	}
-	return ioutil.WriteFile(dest, content, 0777)
-}
-
-func copyConfigFiles(dir string, goOS GoOS) error {
-	GOPATH := os.Getenv("GOPATH")
-	srcDir := filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "config")
-	src := filepath.Join(srcDir, "vpoint_socks_vmess.json")
-	dest := filepath.Join(dir, "vpoint_socks_vmess.json")
-	if goOS == Windows || goOS == MacOS {
-		dest = filepath.Join(dir, "config.json")
-	}
-	if err := copyConfigFile(src, dest, goOS, true); err != nil {
-		return err
-	}
-
-	src = filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "doc", "readme.md")
-	dest = filepath.Join(dir, "readme.md")
-
-	if err := copyConfigFile(src, dest, goOS, true); err != nil {
-		return err
-	}
-
-	if goOS == Windows || goOS == MacOS {
-		return nil
-	}
-
-	src = filepath.Join(srcDir, "vpoint_vmess_freedom.json")
-	dest = filepath.Join(dir, "vpoint_vmess_freedom.json")
-
-	if err := copyConfigFile(src, dest, goOS, true); err != nil {
-		return err
-	}
-
-	if err := copyConfigFile(src, dest, goOS, true); err != nil {
-		return err
-	}
-
-	if goOS == Linux {
-		if err := os.MkdirAll(filepath.Join(dir, "systemv"), os.ModeDir|0777); err != nil {
-			return err
-		}
-		src = filepath.Join(srcDir, "systemv", "v2ray")
-		dest = filepath.Join(dir, "systemv", "v2ray")
-		if err := copyConfigFile(src, dest, goOS, false); err != nil {
-			return err
-		}
-
-		if err := os.MkdirAll(filepath.Join(dir, "systemd"), os.ModeDir|0777); err != nil {
-			return err
-		}
-		src = filepath.Join(srcDir, "systemd", "v2ray.service")
-		dest = filepath.Join(dir, "systemd", "v2ray.service")
-		if err := copyConfigFile(src, dest, goOS, false); err != nil {
-			return err
-		}
-	}
-
-	return nil
-}

+ 0 - 124
tools/build/env.go

@@ -1,124 +0,0 @@
-package main
-
-import (
-	"strings"
-)
-
-type GoOS string
-
-const (
-	Windows   = GoOS("windows")
-	MacOS     = GoOS("darwin")
-	Linux     = GoOS("linux")
-	FreeBSD   = GoOS("freebsd")
-	OpenBSD   = GoOS("openbsd")
-	UnknownOS = GoOS("unknown")
-)
-
-type GoArch string
-
-const (
-	X86         = GoArch("386")
-	Amd64       = GoArch("amd64")
-	Arm         = GoArch("arm")
-	Arm64       = GoArch("arm64")
-	Mips64      = GoArch("mips64")
-	Mips64LE    = GoArch("mips64le")
-	Mips        = GoArch("mips")
-	MipsLE      = GoArch("mipsle")
-	UnknownArch = GoArch("unknown")
-)
-
-func parseOS(rawOS string) GoOS {
-	osStr := strings.ToLower(rawOS)
-	switch osStr {
-	case "windows", "win":
-		return Windows
-	case "darwin", "mac", "macos", "osx":
-		return MacOS
-	case "linux", "debian", "ubuntu", "redhat", "centos":
-		return Linux
-	case "freebsd":
-		return FreeBSD
-	case "openbsd":
-		return OpenBSD
-	default:
-		return UnknownOS
-	}
-}
-
-func parseArch(rawArch string) GoArch {
-	archStr := strings.ToLower(rawArch)
-	switch archStr {
-	case "x86", "386", "i386":
-		return X86
-	case "amd64", "x86-64", "x64":
-		return Amd64
-	case "arm":
-		return Arm
-	case "arm64":
-		return Arm64
-	case "mips":
-		return Mips
-	case "mipsle":
-		return MipsLE
-	case "mips64":
-		return Mips64
-	case "mips64le":
-		return Mips64LE
-	default:
-		return UnknownArch
-	}
-}
-
-func getSuffix(os GoOS, arch GoArch) string {
-	suffix := "-custom"
-	switch os {
-	case Windows:
-		switch arch {
-		case X86:
-			suffix = "-windows-32"
-		case Amd64:
-			suffix = "-windows-64"
-		}
-	case MacOS:
-		suffix = "-macos"
-	case Linux:
-		switch arch {
-		case X86:
-			suffix = "-linux-32"
-		case Amd64:
-			suffix = "-linux-64"
-		case Arm:
-			suffix = "-linux-arm"
-		case Arm64:
-			suffix = "-linux-arm64"
-		case Mips64:
-			suffix = "-linux-mips64"
-		case Mips64LE:
-			suffix = "-linux-mips64le"
-		case Mips:
-			suffix = "-linux-mips"
-		case MipsLE:
-			suffix = "-linux-mipsle"
-		}
-	case FreeBSD:
-		switch arch {
-		case X86:
-			suffix = "-freebsd-32"
-		case Amd64:
-			suffix = "-freebsd-64"
-		case Arm:
-			suffix = "-freebsd-arm"
-		}
-	case OpenBSD:
-		switch arch {
-		case X86:
-			suffix = "-openbsd-32"
-		case Amd64:
-			suffix = "-openbsd-64"
-		}
-	}
-
-	return suffix
-}

+ 0 - 26
tools/build/env_test.go

@@ -1,26 +0,0 @@
-package main
-
-import (
-	"testing"
-
-	"v2ray.com/core/testing/assert"
-)
-
-func TestParseOS(t *testing.T) {
-	assert := assert.On(t)
-
-	assert.Pointer(parseOS("windows")).Equals(Windows)
-	assert.Pointer(parseOS("macos")).Equals(MacOS)
-	assert.Pointer(parseOS("linux")).Equals(Linux)
-	assert.Pointer(parseOS("test")).Equals(UnknownOS)
-}
-
-func TestParseArch(t *testing.T) {
-	assert := assert.On(t)
-
-	assert.Pointer(parseArch("x86")).Equals(X86)
-	assert.Pointer(parseArch("x64")).Equals(Amd64)
-	assert.Pointer(parseArch("arm")).Equals(Arm)
-	assert.Pointer(parseArch("arm64")).Equals(Arm64)
-	assert.Pointer(parseArch("test")).Equals(UnknownArch)
-}

+ 0 - 51
tools/build/go.go

@@ -1,51 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"os"
-	"os/exec"
-	"time"
-)
-
-func buildV2Ray(targetFile string, version string, goOS GoOS, goArch GoArch, extraLdFlags string) error {
-	goPath := os.Getenv("GOPATH")
-	ldFlags := "-s " + extraLdFlags
-	if version != "custom" {
-		year, month, day := time.Now().UTC().Date()
-		today := fmt.Sprintf("%04d%02d%02d", year, int(month), day)
-		ldFlags = ldFlags + " -X v2ray.com/core.version=" + version + " -X v2ray.com/core.build=" + today
-
-		bUser := os.Getenv("V_USER")
-		if len(bUser) > 0 {
-			ldFlags += " -X v2ray.com/ext/tools/conf.bUser=" + bUser
-		}
-	}
-
-	cmd := exec.Command(
-		"go", "build",
-		"-tags", "json",
-		"-o", targetFile,
-		"-compiler", "gc",
-		"-ldflags", ldFlags,
-		"-gcflags", "-trimpath="+goPath,
-		"-asmflags", "-trimpath="+goPath,
-		"v2ray.com/core/main")
-	cmd.Env = append(cmd.Env, "GOOS="+string(goOS), "GOARCH="+string(goArch), "CGO_ENABLED=0")
-	cmd.Env = append(cmd.Env, os.Environ()...)
-	output, err := cmd.CombinedOutput()
-	if len(output) > 0 {
-		fmt.Println(string(output))
-	}
-	return err
-}
-
-func signFile(file string) error {
-	pass := os.Getenv("GPG_SIGN_PASS")
-	cmd := exec.Command("gpg", "--digest-algo", "SHA512", "--no-tty", "--batch", "--passphrase", pass, "--output", file+".sig", "--detach-sig", file)
-	cmd.Env = append(cmd.Env, os.Environ()...)
-	output, err := cmd.CombinedOutput()
-	if len(output) > 0 {
-		fmt.Println(string(output))
-	}
-	return err
-}

+ 0 - 47
tools/build/go_test.go

@@ -1,47 +0,0 @@
-package main
-
-import (
-	"bytes"
-	"os"
-	"os/exec"
-	"path/filepath"
-	"runtime"
-	"strings"
-	"testing"
-	"time"
-
-	"v2ray.com/core/testing/assert"
-)
-
-func TestBuildAndRun(t *testing.T) {
-	assert := assert.On(t)
-
-	gopath := os.Getenv("GOPATH")
-	goOS := parseOS(runtime.GOOS)
-	goArch := parseArch(runtime.GOARCH)
-	target := filepath.Join(gopath, "src", "v2ray_test")
-	if goOS == Windows {
-		target += ".exe"
-	}
-	err := buildV2Ray(target, "v1.0", goOS, goArch, "")
-	assert.Error(err).IsNil()
-
-	outBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
-	errBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
-	configFile := filepath.Join(gopath, "src", "github.com", "v2ray", "v2ray-core", "tools", "release", "config", "vpoint_socks_vmess.json")
-	cmd := exec.Command(target, "--config="+configFile)
-	cmd.Stdout = outBuffer
-	cmd.Stderr = errBuffer
-	cmd.Start()
-
-	time.Sleep(1 * time.Second)
-	cmd.Process.Kill()
-
-	outStr := string(outBuffer.Bytes())
-	errStr := string(errBuffer.Bytes())
-
-	assert.Bool(strings.Contains(outStr, "v1.0")).IsTrue()
-	assert.String(errStr).Equals("")
-
-	os.Remove(target)
-}

+ 0 - 31
tools/build/metadata.go

@@ -1,31 +0,0 @@
-package main
-
-import (
-	"crypto/sha1"
-	"encoding/hex"
-	"fmt"
-	"io"
-	"os"
-	"path/filepath"
-)
-
-func CalcMetadata(file string, writer io.Writer) error {
-	fileReader, err := os.Open(file)
-	if err != nil {
-		return err
-	}
-	defer fileReader.Close()
-
-	hasher := sha1.New()
-	nBytes, err := io.Copy(hasher, fileReader)
-	if err != nil {
-		return err
-	}
-	sha1sum := hasher.Sum(nil)
-	filename := filepath.Base(file)
-	fmt.Fprintf(writer, "File: %s\n", filename)
-	fmt.Fprintf(writer, "Size: %d\n", nBytes)
-	fmt.Fprintf(writer, "SHA1: %s\n", hex.EncodeToString(sha1sum))
-	fmt.Fprintln(writer)
-	return nil
-}