feat: 增加独立构建工作区、服务端ADB与私有文件清单
支持Git提交导入及未提交源码叠加,APK原名下载和完成通知。新增服务端设备安装与按工程维护的私有文件清单,修复Wrapper预检查、布局及IDE读锁和保存状态问题。更新协议、测试和部署记录;服务端0.7.0,插件0.7.1。
This commit is contained in:
1 parent
87652364bc
commit
6f9cc7e7ea
44 files changed
+2742
-87
No files matched your search
+116
-10
@@ -23,6 +23,7 @@ type GitSnapshot struct {
|
||||
AheadBehind string `json:"aheadBehind"`
|
||||
}
|
||||
type WorkspaceRequest struct {
|
||||
Dedicated bool `json:"dedicated,omitempty"`
|
||||
WorkspacePath string `json:"workspacePath"`
|
||||
ProjectID string `json:"projectId,omitempty"`
|
||||
JavaHome string `json:"javaHome,omitempty"`
|
||||
@@ -74,7 +75,7 @@ func (s *Server) strictManifest(p string) *Project {
|
||||
// Keep this read-only: a build must still match the last committed sync snapshot.
|
||||
func (s *Server) manifest(p string) *Project {
|
||||
result := s.strictManifest(p)
|
||||
if s.projects[p].WorkspacePath == "" {
|
||||
if s.projects[p].WorkspacePath == "" || s.projects[p].Dedicated {
|
||||
return result
|
||||
}
|
||||
remote, e := gitSnapshot(s.work(p))
|
||||
@@ -95,6 +96,23 @@ func (s *Server) manifest(p string) *Project {
|
||||
result.Revision = ""
|
||||
}
|
||||
}
|
||||
checkout, err := inspectCheckout(s.work(p), remote, s.projects[p].Git)
|
||||
if err == nil {
|
||||
actual, inventoryErr := sourceInventory(s.work(p))
|
||||
if inventoryErr == nil {
|
||||
for path := range actual {
|
||||
if _, exists := result.Files[path]; !exists && checkout.matches(path) {
|
||||
if current, err := comparisonFile(filepath.Join(s.work(p), filepath.FromSlash(path))); err == nil {
|
||||
result.Files[path] = current
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !sameSourceHashes(s.projects[p].Files, result.Files) || (s.projects[p].Git != nil && s.projects[p].Git.Head != remote.Head) {
|
||||
result.Revision = ""
|
||||
}
|
||||
result.Git = remote
|
||||
return result
|
||||
}
|
||||
actual, e := sourceInventory(s.work(p))
|
||||
@@ -109,7 +127,7 @@ func (s *Server) manifest(p string) *Project {
|
||||
}
|
||||
result.Files[path] = f
|
||||
}
|
||||
if !sameSourceHashes(s.projects[p].Files, result.Files) {
|
||||
if !sameSourceHashes(s.projects[p].Files, result.Files) || (s.projects[p].Git != nil && s.projects[p].Git.Head != remote.Head) {
|
||||
result.Revision = ""
|
||||
}
|
||||
result.Git = remote
|
||||
@@ -132,6 +150,18 @@ func sameSourceHashes(a, b map[string]File) bool {
|
||||
// Include restored/deleted tracked files when syncing after a clean reset/checkout.
|
||||
func (s *Server) syncBase(p string) (map[string]File, error) {
|
||||
old := s.projects[p].Files
|
||||
if s.projects[p].Dedicated {
|
||||
base := map[string]File{}
|
||||
for path, f := range old {
|
||||
base[path] = f
|
||||
}
|
||||
if s.projects[p].Pending != nil {
|
||||
for path, f := range s.projects[p].Pending.Files {
|
||||
base[path] = f
|
||||
}
|
||||
}
|
||||
return base, nil
|
||||
}
|
||||
if s.projects[p].WorkspacePath == "" {
|
||||
return old, nil
|
||||
}
|
||||
@@ -139,7 +169,7 @@ func (s *Server) syncBase(p string) (map[string]File, error) {
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
if remote == nil || remote.Dirty {
|
||||
if remote == nil {
|
||||
return old, nil
|
||||
}
|
||||
actual, e := sourceInventory(s.work(p))
|
||||
@@ -150,8 +180,14 @@ func (s *Server) syncBase(p string) (map[string]File, error) {
|
||||
for path, f := range old {
|
||||
base[path] = f
|
||||
}
|
||||
var checkout *cleanCheckout
|
||||
if remote.Dirty {
|
||||
checkout, _ = inspectCheckout(s.work(p), remote, s.projects[p].Git)
|
||||
}
|
||||
for path, f := range actual {
|
||||
base[path] = f
|
||||
if !remote.Dirty || checkout.matches(path) {
|
||||
base[path] = f
|
||||
}
|
||||
}
|
||||
return base, nil
|
||||
}
|
||||
@@ -248,7 +284,10 @@ func (s *Server) browseDirectories(w http.ResponseWriter, r *http.Request) {
|
||||
jsonOut(w, map[string]any{"path": path, "root": root, "roots": roots, "parent": parent, "selectable": selectErr == nil, "directories": dirs, "limit": 1000})
|
||||
}
|
||||
func gitCommand(work string, input []byte, args ...string) ([]byte, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
return gitCommandFor(work, input, 30*time.Second, args...)
|
||||
}
|
||||
func gitCommandFor(work string, input []byte, timeout time.Duration, args ...string) ([]byte, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, "git", append([]string{"-c", "safe.directory=" + work, "-C", work}, args...)...)
|
||||
cmd.Stdin = bytes.NewReader(input)
|
||||
@@ -272,12 +311,20 @@ func gitSnapshot(work string) (*GitSnapshot, error) {
|
||||
}
|
||||
return &GitSnapshot{Head: read("rev-parse", "--verify", "HEAD"), Branch: read("symbolic-ref", "--short", "-q", "HEAD"), Dirty: read("status", "--porcelain", "--untracked-files=normal") != "", Upstream: read("rev-parse", "--abbrev-ref", "@{upstream}"), AheadBehind: read("rev-list", "--left-right", "--count", "HEAD...@{upstream}")}, nil
|
||||
}
|
||||
func sourceInventory(work string) (map[string]File, error) {
|
||||
func sourceInventory(work string) (map[string]File, error) { return sourceInventoryMode(work, false) }
|
||||
func dedicatedInventory(work string) (map[string]File, error) { return sourceInventoryMode(work, true) }
|
||||
func sourceInventoryMode(work string, dedicated bool) (map[string]File, error) {
|
||||
if e := noLinks(work); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
result := map[string]File{}
|
||||
git, e := gitSnapshot(work)
|
||||
var git *GitSnapshot
|
||||
var e error
|
||||
if dedicated {
|
||||
git = &GitSnapshot{}
|
||||
} else {
|
||||
git, e = gitSnapshot(work)
|
||||
}
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
@@ -365,6 +412,9 @@ func compareGit(local, remote *GitSnapshot) error {
|
||||
return nil
|
||||
}
|
||||
func (s *Server) checkGit(p string, local *GitSnapshot) error {
|
||||
if s.projects[p].Dedicated {
|
||||
return s.checkDedicated(p, local)
|
||||
}
|
||||
remote, e := gitSnapshot(s.work(p))
|
||||
if e != nil {
|
||||
return e
|
||||
@@ -384,6 +434,15 @@ func (s *Server) checkGit(p string, local *GitSnapshot) error {
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
var checkout *cleanCheckout
|
||||
checked := false
|
||||
clean := func(path string) bool {
|
||||
if !checked {
|
||||
checkout, _ = inspectCheckout(s.work(p), remote, s.projects[p].Git)
|
||||
checked = true
|
||||
}
|
||||
return checkout.matches(path)
|
||||
}
|
||||
for path, f := range s.projects[p].Files {
|
||||
if !validPath(path) {
|
||||
continue
|
||||
@@ -394,11 +453,14 @@ func (s *Server) checkGit(p string, local *GitSnapshot) error {
|
||||
continue
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("服务端源码已变化:%s;为避免覆盖,请先处理服务端修改", path)
|
||||
if clean(path) {
|
||||
continue
|
||||
}
|
||||
return fmt.Errorf("服务端源码已变化:%s;该文件既不匹配上次同步版本,也未能确认与当前 Git 提交一致,请先处理服务端修改", path)
|
||||
}
|
||||
}
|
||||
for path := range actual {
|
||||
if _, ok := s.projects[p].Files[path]; !ok {
|
||||
if _, ok := s.projects[p].Files[path]; !ok && !clean(path) {
|
||||
return fmt.Errorf("服务端新增源码:%s;请先处理服务端修改", path)
|
||||
}
|
||||
}
|
||||
@@ -415,6 +477,46 @@ func (s *Server) checkWorkspace(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, e.Error(), 400)
|
||||
return
|
||||
}
|
||||
if req.Dedicated {
|
||||
var err error
|
||||
buildWork := ""
|
||||
if pr := s.projects[req.ProjectID]; pr != nil && pr.Dedicated {
|
||||
if !sameAccessValue(pr.WorkspacePath, path) {
|
||||
err = fmt.Errorf("工程绑定目录不匹配")
|
||||
} else if pr.Busy {
|
||||
err = fmt.Errorf("工作区正在构建")
|
||||
} else {
|
||||
err = s.checkDedicated(req.ProjectID, req.Git)
|
||||
buildWork = s.work(req.ProjectID)
|
||||
}
|
||||
}
|
||||
if req.Git == nil || !gitObjectID.MatchString(req.Git.Head) {
|
||||
err = fmt.Errorf("请选择具有有效 Git 提交的本机工程")
|
||||
}
|
||||
message := "专用编译工作区:本机提交通过 bundle 导入,原远端仓库不参与同步或构建"
|
||||
if err != nil {
|
||||
message = err.Error()
|
||||
}
|
||||
var baseline *GitSnapshot
|
||||
if pr := s.projects[req.ProjectID]; pr != nil && pr.Dedicated {
|
||||
baseline = pr.Git
|
||||
}
|
||||
report := Preflight{Ready: true, Items: []CheckItem{{Name: "专用工作区", Status: "warning", Message: "首次Remote Run会初始化独立目录;初始化后可在此检查工具链,构建前也会再次检查"}}}
|
||||
if buildWork != "" && err == nil {
|
||||
cfg, configErr := s.buildEnvironment()
|
||||
if configErr == nil && req.JavaHome != "" {
|
||||
cfg.JavaHome, configErr = s.selectedJDK(req.JavaHome)
|
||||
}
|
||||
if configErr != nil {
|
||||
report = Preflight{Items: []CheckItem{{Name: "环境配置", Status: "error", Message: configErr.Error()}}}
|
||||
} else {
|
||||
report = s.preflightForSync(buildWork, path, cfg)
|
||||
}
|
||||
}
|
||||
s.privatePreflight(&report, path)
|
||||
jsonOut(w, map[string]any{"workspacePath": path, "buildWorkspace": buildWork, "canSync": err == nil, "message": message, "git": baseline, "preflight": report})
|
||||
return
|
||||
}
|
||||
remote, e := gitSnapshot(path)
|
||||
if e != nil {
|
||||
http.Error(w, e.Error(), 400)
|
||||
@@ -454,7 +556,7 @@ func (s *Server) checkWorkspace(w http.ResponseWriter, r *http.Request) {
|
||||
if configErr != nil {
|
||||
report = Preflight{Items: []CheckItem{{Name: "环境配置", Status: "error", Message: configErr.Error()}}}
|
||||
} else {
|
||||
report = s.preflight(path, cfg)
|
||||
report = s.preflightForSync(path, path, cfg)
|
||||
}
|
||||
}
|
||||
jsonOut(w, map[string]any{"workspacePath": path, "git": remote, "canSync": e == nil, "message": message, "preflight": report})
|
||||
@@ -465,6 +567,10 @@ func (s *Server) createProject(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, e.Error(), 400)
|
||||
return
|
||||
}
|
||||
if req.Dedicated {
|
||||
s.createDedicated(w, req)
|
||||
return
|
||||
}
|
||||
p := id()
|
||||
pr := &Project{Files: map[string]File{}}
|
||||
if req.WorkspacePath != "" {
|
||||
|
||||
Reference in new issue
Block a user