diff --git a/pkg/settings/a_test_unix.go b/pkg/settings/a_test_unix.go index fc8ad86f..7e149531 100644 --- a/pkg/settings/a_test_unix.go +++ b/pkg/settings/a_test_unix.go @@ -19,6 +19,8 @@ kcl_cli_configs: - ${KCL_MOD}/file2.k - ../../base/base.k disable_none: false + package_maps: + k8s: ../vendor/k8s ` f, err := LoadFile("./sub/settings.yaml", []byte(s)) if err != nil { @@ -33,6 +35,8 @@ kcl_cli_configs: tAssertEQ(t, x.KFilenameList[1], filepath.Join(pwd, "sub", "sub_main.k")) tAssertEQ(t, x.KFilenameList[2], filepath.Join(pwd, "file2.k")) tAssertEQ(t, x.KFilenameList[3], filepath.Join(pwd, "..", "base", "base.k")) + tAssertEQ(t, x.ExternalPkgs[1].PkgName, "k8s") + tAssertEQ(t, x.ExternalPkgs[1].PkgPath, "../vendor/k8s") } func tAssertEQ(t *testing.T, x, y interface{}) { diff --git a/pkg/settings/utils_settings_yaml.go b/pkg/settings/utils_settings_yaml.go index 546454d3..ed544d99 100644 --- a/pkg/settings/utils_settings_yaml.go +++ b/pkg/settings/utils_settings_yaml.go @@ -29,11 +29,13 @@ type ConfigStruct struct { Overrides []string `yaml:"overrides"` PathSelector []string `yaml:"path_selector"` - StrictRangeCheck bool `yaml:"strict_range_check"` - DisableNone bool `yaml:"disable_none"` - Verbose int `yaml:"verbose"` - Debug bool `yaml:"debug"` + StrictRangeCheck bool `yaml:"strict_range_check"` + DisableNone bool `yaml:"disable_none"` + Verbose int `yaml:"verbose"` + Debug bool `yaml:"debug"` + PackageMaps map[string]string `yaml:"package_maps"` } + type KeyValueStruct struct { Key string `yaml:"key"` Value interface{} `yaml:"value"` @@ -174,6 +176,15 @@ func (settings *SettingsFile) To_ExecProgram_Args() *gpyrpc.ExecProgram_Args { }) } + // kcl -E k8s=../vendor/k8s + for name, path := range settings.Config.PackageMaps { + externalPkg := gpyrpc.CmdExternalPkgSpec{ + PkgName: name, + PkgPath: path, + } + args.ExternalPkgs = append(args.ExternalPkgs, &externalPkg) + } + return args }