Skip to content

Commit

Permalink
Merge pull request #286 from tbs60/dev_tming
Browse files Browse the repository at this point in the history
Dev tming
  • Loading branch information
tming authored Aug 27, 2024
2 parents 689f5e9 + 985355a commit 2c91bef
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 28 deletions.
71 changes: 49 additions & 22 deletions src/backend/booster/bk_dist/booster/pkg/booster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1343,15 +1343,15 @@ func (b *Booster) checkPump() {
b.checkPumpCache(pumpdir)

if b.config.Works.PumpSearchLink && runtime.GOOS == "darwin" {
dirs := []string{}
// 获取默认xcode的路径
xcodepath, err := getXcodeIncludeLinkDir()
if err != nil || xcodepath == nil {
blog.Infof("booster: get default xcode path with error:%v", err)
return
} else {
// 得到所有需要搜索的目录(包括默认xcode和用户指定的)
dirs = xcodepath
}

// 得到所有需要搜索的目录(包括默认xcode和用户指定的)
dirs := xcodepath
dirs = append(dirs, b.config.Works.PumpSearchLinkDir...)

// 搜索所有symlink
Expand Down Expand Up @@ -1405,27 +1405,50 @@ func getXcodeIncludeLinkDir() ([]string, error) {
return nil, err
}

xcodepath := filepath.Join(strings.Trim(string(stdout), "\r\n "), "Platforms/MacOSX.platform/Developer/SDKs")
info, err := os.Stat(xcodepath)
if info != nil && (err == nil || os.IsExist(err)) {
fis, err := ioutil.ReadDir(xcodepath)
if err != nil {
return nil, err
// get all dirs in Platforms
platformspath := filepath.Join(strings.Trim(string(stdout), "\r\n "), "Platforms")
var subdirs []string

entries, err := os.ReadDir(platformspath)
if err != nil {
return nil, err
}

for _, entry := range entries {
if entry.IsDir() {
absPath, err := filepath.Abs(filepath.Join(platformspath, entry.Name()))
if err != nil {
return nil, err
}
subdirs = append(subdirs, absPath)
}
}

// get all target dirs
resultdirs := []string{}
for _, v := range subdirs {
// xcodepath := filepath.Join(strings.Trim(string(stdout), "\r\n "), "Platforms/MacOSX.platform/Developer/SDKs")
xcodepath := filepath.Join(v, "Developer/SDKs")
info, err := os.Stat(xcodepath)
if info != nil && (err == nil || os.IsExist(err)) {
fis, err := ioutil.ReadDir(xcodepath)
if err != nil {
return nil, err
}

for _, fi := range fis {
if fi.Mode()&os.ModeSymlink != 0 {
linkfile := filepath.Join(xcodepath, fi.Name())
originFile, err := os.Readlink(linkfile)
for _, fi := range fis {
if fi.Mode()&os.ModeSymlink != 0 {
linkfile := filepath.Join(xcodepath, fi.Name())
originFile, err := os.Readlink(linkfile)

if err != nil {
blog.Warnf("booster: readlink %s with error:%v", linkfile, err)
continue
}
if err != nil {
blog.Warnf("booster: readlink %s with error:%v", linkfile, err)
continue
}

blog.Infof("booster: Resolved symlink %s to %s", linkfile, originFile)
blog.Infof("booster: Resolved symlink %s to %s", linkfile, originFile)

if strings.HasSuffix(originFile, "MacOSX.sdk") {
// if strings.HasSuffix(originFile, "MacOSX.sdk") {
blog.Infof("booster: found target link dir %s", linkfile)

xcodepath1 := filepath.Join(linkfile, "usr/include")
Expand All @@ -1435,13 +1458,17 @@ func getXcodeIncludeLinkDir() ([]string, error) {
}
xcodepath2 := filepath.Join(originFile, "usr/include")

return []string{xcodepath1, xcodepath2}, nil
resultdirs = append(resultdirs, xcodepath1)
resultdirs = append(resultdirs, xcodepath2)

// return []string{xcodepath1, xcodepath2}, nil
// }
}
}
}
}

return nil, nil
return resultdirs, nil
}

func getLinkFile(pumpdir string, xcodepath string) string {
Expand Down
5 changes: 5 additions & 0 deletions src/backend/booster/bk_dist/booster/pkg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ func searchSymlink(dirPth string, files map[string]string) (err error) {
}

err = filepath.Walk(dirPth, func(filename string, fi os.FileInfo, err error) error {
if err != nil {
blog.Infof("booster: search path:%s failed with error:%v", dirPth, err)
return err
}

if fi.IsDir() {
return nil
}
Expand Down
10 changes: 8 additions & 2 deletions src/backend/booster/bk_dist/handler/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func GetFileInfo(fs []string, mustexisted bool, notdir bool, statbysearchdir boo
tempis := make(map[string]*dcFile.Info, len(notfound))
for _, notf := range notfound {
tempf := notf
try := 0
maxtry := 10
for {
var i *dcFile.Info
if statbysearchdir {
Expand All @@ -124,6 +126,7 @@ func GetFileInfo(fs []string, mustexisted bool, notdir bool, statbysearchdir boo
i = dcFile.Lstat(tempf)
}
tempis[tempf] = i
try++

if !i.Exist() {
if mustexisted {
Expand Down Expand Up @@ -156,8 +159,11 @@ func GetFileInfo(fs []string, mustexisted bool, notdir bool, statbysearchdir boo
}

// 如果是链接,并且指向了其它文件,则需要将指向的文件也包含进来
loopagain = true
tempf = originFile
// 增加寻找次数限制,避免死循环
if try < maxtry {
loopagain = true
tempf = originFile
}
} else {
blog.Infof("common util: symlink %s Readlink error:%s", tempf, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,12 +837,28 @@ func encodeSendFileReq(
}

fullpath := sandbox.GetAbsPath(f.FilePath)
size := f.FileSize
md5 := f.Md5

// TODO : fresh file info here, avoid file info changed
newlyInfo := dcFile.Lstat(fullpath)
if !newlyInfo.Exist() {
blog.Warnf("file %f not existed when encode send request", fullpath)
continue
}

size := newlyInfo.Size()
md5 := ""
if f.Md5 != "" {
md5, _ = newlyInfo.Md5()
}
filemode := newlyInfo.Mode32()
modifytime := newlyInfo.ModifyTime64()

// size := f.FileSize
// md5 := f.Md5
targetrelativepath := f.Targetrelativepath
filemode := f.Filemode
// filemode := f.Filemode
linkTarget := f.LinkTarget
modifytime := f.Lastmodifytime
// modifytime := f.Lastmodifytime

if size <= 0 {
pbbody.Inputfiles = append(pbbody.Inputfiles, &protocol.PBFileDesc{
Expand Down

0 comments on commit 2c91bef

Please sign in to comment.