How to use getGoArch method of install Package

Best Gauge code snippet using install.getGoArch

make.go

Source:make.go Github

copy

Full Screen

1/*----------------------------------------------------------------2 * Copyright (c) ThoughtWorks, Inc.3 * Licensed under the Apache License, Version 2.04 * See LICENSE in the project root for license information.5 *----------------------------------------------------------------*/6package main7import (8 "encoding/json"9 "flag"10 "fmt"11 "io"12 "io/ioutil"13 "log"14 "os"15 "os/exec"16 "path/filepath"17 "runtime"18 "strings"19)20const (21 CGO_ENABLED = "CGO_ENABLED"22)23const (24 dotGauge = ".gauge"25 plugins = "plugins"26 distros = "distros"27 GOARCH = "GOARCH"28 GOOS = "GOOS"29 X86 = "386"30 X86_64 = "amd64"31 DARWIN = "darwin"32 LINUX = "linux"33 WINDOWS = "windows"34 bin = "bin"35 newDirPermissions = 075536 gauge = "gauge"37 spectacle = "spectacle"38 pluginJsonFile = "plugin.json"39)40func main() {41 flag.Parse()42 if *install {43 updatePluginInstallPrefix()44 installPlugin(*pluginInstallPrefix)45 } else if *distro {46 createPluginDistro(*allPlatforms)47 } else {48 compile()49 }50}51func compile() {52 if *allPlatforms {53 compileAcrossPlatforms()54 } else {55 compileGoPackage(spectacle)56 }57}58func createPluginDistro(forAllPlatforms bool) {59 if forAllPlatforms {60 for _, platformEnv := range platformEnvs {61 setEnv(platformEnv)62 *binDir = filepath.Join(bin, fmt.Sprintf("%s_%s", platformEnv[GOOS], platformEnv[GOARCH]))63 fmt.Printf("Creating distro for platform => OS:%s ARCH:%s \n", platformEnv[GOOS], platformEnv[GOARCH])64 createDistro()65 }66 } else {67 createDistro()68 }69 log.Printf("Distributables created in directory => %s \n", bin)70}71func createDistro() {72 packageName := fmt.Sprintf("%s-%s-%s.%s", spectacle, getPluginVersion(), getGOOS(), getArch())73 mirrorFile(pluginJsonFile, filepath.Join(getBinDir(), pluginJsonFile))74 os.Mkdir(filepath.Join(bin, distros), 0755)75 createZipFromUtil(getBinDir(), packageName)76}77func createZipFromUtil(dir, name string) {78 wd, err := os.Getwd()79 if err != nil {80 panic(err)81 }82 os.Chdir(dir)83 output, err := executeCommand("zip", "-r", filepath.Join("..", distros, name+".zip"), ".")84 fmt.Println(output)85 if err != nil {86 panic(fmt.Sprintf("Failed to zip: %s", err))87 }88 os.Chdir(wd)89}90func isExecMode(mode os.FileMode) bool {91 return (mode & 0111) != 092}93func mirrorFile(src, dst string) error {94 sfi, err := os.Stat(src)95 if err != nil {96 return err97 }98 if sfi.Mode()&os.ModeType != 0 {99 log.Fatalf("mirrorFile can't deal with non-regular file %s", src)100 }101 dfi, err := os.Stat(dst)102 if err == nil &&103 isExecMode(sfi.Mode()) == isExecMode(dfi.Mode()) &&104 (dfi.Mode()&os.ModeType == 0) &&105 dfi.Size() == sfi.Size() &&106 dfi.ModTime().Unix() == sfi.ModTime().Unix() {107 // Seems to not be modified.108 return nil109 }110 dstDir := filepath.Dir(dst)111 if err := os.MkdirAll(dstDir, newDirPermissions); err != nil {112 return err113 }114 df, err := os.Create(dst)115 if err != nil {116 return err117 }118 sf, err := os.Open(src)119 if err != nil {120 return err121 }122 defer sf.Close()123 n, err := io.Copy(df, sf)124 if err == nil && n != sfi.Size() {125 err = fmt.Errorf("copied wrong size for %s -> %s: copied %d; want %d", src, dst, n, sfi.Size())126 }127 cerr := df.Close()128 if err == nil {129 err = cerr130 }131 if err == nil {132 err = os.Chmod(dst, sfi.Mode())133 }134 if err == nil {135 err = os.Chtimes(dst, sfi.ModTime(), sfi.ModTime())136 }137 return err138}139func mirrorDir(src, dst string) error {140 log.Printf("Copying '%s' -> '%s'\n", src, dst)141 err := filepath.Walk(src, func(path string, fi os.FileInfo, err error) error {142 if err != nil {143 return err144 }145 if fi.IsDir() {146 return nil147 }148 suffix, err := filepath.Rel(src, path)149 if err != nil {150 return fmt.Errorf("Failed to find Rel(%q, %q): %v", src, path, err)151 }152 return mirrorFile(path, filepath.Join(dst, suffix))153 })154 return err155}156func runProcess(command string, arg ...string) {157 cmd := exec.Command(command, arg...)158 cmd.Stdout = os.Stdout159 cmd.Stderr = os.Stderr160 log.Printf("Execute %v\n", cmd.Args)161 err := cmd.Run()162 if err != nil {163 panic(err)164 }165}166func executeCommand(command string, arg ...string) (string, error) {167 cmd := exec.Command(command, arg...)168 bytes, err := cmd.Output()169 return strings.TrimSpace(fmt.Sprintf("%s", bytes)), err170}171func compileGoPackage(packageName string) {172 runProcess("go", "build", "-o", getGaugeExecutablePath(spectacle))173}174func getGaugeExecutablePath(file string) string {175 return filepath.Join(getBinDir(), getExecutableName(file))176}177func getExecutableName(file string) string {178 if getGOOS() == "windows" {179 return file + ".exe"180 }181 return file182}183func getBinDir() string {184 if *binDir != "" {185 return *binDir186 }187 return filepath.Join(bin, fmt.Sprintf("%s_%s", getGOOS(), getGOARCH()))188}189func getPluginVersion() string {190 pluginProperties, err := getPluginProperties(pluginJsonFile)191 if err != nil {192 panic(fmt.Sprintf("Failed to get properties file. %s", err))193 }194 return pluginProperties["version"].(string)195}196func setEnv(envVariables map[string]string) {197 for k, v := range envVariables {198 os.Setenv(k, v)199 }200}201var install = flag.Bool("install", false, "Install to the specified prefix")202var pluginInstallPrefix = flag.String("plugin-prefix", "", "Specifies the prefix where the plugin will be installed")203var distro = flag.Bool("distro", false, "Creates distributables for the plugin")204var allPlatforms = flag.Bool("all-platforms", false, "Compiles or creates distributables for all platforms windows, linux, darwin both x86 and x86_64")205var binDir = flag.String("bin-dir", "", "Specifies OS_PLATFORM specific binaries to install when cross compiling")206var (207 platformEnvs = []map[string]string{208 map[string]string{GOARCH: X86, GOOS: DARWIN, CGO_ENABLED: "0"},209 map[string]string{GOARCH: X86_64, GOOS: DARWIN, CGO_ENABLED: "0"},210 map[string]string{GOARCH: X86, GOOS: LINUX, CGO_ENABLED: "0"},211 map[string]string{GOARCH: X86_64, GOOS: LINUX, CGO_ENABLED: "0"},212 map[string]string{GOARCH: X86, GOOS: WINDOWS, CGO_ENABLED: "0"},213 map[string]string{GOARCH: X86_64, GOOS: WINDOWS, CGO_ENABLED: "0"},214 }215)216func getPluginProperties(jsonPropertiesFile string) (map[string]interface{}, error) {217 pluginPropertiesJson, err := ioutil.ReadFile(jsonPropertiesFile)218 if err != nil {219 fmt.Printf("Could not read %s: %s\n", filepath.Base(jsonPropertiesFile), err)220 return nil, err221 }222 var pluginJson interface{}223 if err = json.Unmarshal([]byte(pluginPropertiesJson), &pluginJson); err != nil {224 fmt.Printf("Could not read %s: %s\n", filepath.Base(jsonPropertiesFile), err)225 return nil, err226 }227 return pluginJson.(map[string]interface{}), nil228}229func compileAcrossPlatforms() {230 for _, platformEnv := range platformEnvs {231 setEnv(platformEnv)232 fmt.Printf("Compiling for platform => OS:%s ARCH:%s \n", platformEnv[GOOS], platformEnv[GOARCH])233 compileGoPackage(spectacle)234 }235}236func installPlugin(installPrefix string) {237 pluginInstallPath := filepath.Join(installPrefix, spectacle, getPluginVersion())238 mirrorDir(getBinDir(), pluginInstallPath)239 mirrorFile(pluginJsonFile, filepath.Join(pluginInstallPath, pluginJsonFile))240}241func updatePluginInstallPrefix() {242 if *pluginInstallPrefix == "" {243 if runtime.GOOS == "windows" {244 *pluginInstallPrefix = os.Getenv("APPDATA")245 if *pluginInstallPrefix == "" {246 panic(fmt.Errorf("Failed to find AppData directory"))247 }248 *pluginInstallPrefix = filepath.Join(*pluginInstallPrefix, gauge, plugins)249 } else {250 userHome := getUserHome()251 if userHome == "" {252 panic(fmt.Errorf("Failed to find User Home directory"))253 }254 *pluginInstallPrefix = filepath.Join(userHome, dotGauge, plugins)255 }256 }257}258func getUserHome() string {259 return os.Getenv("HOME")260}261func getArch() string {262 arch := getGOARCH()263 if arch == X86 {264 return "x86"265 }266 return "x86_64"267}268func getGOARCH() string {269 goArch := os.Getenv(GOARCH)270 if goArch == "" {271 return runtime.GOARCH272 }273 return goArch274}275func getGOOS() string {276 os := os.Getenv(GOOS)277 if os == "" {278 return runtime.GOOS279 }280 return os281}...

Full Screen

Full Screen

buildSo.go

Source:buildSo.go Github

copy

Full Screen

1package udwGoBuild2import (3 "fmt"4 "github.com/tachyon-protocol/udw/udwProfile/udwProfileDelay"5 "github.com/tachyon-protocol/udw/udwStrings"6 "path/filepath"7 "strings"8)9func (p *programV2) BuildSoFile() {10 if !p.MustIsTargetExist() {11 panic(fmt.Errorf("[BuildSoFile] target not exist target:[%s]", p.targetPackagePathOrFilePath))12 }13 pkgName := p.GetGoos() + "_" + p.GetGoArch() + "_shared"14 pkgPath := filepath.Join(p.ctx.GetFirstGoPathString(), "pkg", pkgName)15 installBinPath := p.ctx.GetGoInstallOutputExeFilePath()16 slice := udwStrings.StringSliceMerge("go", "build", "-buildmode=c-shared", "-i", "-pkgdir", pkgPath,17 p.getBuildFlagCmdSlice(), "-o="+installBinPath, p.targetPackagePathOrFilePath)18 p.mustUdwGoInstall(slice)19}20func (p *programV2) BuildIosAFile() {21 if !p.MustIsTargetExist() {22 panic(fmt.Errorf("[BuildIosAFile] target not exist target:[%s]", p.targetPackagePathOrFilePath))23 }24 pkgName := p.GetGoos() + "_" + p.GetGoArch()25 if len(p.buildTagList) > 0 {26 pkgName += "_" + strings.Join(p.buildTagList, "_")27 }28 pkgPath := filepath.Join(p.gopathList[0], "pkg", pkgName)29 installBinPath := p.ctx.GetGoInstallOutputExeFilePath()30 udwProfileDelay.P()31 p.mustUdwGoInstall(udwStrings.StringSliceMerge("go", "build", "-buildmode=c-archive",32 p.getBuildFlagCmdSlice(), "-i", "-pkgdir", pkgPath,33 "-o="+installBinPath, p.targetPackagePathOrFilePath))34 udwProfileDelay.P()35}36func (p *programV2) BuildWindowsNoConsoleExe() {37 p.SetLdflags("-H=windowsgui -s -w")38 if !p.MustIsTargetExist() {39 panic("[BuildWindowsNoConsoleExe] target not exist target:[" + p.targetPackagePathOrFilePath + "]")40 }41 pkgPath := filepath.Join(p.gopathList[0], "pkg", p.GetGoos()+"_"+p.GetGoArch()+"_windowsgui")42 installBinPath := p.ctx.GetGoInstallOutputExeFilePath()43 p.mustUdwGoInstall(udwStrings.StringSliceMerge("go", "build",44 p.getBuildFlagCmdSlice(), "-pkgdir", pkgPath, "-o="+installBinPath, p.targetPackagePathOrFilePath))45}...

Full Screen

Full Screen

getGoArch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Goarch is: ", install.GetGoArch())4}5import (6func GetGoArch() string {7}8When we run the above program, it prints the GOARCH of the system where it is executed. In the above program, we have used the GetGoArch method of install package. This method is defined in install.go file. The install.go file is in the install directory. This directory is in the same directory as the 1.go file. So, in order to use the GetGoArch method, we have to import the install package. The import statement is given below:9import "install"

Full Screen

Full Screen

getGoArch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 bus := gobus.NewBus()4 install := bus.CreateClass("install")5 install.RegisterMethod("getGoArch", func() string {6 })7 obj := bus.NewObject("install", "install")8 arch, err := obj.Call("getGoArch")9 if err != nil {10 panic(err)11 }12 fmt.Println("GOARCH:", arch)13}14import (15func main() {16 bus := gobus.NewBus()17 install := bus.CreateClass("install")18 install.RegisterMethod("getGoArch", func() string {19 })20 obj := bus.NewObject("install", "install")21 arch, err := obj.Call("getGoArch")22 if err != nil {23 panic(err)24 }25 fmt.Println("GOARCH:", arch)26}27import (28func main() {29 bus := gobus.NewBus()30 install := bus.CreateClass("install")31 install.RegisterMethod("getGoArch", func() string {32 })33 obj := bus.NewObject("install", "install")34 arch, err := obj.Call("getGoArch")35 if err != nil {36 panic(err)37 }38 fmt.Println("GOARCH:", arch)39}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful