Skip to content

Commit 6f00de0

Browse files
committed
feat: add externalRoot
1 parent ac909d0 commit 6f00de0

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

cmd/codeql_qdriver/main.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func queriesExec(cfg *config.Artifact, grp config.QueryGroup, queryRoot string,
170170
// Create Query objects for all queries in the group
171171
queries := make([]config.Query, len(grp.Queries))
172172
for i, qScript := range grp.Queries {
173-
queries[i] = config.CreateQuery(qScript, grp.Externals, grp.ExternalFiles, queryRoot)
173+
queries[i] = config.CreateQuery(qScript, grp.Externals, grp.ExternalFiles, grp.ResolvedExternalRoot())
174174
}
175175

176176
bar := progressbar.Default(int64(len(dbs)))
@@ -207,13 +207,12 @@ func decodeResults(cfg *config.Artifact, tgtFmt string) {
207207
checkDecodeTargetFmt(tgtFmt)
208208

209209
for grpi, grp := range cfg.QueryGrps {
210-
queryRoot := grp.ResolvedQueryRoot()
211210
dbs := cfg.ConvStrSliceToDBSlice(grp.QueryDBs)
212211
queries := grp.Queries
213212

214213
bar := progressbar.Default(int64(len(queries) * len(dbs)))
215214
for _, qScript := range queries {
216-
query := config.CreateQuery(qScript, grp.Externals, grp.ExternalFiles, queryRoot)
215+
query := config.CreateQuery(qScript, grp.Externals, grp.ExternalFiles, grp.ResolvedExternalRoot())
217216
for _, db := range dbs {
218217
bqrsPath := filepath.Join(db.Path(), "results/lslightly/qlstat", query.PathNoExt()+".bqrs")
219218
csvPath := filepath.Join(db.Path(), "results/lslightly/qlstat", query.PathNoExt()+"."+tgtFmt)
@@ -245,10 +244,9 @@ func decodeResults(cfg *config.Artifact, tgtFmt string) {
245244

246245
func collectCSVs(cfg *config.Artifact) {
247246
for grpi, grp := range cfg.QueryGrps {
248-
queryRoot := grp.ResolvedQueryRoot()
249247
bar := progressbar.Default(int64(len(grp.Queries)))
250248
for _, qScript := range grp.Queries {
251-
query := config.CreateQuery(qScript, grp.Externals, grp.ExternalFiles, queryRoot)
249+
query := config.CreateQuery(qScript, grp.Externals, grp.ExternalFiles, grp.ResolvedExternalRoot())
252250
bar.Describe(fmt.Sprintf("Grp %d: Collecting for "+query.PathNoExt(), grpi))
253251
collectCSVsForQuery(cfg, query, grp)
254252
bar.Add(1)

config/artifact.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type BuildGroup struct {
3737

3838
type QueryGroup struct {
3939
QueryRoot string `yaml:"queryRoot"`
40+
ExternalRoot string `yaml:"externalRoot"`
4041
QueryDBs []string `yaml:"queryDBs"`
4142
Queries []string `yaml:"queries"`
4243
Externals []string `yaml:"externals"`
@@ -53,6 +54,16 @@ func (g *QueryGroup) ResolvedQueryRoot() string {
5354
return g.QueryRoot
5455
}
5556

57+
// ResolvedExternalRoot returns the absolute path for external predicate files.
58+
// "std" or empty → <projectRoot>/qlsrc (same as built-in query root).
59+
// Other values are returned as-is (absolute path or CWD-relative).
60+
func (g *QueryGroup) ResolvedExternalRoot() string {
61+
if g.ExternalRoot == "" || g.ExternalRoot == "std" {
62+
return filepath.Join(utils.ProjectRoot(), "qlsrc")
63+
}
64+
return g.ExternalRoot
65+
}
66+
5667
func UnmarshalArtifact(filename string) *Artifact {
5768
data, err := os.ReadFile(filename)
5869
if err != nil {

config/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ type Query struct {
1414
cacheEntriesForFiles []string // cache external entries for externalFiles
1515
}
1616

17-
func CreateQuery(path string, externals []string, externalFiles []string, queryRoot string) Query {
17+
func CreateQuery(path string, externals []string, externalFiles []string, externalRoot string) Query {
1818
if filepath.Ext(path) != ".ql" {
1919
log.Fatalf("Suffix of query source %s is not .ql.", path)
2020
}
2121
cache := make([]string, 0, len(externalFiles)*5)
2222
for _, extfile := range externalFiles {
2323
resolvedPath := extfile
2424
if !filepath.IsAbs(extfile) {
25-
resolvedPath = filepath.Join(queryRoot, extfile)
25+
resolvedPath = filepath.Join(externalRoot, extfile)
2626
}
2727
exts, err := ReadExtsFromFile(resolvedPath)
2828
if err != nil {

0 commit comments

Comments
 (0)