-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom install root. (#108)
* refactor: remove duplicated logic for work directory. * chore: use string contains for high go version because of the vfs.stat error message changed. * refactor: remove duplicated logic for commands. * feat: support custom install root. * chore: use parallel 1 for tests * chore: bump kclvm-go to v0.5.0-alpha.1
- Loading branch information
Showing
19 changed files
with
269 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ zz_* | |
**/.vscode | ||
__pycache__ | ||
/vendor | ||
profile.cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
# Copyright 2023 The KCL Authors. All rights reserved. | ||
|
||
KCLVM_URL_MIRRORS:= | ||
PROJECT_NAME = kcl-go | ||
|
||
PWD:=$(shell pwd) | ||
|
||
BUILD_IMAGE:=kusionstack/kclvm-builder | ||
|
||
# export DOCKER_DEFAULT_PLATFORM=linux/amd64 | ||
# or | ||
# --platform linux/amd64 | ||
|
||
RUN_IN_DOCKER:=docker run -it --rm | ||
RUN_IN_DOCKER+=-v ~/.ssh:/root/.ssh | ||
RUN_IN_DOCKER+=-v ~/.gitconfig:/root/.gitconfig | ||
RUN_IN_DOCKER+=-v ${PWD}:/root/kcl | ||
RUN_IN_DOCKER+=-w /root/kcl ${BUILD_IMAGE} | ||
|
||
default: | ||
go run ./cmds/kcl-go run hello.k | ||
|
||
clean: | ||
-rm -rf ./_build | ||
|
||
# ---------------- | ||
# Docker | ||
# ---------------- | ||
|
||
sh-in-docker: | ||
${RUN_IN_DOCKER} bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright The KCL Authors. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
|
||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Reference: k8s.io/client-go/util/homedir | ||
package path | ||
|
||
import ( | ||
"os" | ||
"runtime" | ||
) | ||
|
||
// HomeDir returns the home directory for the current user. | ||
// On Windows: | ||
// 1. if none of those locations are writeable, the first of %HOME%, %USERPROFILE%, %HOMEDRIVE%%HOMEPATH% that exists is returned. | ||
// 2. if none of those locations exists, the first of %HOME%, %USERPROFILE%, %HOMEDRIVE%%HOMEPATH% that is set is returned. | ||
func HomeDir() string { | ||
if runtime.GOOS == "windows" { | ||
home := os.Getenv("HOME") | ||
homeDriveHomePath := "" | ||
if homeDrive, homePath := os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH"); len(homeDrive) > 0 && len(homePath) > 0 { | ||
homeDriveHomePath = homeDrive + homePath | ||
} | ||
userProfile := os.Getenv("USERPROFILE") | ||
|
||
firstSetPath := "" | ||
firstExistingPath := "" | ||
|
||
// Prefer %USERPROFILE% over %HOMEDRIVE%/%HOMEPATH% for compatibility with other auth-writing tools | ||
for _, p := range []string{home, userProfile, homeDriveHomePath} { | ||
if len(p) == 0 { | ||
continue | ||
} | ||
if len(firstSetPath) == 0 { | ||
// remember the first path that is set | ||
firstSetPath = p | ||
} | ||
info, err := os.Stat(p) | ||
if err != nil { | ||
continue | ||
} | ||
if len(firstExistingPath) == 0 { | ||
// remember the first path that exists | ||
firstExistingPath = p | ||
} | ||
if info.IsDir() && info.Mode().Perm()&(1<<(uint(7))) != 0 { | ||
// return first path that is writeable | ||
return p | ||
} | ||
} | ||
|
||
// If none are writeable, return first location that exists | ||
if len(firstExistingPath) > 0 { | ||
return firstExistingPath | ||
} | ||
|
||
// If none exist, return first location that is set | ||
if len(firstSetPath) > 0 { | ||
return firstSetPath | ||
} | ||
|
||
// We've got nothing | ||
return "" | ||
} | ||
return os.Getenv("HOME") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright The KCL Authors. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
|
||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package path | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
const ( | ||
// LibHomeEnvVar is the environment variable used by kcl | ||
// for the lib install directory. When no value is set a default is used. | ||
LibHomeEnvVar = "KCL_LIB_HOME" | ||
) | ||
|
||
// lazypath is an lazy-loaded path buffer for the XDG base directory specification. | ||
type lazypath string | ||
|
||
func (l lazypath) path(envVar string, defaultFn func() string, elem ...string) string { | ||
|
||
// There is an order to checking for a path. | ||
// 1. See if a KCL specific environment variable has been set. | ||
// 2. Fall back to a default | ||
base := os.Getenv(envVar) | ||
if base != "" { | ||
return filepath.Join(base, filepath.Join(elem...)) | ||
} | ||
if base == "" { | ||
base = defaultFn() | ||
} | ||
return filepath.Join(base, string(l), filepath.Join(elem...)) | ||
} | ||
|
||
// libPath defines the base directory relative to which user specific non-essential data files | ||
// should be stored. | ||
func (l lazypath) libPath(elem ...string) string { | ||
return l.path(LibHomeEnvVar, libHome, filepath.Join(elem...)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright The KCL Authors. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
|
||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build darwin | ||
|
||
package path | ||
|
||
import ( | ||
"path/filepath" | ||
) | ||
|
||
func libHome() string { | ||
return filepath.Join(HomeDir(), "Library", "Preferences") | ||
} |
Oops, something went wrong.