Skip to content

Commit 1f13ec3

Browse files
committed
upd
1 parent 2abd6de commit 1f13ec3

File tree

8 files changed

+65
-58
lines changed

8 files changed

+65
-58
lines changed

build.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/env bash
2+
export CGO_ENABLED=0
23

4+
export CGO_ENABLED=0
35
version=$(git describe --long --dirty --abbrev=10 --tags)
46
lf="-X github.com/intel/oneapi-cli/cmd.version=${version}"
57

6-
GOOS=linux GOARCH=amd64 go build -ldflags "$lf" -o linux/bin/oneapi-cli
7-
GOOS=windows GOARCH=amd64 go build -ldflags "$lf" -o win/bin/oneapi-cli.exe
8-
GOOS=darwin GOARCH=amd64 go build -ldflags "$lf" -o osx/bin/oneapi-cli
8+
9+
GOOS=linux GOARCH=amd64 go build -ldflags "$lf" -trimpath -mod=readonly -gcflags="all=-spectre=all -N -l" -asmflags="all=-spectre=all" -ldflags="all=-s -w" -o linux/bin/oneapi-cli
10+
GOOS=windows GOARCH=amd64 go build -ldflags "$lf" -trimpath -mod=readonly -gcflags="all=-spectre=all -N -l" -asmflags="all=-spectre=all" -ldflags="all=-s -w" -o win/bin/oneapi-cli.exe
11+
GOOS=darwin GOARCH=amd64 go build -ldflags "$lf" -trimpath -mod=readonly -gcflags="all=-spectre=all -N -l" -asmflags="all=-spectre=all" -ldflags="all=-s -w" -o osx/bin/oneapi-cli

cmd/check.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
// Copyright 2019 Intel Corporation
22
// SPDX-License-Identifier: BSD-3-Clause
3-
/*
4-
usage:
5-
oneapi-cli check --deps="mkl,tbb"
6-
7-
TODO: --html flag
8-
9-
https://software.intel.com/en-us/oneapi
10-
11-
*/
123

134
package cmd
145

cmd/clean.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"fmt"
78
"os"
89
"path/filepath"
910

@@ -18,6 +19,11 @@ var cleanCmd = &cobra.Command{
1819
Long: `Removes local Sample Cache`,
1920
Run: func(cmd *cobra.Command, args []string) {
2021
os.RemoveAll(filepath.Join(baseFilePath, aggregator.AggregatorLocalAPILevel))
22+
if err := os.RemoveAll(filepath.Join(baseFilePath, aggregator.AggregatorLocalAPILevel)); err != nil {
23+
fmt.Println("Failed to clean sample cache.")
24+
fmt.Printf("%s \n", err)
25+
os.Exit(1)
26+
}
2127
},
2228
}
2329

cmd/root.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@ import (
1515
"github.com/spf13/cobra"
1616
)
1717

18-
//SamplesEndpointDefault default samples endpoint
1918
const SamplesEndpointDefault = "https://iotdk.intel.com/samples-iss"
2019

21-
//2021.1-beta05/
22-
23-
//SampleLatestKey the location from the default path that points to a "latest version"
2420
const SampleLatestKey = "latest"
2521

26-
//LocalStorageDefault the default path root where the local cache is kept
2722
const LocalStorageDefault = ".oneapi-cli"
2823

2924
var baseURL string
@@ -95,7 +90,6 @@ func init() {
9590
}
9691
defaultBaseFilePath := filepath.Join(userHome, LocalStorageDefault)
9792

98-
//rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cmd.yaml)")
9993
rootCmd.PersistentFlags().StringVarP(&baseURL, "url", "u", getVersionInfo(), "URL of remote sample aggregator")
10094
rootCmd.PersistentFlags().StringVarP(&baseFilePath, "directory", "d", defaultBaseFilePath, "location to store local oneapi samples cache")
10195
rootCmd.PersistentFlags().StringSliceVarP(&enabledLanguages, "languages", "l", defaultLanguages, "enabled languages")
@@ -104,16 +98,20 @@ func init() {
10498

10599
}
106100

107-
//looks at the command bin path and looks for "version.txt" which
108-
//points to which sample version to look at. If it cant find it it
109-
//returns the Latestkey const
101+
// looks at the command bin path and looks for "samples-version-tag.txt" which
102+
103+
// points to which sample version to look at. If it cant find it it
104+
// returns the Latestkey const
110105
func getVersionInfo() string {
111106
bin, err := os.Executable()
112107
if err != nil {
113108
return fmt.Sprintf("%s/%s/", SamplesEndpointDefault, SampleLatestKey)
114109
}
115-
versionPath := filepath.Join(filepath.Dir(bin), "version.txt")
116-
110+
bin, err = filepath.EvalSymlinks(bin)
111+
if err != nil {
112+
return fmt.Sprintf("%s/%s/", SamplesEndpointDefault, SampleLatestKey)
113+
}
114+
versionPath := filepath.Join(filepath.Dir(filepath.Dir(bin)), "etc", "samples-version-tag.txt")
117115
file, err := os.Open(versionPath)
118116
if err != nil {
119117
return fmt.Sprintf("%s/%s/", SamplesEndpointDefault, SampleLatestKey)

cmd/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
//Version set during build via `go build -ldflags -X "-X main.Version=version"`
12+
// Version set during build via `go build -ldflags -X "-X main.Version=version"`
1313
var version string
1414

15-
// cleanCmd represents the clean command
15+
// versionCmd represents the version command
1616
var versionCmd = &cobra.Command{
1717
Use: "version",
1818
Short: "Show the CLI version information",

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/mattn/go-ieproxy v0.0.1
88
github.com/spf13/cobra v1.6.1
99
gitlab.com/tslocum/cview v1.4.4
10+
// golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43
1011
golang.org/x/sys v0.13.0
1112
)
1213

pkg/deps/checker.go

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
const (
1818
rootEnvKey = "ONEAPI_ROOT"
1919

20-
baseURL = "https://software.intel.com/en-us/oneapi/"
20+
baseURL = "https://www.intel.com/content/www/us/en/developer/tools/oneapi/overview"
2121

2222
formatStr = `The following tools are needed to build this sample but are not locally installed: (%s)
2323
You may continue and view the sample without the prerequisites. To install the missing prerequisites, visit:
@@ -28,11 +28,10 @@ You may continue and view the sample without the prerequisites. To install the m
2828
compilerReg = "compiler\\|(.*)"
2929
)
3030

31-
//CheckDeps as
31+
// CheckDeps as
3232
func CheckDeps(dependencies []string, root string) (msg string, errCode int) {
3333
//dependencies are both "normal" component dependencies ( ["mkl", "vtune"])
3434
//and "special" dependencies ( ["pkg|mraa", "compiler|icc"])
35-
3635
componentDeps, specialDeps := separatethSheepsGoats(dependencies)
3736

3837
componentMsg, componentErrCode := checkComponentDeps(componentDeps, root)
@@ -145,30 +144,30 @@ func checkCompilerDeps(compilerDeps []string, root string) (msg string, errCode
145144
var missing []string
146145

147146
winCompilers := map[string]string{
148-
"icc": "windows/bin/intel64/icl.exe",
149-
"fortran": "windows/bin/intel64/ifort.exe",
150-
"dpcpp": "windows/bin/dpcpp.exe",
151-
"icpc": "windows/bin/intel64/icpc.exe",
152-
"icx": "windows/bin/icx.exe",
153-
"icpcx": "windows/bin/icpcx.exe",
154-
"ifx": "windows/bin/ifx.exe",
147+
"icc": "bin/intel64/icl.exe",
148+
"fortran": "bin/intel64/ifort.exe",
149+
"dpcpp": "bin/dpcpp.exe",
150+
"icpc": "bin/intel64/icpc.exe",
151+
"icx": "bin/icx.exe",
152+
"icpcx": "bin/icpcx.exe",
153+
"ifx": "bin/ifx.exe",
155154
}
156155
linCompilers := map[string]string{
157-
"icc": "linux/bin/intel64/icc",
158-
"fortran": "linux/bin/intel64/ifort",
159-
"dpcpp": "linux/bin/dpcpp",
160-
"icpc": "linux/bin/intel64/icpc",
161-
"icx": "linux/bin/icx",
162-
"icpcx": "linux/bin/icpcx",
163-
"ifx": "linux/bin/ifx",
156+
"icc": "bin/intel64/icc",
157+
"fortran": "bin/intel64/ifort",
158+
"dpcpp": "bin/dpcpp",
159+
"icpc": "bin/intel64/icpc",
160+
"icx": "bin/icx",
161+
"icpcx": "bin/icpcx",
162+
"ifx": "bin/ifx",
164163
}
165164
macCompilers := map[string]string{
166-
"icpc": "mac/bin/intel64/icpc",
167-
"icc": "mac/bin/intel64/icc",
168-
"ifort": "mac/bin/intel64/ifort",
169-
"icx": "mac/bin/icx",
170-
"icpcx": "mac/bin/icpcx",
171-
"ifx": "mac/bin/ifx",
165+
"icpc": "bin/intel64/icpc",
166+
"icc": "bin/intel64/icc",
167+
"ifort": "bin/intel64/ifort",
168+
"icx": "bin/icx",
169+
"icpcx": "bin/icpcx",
170+
"ifx": "bin/ifx",
172171
}
173172

174173
compilerRoot := GetCompilerRoot(root)
@@ -220,19 +219,28 @@ func checkSpecialDeps(specialDependencies []string, root string) (msg string, er
220219
return msg, errCode
221220
}
222221

223-
//GetOneAPIRoot gets the root the OneAPI installation
224-
//based on the ONEAPI_ROOT
222+
// GetOneAPIRoot gets the root the OneAPI installation
223+
// based on the ONEAPI_ROOT
225224
func GetOneAPIRoot() (path string, err error) {
226225
root, ok := os.LookupEnv(rootEnvKey)
226+
227227
if !ok {
228228
return "", fmt.Errorf("%s not defined. Be sure to run oneapi environment script ( source setvars.sh )", rootEnvKey)
229229
}
230+
231+
tmp := filepath.Dir(root)
232+
tmp = strings.ToLower(filepath.Base(tmp))
233+
if tmp == "oneapi" {
234+
return filepath.Dir(root), nil
235+
}
236+
230237
return root, nil
231238
}
232239

233240
// CMPLR_ROOT was, for awhile, always defined in the environment. But no longer.
234241
func GetCompilerRoot(root string) (compilerRoot string) {
235-
return filepath.Join(root, "compiler", "latest")
242+
compilerRoot = filepath.Join(root, "compiler", "latest")
243+
return compilerRoot
236244
}
237245

238246
type suiteComponent struct {
@@ -265,7 +273,7 @@ func GenerateMessage(missing []string) string {
265273

266274
//5. return message with url.
267275

268-
//baseURL := "https://software.intel.com/en-us/oneapi" // this is captured in format String
276+
//baseURL := "https://www.intel.com/content/www/us/en/developer/tools/oneapi/overview" // this is captured in format String
269277
var slug string
270278
fallbackMsg := fmt.Sprintf(formatStr, strings.Join(missing, " "), baseURL, slug)
271279

@@ -342,7 +350,7 @@ func readSomeJSON(path string, something interface{}) error {
342350
return nil
343351
}
344352

345-
//keeping the same interface as the file reading function for now.
353+
// keeping the same interface as the file reading function for now.
346354
func parseSomeJSON(str string, something interface{}) error {
347355
json.Unmarshal([]byte(str), something)
348356
return nil

pkg/ui/cli.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const depsMissingEnvFmt = `The sample you have chosen requires the following dep
2525
Unfortunately, we are unable to determine if they are present.
2626
Did you use setvars to configure your environment? Are you using a container build environment?`
2727

28-
//CLI data
28+
// CLI data
2929
type CLI struct {
3030
sidebar *cview.TextView
3131
app *cview.Application
@@ -36,14 +36,14 @@ type CLI struct {
3636
langSelect *cview.List
3737
}
3838

39-
const idzURL = "https://software.intel.com/en-us/oneapi"
39+
const idzURL = "https://www.intel.com/content/www/us/en/developer/tools/oneapi/overview"
4040

4141
func optionViewDocsInBrowser(url string) {
4242
//If it cant open it for some reason, it will silently fail
4343
browser.OpenBrowser(url)
4444
}
4545

46-
//NewCLI create a new *CLI element for showing the CLI
46+
// NewCLI create a new *CLI element for showing the CLI
4747
func NewCLI(a *aggregator.Aggregator, uH string) (cli *CLI, err error) {
4848
if a == nil {
4949
return nil, fmt.Errorf("Aggregator passed not valid")
@@ -64,7 +64,7 @@ func NewCLI(a *aggregator.Aggregator, uH string) (cli *CLI, err error) {
6464
return &CLI{app: cview.NewApplication(), aggregator: a, userHome: uH, oneAPIRoot: oneRootPath}, nil
6565
}
6666

67-
//Show displays the UI
67+
// Show displays the UI
6868
func (cli *CLI) Show() {
6969

7070
list := cview.NewList().
@@ -172,7 +172,7 @@ func newSampleNode(s aggregator.Sample) *cview.TreeNode {
172172
return node
173173
}
174174

175-
//This take a sample and a category to add it to. TODO revist this
175+
// This take a sample and a category to add it to. TODO revist this
176176
func categoriesSeach(parent *cview.TreeNode, cats []string, s aggregator.Sample) {
177177
if len(cats) == 0 {
178178
parent.AddChild(newSampleNode(s))

0 commit comments

Comments
 (0)