Skip to content

Commit a8237bd

Browse files
committed
Merge branch 'worktree-redesign-repo-config'
2 parents 755f79d + eb73403 commit a8237bd

32 files changed

Lines changed: 302 additions & 212 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ QLStat provides a comprehensive framework for large-scale empirical analysis of
3131

3232
Create your `stat.yaml` config file according to [`example.yaml`](./example.yaml), [`demo.yaml`](./demo.yaml) or YAML files in [`yaml-examples/`](./yaml-examples/). The configuration supports several key sections:
3333

34-
- `sources`: Define repository sources with prefixes and specific repositories
34+
- `repositories`: Define repositories with URL prefixes and optional directory layout
3535
- `language`: Specify the programming language for analysis (e.g., go)
3636
- `buildGrps`: Configure build groups with timeout, build commands, and optional extgen scripts
3737
- `queryconfig`: Set up query execution with parallelization options

ci/malloc_test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ repoRoot: repos # repoRoot stores all repositories
33
dbRoot: codeql-db # dbRoot stores all databases created by codeql indexed by repository name
44

55
# clone
6-
sources:
7-
- prefix: https://test/ # clone url prefix
8-
fullnames:
6+
repositories:
7+
- dir: test/
8+
repos:
99
- malloc_test
1010
- batchmalloc
1111

1212
# build
1313
language: go # language to analyze
1414
buildTimeout: 3600 # timeout for building repository
1515
buildGrps:
16-
- buildRepos: # "*" means all repositories. "-" means repositories defined in "sources" attribute. You can also specify fullname of repositories to force re-build. Note that repositories with same fullname in different source will be re-built also.
16+
- buildRepos: # "*" means all repositories. "-" means repositories defined in the "repositories" section. You can also specify fullname of repositories to force re-build. Note that repositories with same fullname in different source will be re-built also.
1717
- malloc_test
1818
buildCmd: ci/build/malloc_test.sh
1919
extgenScript: ci/extgens/malloc_test.sh

cmd/batch_clone_build/build.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ func buildDirSetup(cfg *config.Artifact) (*os.File, *os.File) {
127127
logFile := utils.CreateFile(logFilePath)
128128
defer logFile.Close()
129129

130-
for _, gs := range cfg.Sources {
131-
hostdir := gs.HostDir(cfg.RepoRoot)
132-
utils.MkdirAll(filepath.Join(hostdir))
130+
for _, rg := range cfg.Repositories {
131+
rg.CreateRepoRootDir(cfg.RepoRoot)
133132
}
134133
return csvFile, logFile
135134
}

cmd/batch_clone_build/clone.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ func batchClone(cfg *config.Artifact) {
4040
statusChan := make(chan cloneStatus)
4141
repoCnt := 0
4242
var wg sync.WaitGroup
43-
for _, gs := range cfg.Sources {
44-
gs.CreateRepoRootDir(cfg.RepoRoot)
45-
for _, repo := range gs.GetRepos() {
43+
for _, rg := range cfg.Repositories {
44+
rg.CreateRepoRootDir(cfg.RepoRoot)
45+
for _, repo := range rg.GetRepos() {
4646
wg.Add(1)
4747
repoCnt++
4848
go func() {

cmd/batch_clone_build/clone_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ func TestCloneBranch(t *testing.T) {
2323
assert.Nil(t, err, err.Error()+"\nstdout:"+outbuf.String()+"\nstderr:"+errbuf.String())
2424
}
2525
outbuf.Reset()
26-
assert.Nil(t, utils.RuncmdWithBuf(filepath.Join(utils.ProjectRoot(), "repos/github.com/zhihu-parallel-pi-calc"), &outbuf, nil, "git", "branch", "--show-current"))
26+
assert.Nil(t, utils.RuncmdWithBuf(filepath.Join(utils.ProjectRoot(), "repos/zhihu-parallel-pi-calc"), &outbuf, nil, "git", "branch", "--show-current"))
2727
assert.Equal(t, "QLStat-test", strings.TrimSpace(outbuf.String()))
2828
}

cmd/batch_clone_build/clone_test.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
logRoot: logs
22
repoRoot: repos
33
dbRoot: codeql-db
4-
sources:
5-
- prefix: https://github.com/ # clone url prefix
6-
fullnames:
4+
repositories:
5+
- urlPrefix: https://github.com/
6+
dir: github.com
7+
repos:
78
- Lslightly-courses/zhihu-parallel-pi-calc QLStat-test
89

910
queryconfig:

cmd/escape_adapter/movedtoheap_test.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ repoRoot: repos # repoRoot stores all repositories
33
dbRoot: codeql-db # dbRoot stores all databases created by codeql indexed by repository name
44

55
# clone
6-
sources:
7-
- prefix: https://test/ # clone url prefix
8-
fullnames:
6+
repositories:
7+
- dir: test/
8+
repos:
99
- escape
1010
- false-sharing
1111

1212
# build
1313
language: go # language to analyze
1414
buildTimeout: 3600 # timeout for building repository
1515
buildGrps:
16-
- buildRepos: # "*" means all repositories. "-" means repositories defined in "sources" attribute. You can also specify fullname of repositories to force re-build. Note that repositories with same fullname in different source will be re-built also.
16+
- buildRepos: # "*" means all repositories. "-" means repositories defined in the "repositories" section. You can also specify fullname of repositories to force re-build. Note that repositories with same fullname in different source will be re-built also.
1717
- "-"
1818
extgenScript: goescape
1919

@@ -23,7 +23,7 @@ queryconfig:
2323
queryRoot: qlsrc # query root. There should be codeql-pack.yaml in queryRoot directory
2424
parallelCore: 20 # parallel cores to run query
2525
queryGrps:
26-
- queryDBs: # "*" means all repositories. "-" means repositories defined in "sources" attribute. Otherwise, use fullnames. Note that repositories with same fullname in different source will be queried.
26+
- queryDBs: # "*" means all repositories. "-" means repositories defined in the "repositories" section. Otherwise, use fullnames. Note that repositories with same fullname in different source will be queried.
2727
- escape
2828
queries: # queries
2929
- escape_ext/moved_to_heap_var_test.ql

config/artifact.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
type Artifact struct {
1515
RepoRoot string `yaml:"repoRoot"`
1616
LogRoot string `yaml:"logRoot"`
17-
Sources []*GitSource `yaml:"sources"`
17+
Repositories []*RepoGroup `yaml:"repositories"`
1818
DBRoot string `yaml:"dbRoot"`
1919
Lang string `yaml:"language"`
2020
BuildTimeout int `yaml:"buildTimeout"`
@@ -156,7 +156,7 @@ type reposType int
156156

157157
const (
158158
buildSpecific reposType = iota
159-
buildWrittenInSources
159+
buildWrittenInRepositories
160160
buildAll
161161
)
162162

@@ -165,7 +165,7 @@ func getReposType(repos []string) reposType {
165165
repo0 := repos[0]
166166
switch repo0 {
167167
case "-":
168-
return buildWrittenInSources
168+
return buildWrittenInRepositories
169169
case "*":
170170
return buildAll
171171
}
@@ -175,23 +175,23 @@ func getReposType(repos []string) reposType {
175175

176176
func (art *Artifact) ConvStrSliceToRepoSlice(repos []string) (res []Repo) {
177177
switch getReposType(repos) {
178-
case buildWrittenInSources:
179-
for _, gs := range art.Sources {
180-
res = append(res, gs.GetRepos()...)
178+
case buildWrittenInRepositories:
179+
for _, rg := range art.Repositories {
180+
res = append(res, rg.GetRepos()...)
181181
}
182182
return
183183
case buildAll:
184-
for _, gs := range art.Sources {
185-
res = append(res, gs.reposInDir(art.RepoRoot)...)
184+
for _, rg := range art.Repositories {
185+
res = append(res, rg.reposInDir(art.RepoRoot)...)
186186
}
187187
return
188188
default:
189-
for _, gs := range art.Sources {
190-
gs.calcFullName2RepoCache()
189+
for _, rg := range art.Repositories {
190+
rg.calcRepoCache()
191191
}
192192
for _, fullname := range repos {
193-
for _, gs := range art.Sources {
194-
if repo, ok := gs.fullName2RepoCache[fullname]; ok {
193+
for _, rg := range art.Repositories {
194+
if repo, ok := rg.repoCache[fullname]; ok {
195195
res = append(res, repo)
196196
}
197197
}

config/gitsource.go

Lines changed: 0 additions & 92 deletions
This file was deleted.

config/repo.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,39 @@ type Repo struct {
1414
FullName string
1515
DirBaseName string
1616
branch string
17-
*GitSource
17+
*RepoGroup
1818
}
1919

20+
// HasURLPrefix returns true if the repo belongs to a group with a URL prefix (remote repo).
21+
func (r *Repo) HasURLPrefix() bool {
22+
return r.RepoGroup != nil && r.RepoGroup.URLPrefix != ""
23+
}
24+
25+
// RemoteURL returns the full clone URL by joining URLPrefix and FullName.
26+
// Must only be called when HasURLPrefix() is true.
2027
func (r *Repo) RemoteURL() string {
21-
url, err := url.JoinPath(r.GitSource.Prefix, r.FullName)
28+
if !r.HasURLPrefix() {
29+
log.Fatalf("RemoteURL called on repo %s which has no URLPrefix (local-only repo)", r.FullName)
30+
}
31+
u, err := url.JoinPath(r.RepoGroup.URLPrefix, r.FullName)
2232
if err != nil {
2333
log.Fatalf("Fail to know target url: %v", err)
2434
}
25-
url += ".git"
26-
return url
35+
u += ".git"
36+
return u
2737
}
2838

29-
// DirPath returns root/<host>/<repo>
39+
// DirPath returns root/<Dir>/<dirBaseName> if Dir is set, otherwise root/<dirBaseName>
3040
func (r *Repo) DirPath(root string) string {
31-
return filepath.Join(r.GitSource.HostDir(root), r.DirBaseName)
41+
return filepath.Join(r.RepoGroup.GroupDir(root), r.DirBaseName)
3242
}
3343

44+
// Clone clones the repo from remote. Skips silently if URLPrefix is empty (local-only repo).
3445
func (r *Repo) Clone(root string) error {
46+
if !r.HasURLPrefix() {
47+
log.Printf("Skipping clone for %s: no URLPrefix (local-only repo)", r.FullName)
48+
return nil
49+
}
3550
args := []string{"clone"}
3651
args = append(args, r.RemoteURL(), r.DirPath(root))
3752
var errBuf bytes.Buffer

0 commit comments

Comments
 (0)