Skip to content

Commit 457bf58

Browse files
committed
refactoring; adding new command
1 parent a253906 commit 457bf58

21 files changed

+161
-70
lines changed

.github/workflows/demo-run-codeql-unit-tests.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ jobs:
1919
- name: Checkout repository
2020
uses: actions/checkout@v3
2121

22+
- name: Install QLT
23+
id: install-qlt
24+
uses: ./.github/actions/install-qlt
25+
with:
26+
qlt-version: 'latest'
27+
add-to-path: true
28+
2229
- name: Export unit test matrix
2330
id: export-unit-test-matrix
2431
run: |
@@ -37,7 +44,6 @@ jobs:
3744
- name: Checkout repository
3845
uses: actions/checkout@v3
3946

40-
4147
- name: Install QLT
4248
id: install-qlt
4349
uses: ./.github/actions/install-qlt
@@ -56,8 +62,6 @@ jobs:
5662
- name: Verify Versions of Tooling
5763
shell: bash
5864
run: |
59-
echo "PATH: $PATH"
60-
6165
echo "CodeQL Home: ${{ steps.install-codeql.outputs.codeql-home }}"
6266
echo -e "Checking CodeQL Version:"
6367
codeql --version
@@ -69,7 +73,7 @@ jobs:
6973
- name: Install QL Packs
7074
shell: bash
7175
run: |
72-
find . -name 'qlpack.yml' | xargs -L1 codeql pack install
76+
qlt query run install-packs
7377
7478
- name: Run test suites
7579
id: run-test-suites

CodeQLToolkit.sln

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{3038EA53-8
1515
docs\README.md = docs\README.md
1616
EndProjectSection
1717
EndProject
18-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features.Query.Scaffolding", "src\CodeQLToolkit.Features.Query.Scaffolding\CodeQLToolkit.Features.Query.Scaffolding.csproj", "{4E4FB227-CC8A-495F-9999-2060F2D38F73}"
19-
EndProject
2018
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features.Query", "src\CodeQLToolkit.Features.Query\CodeQLToolkit.Features.Query.csproj", "{EF2DD68B-9320-4450-8803-52FD2BB1E69D}"
2119
EndProject
2220
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Core", "src\CodeQLToolkit.Core\CodeQLToolkit.Core.csproj", "{FFC777F2-B98B-4132-A3B8-896C7F8CB763}"
@@ -47,10 +45,6 @@ Global
4745
Release|Any CPU = Release|Any CPU
4846
EndGlobalSection
4947
GlobalSection(ProjectConfigurationPlatforms) = postSolution
50-
{4E4FB227-CC8A-495F-9999-2060F2D38F73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51-
{4E4FB227-CC8A-495F-9999-2060F2D38F73}.Debug|Any CPU.Build.0 = Debug|Any CPU
52-
{4E4FB227-CC8A-495F-9999-2060F2D38F73}.Release|Any CPU.ActiveCfg = Release|Any CPU
53-
{4E4FB227-CC8A-495F-9999-2060F2D38F73}.Release|Any CPU.Build.0 = Release|Any CPU
5448
{EF2DD68B-9320-4450-8803-52FD2BB1E69D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5549
{EF2DD68B-9320-4450-8803-52FD2BB1E69D}.Debug|Any CPU.Build.0 = Debug|Any CPU
5650
{EF2DD68B-9320-4450-8803-52FD2BB1E69D}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -85,7 +79,6 @@ Global
8579
EndGlobalSection
8680
GlobalSection(NestedProjects) = preSolution
8781
{15D5DFB3-16CE-460F-B361-D6FFB8498508} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C}
88-
{4E4FB227-CC8A-495F-9999-2060F2D38F73} = {15D5DFB3-16CE-460F-B361-D6FFB8498508}
8982
{EF2DD68B-9320-4450-8803-52FD2BB1E69D} = {15D5DFB3-16CE-460F-B361-D6FFB8498508}
9083
{FFC777F2-B98B-4132-A3B8-896C7F8CB763} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C}
9184
{4C5C87E8-46E8-41D3-9CF9-F77148C432AF} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C}

src/CodeQLToolkit.Features.Query.Scaffolding/CodeQLToolkit.Features.Query.Scaffolding.csproj

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

9+
<ItemGroup>
10+
<None Remove="Templates\Query\cpp\new-dataflow-query.liquid" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<Compile Include="Templates\Query\cpp\new-dataflow-query.liquid">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</Compile>
17+
</ItemGroup>
18+
919
<ItemGroup>
1020
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
1121
<PackageReference Include="NLog" Version="5.2.2" />
@@ -14,7 +24,28 @@
1424
</ItemGroup>
1525

1626
<ItemGroup>
17-
<ProjectReference Include="..\CodeQLToolkit.Features.Query.Scaffolding\CodeQLToolkit.Features.Query.Scaffolding.csproj" />
27+
<ProjectReference Include="..\CodeQLToolkit.Shared\CodeQLToolkit.Shared.csproj" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<None Update="Templates\Query\cpp\expected.liquid">
32+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33+
</None>
34+
<None Update="Templates\Query\cpp\new-query.liquid">
35+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
36+
</None>
37+
<None Update="Templates\Query\cpp\qlpack-query.liquid">
38+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
39+
</None>
40+
<None Update="Templates\Query\cpp\qlpack-test.liquid">
41+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
42+
</None>
43+
<None Update="Templates\Query\cpp\test.liquid">
44+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
45+
</None>
46+
<None Update="Templates\Query\cpp\testref.liquid">
47+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
48+
</None>
1849
</ItemGroup>
1950

2051
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using CodeQLToolkit.Features.Query.Commands.Targets;
2+
using CodeQLToolkit.Features.Query.Scaffolding;
3+
using CodeQLToolkit.Shared.Feature;
4+
using CodeQLToolkit.Shared.Options;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.CommandLine;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace CodeQLToolkit.Features.Query.Commands
13+
{
14+
public class QueryCommandFeature : FeatureBase, IToolkitCommandFeature
15+
{
16+
public QueryCommandFeature()
17+
{
18+
FeatureName = "Query";
19+
}
20+
21+
public void Register(Command parentCommand)
22+
{
23+
Log<QueryCommandFeature>.G().LogInformation("Registering command submodule.");
24+
25+
var runCommand = new Command("run", "Functions pertaining to running query-related commands.");
26+
parentCommand.Add(runCommand);
27+
28+
// a command that installs query packs
29+
var installPacksQueryCommand = new Command("install-packs", "Installs CodeQL packs within the repository.");
30+
31+
runCommand.Add(installPacksQueryCommand);
32+
33+
installPacksQueryCommand.SetHandler((basePath) => new InstallQueryPacksCommandTarget() { Base = basePath }.Run(), Globals.BasePathOption);
34+
35+
}
36+
37+
public int Run()
38+
{
39+
throw new NotImplementedException();
40+
}
41+
}
42+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CodeQLToolkit.Features.Query.Commands.Targets
9+
{
10+
public class InstallQueryPacksCommandTarget : CommandTarget
11+
{
12+
public override void Run()
13+
{
14+
Log<InstallQueryPacksCommandTarget>.G().LogInformation("Finding all qlpacks...");
15+
16+
// starting at the base path, find all qlpacks and install them
17+
string[] files = Directory.GetFiles(Base, "qlpack.yml", SearchOption.AllDirectories);
18+
19+
Log<InstallQueryPacksCommandTarget>.G().LogInformation($"Got {files.Length} packs...");
20+
21+
foreach ( string file in files )
22+
{
23+
Log<InstallQueryPacksCommandTarget>.G().LogInformation($"Installing qlpack {file}...");
24+
25+
using(Process process = new Process())
26+
{
27+
process.StartInfo.FileName = "codeql";
28+
process.StartInfo.UseShellExecute = false;
29+
process.StartInfo.RedirectStandardOutput = false;
30+
process.StartInfo.Arguments = $"pack install {file}";
31+
process.Start();
32+
33+
process.WaitForExit();
34+
35+
if(process.ExitCode !=0)
36+
{
37+
DieWithError($"Failed to install query pack {file}.");
38+
}
39+
}
40+
41+
}
42+
43+
Log<InstallQueryPacksCommandTarget>.G().LogInformation($"Installed {files.Length} packs.");
44+
45+
}
46+
}
47+
}

src/CodeQLToolkit.Features.Query/QueryFeatureMain.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodeQLToolkit.Features.Query.Scaffolding;
1+
using CodeQLToolkit.Features.Query.Commands;
2+
using CodeQLToolkit.Features.Query.Scaffolding;
23
using CodeQLToolkit.Shared.Feature;
34
using CodeQLToolkit.Shared.Logging;
45
using Microsoft.Extensions.Logging;
@@ -10,6 +11,8 @@ namespace CodeQLDevelopmentLifecycleToolkit.Features.Query
1011
public class QueryFeatureMain : IToolkitFeature
1112
{
1213
readonly QueryScaffoldFeature scaffoldFeature;
14+
readonly QueryCommandFeature commandFeature;
15+
1316
readonly static QueryFeatureMain instance;
1417

1518
static QueryFeatureMain() {
@@ -18,6 +21,7 @@ static QueryFeatureMain() {
1821
private QueryFeatureMain()
1922
{
2023
scaffoldFeature = new QueryScaffoldFeature();
24+
commandFeature = new QueryCommandFeature();
2125
}
2226

2327
public static QueryFeatureMain Instance { get { return instance; } }
@@ -34,8 +38,9 @@ public void Register(Command parentCommand)
3438
{
3539
var queryCommand = new Command("query", "Use the features related to query creation and execution.");
3640
parentCommand.Add(queryCommand);
37-
Log<QueryFeatureMain>.G().LogInformation("Registering scaffolding submodule.");
41+
3842
scaffoldFeature.Register(queryCommand);
43+
commandFeature.Register(queryCommand);
3944

4045
}
4146
}

src/CodeQLToolkit.Features.Query.Scaffolding/QueryScaffoldFeature.cs renamed to src/CodeQLToolkit.Features.Query/Scaffolding/QueryScaffoldFeature.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public QueryScaffoldFeature() {
1414

1515
public void Register(Command parentCommand)
1616
{
17+
Log<QueryScaffoldFeature>.G().LogInformation("Registering scaffolding submodule.");
18+
1719
var scaffoldCommand = new Command("generate", "Functions pertaining to generating query-related artifacts.");
1820
parentCommand.Add(scaffoldCommand);
1921

0 commit comments

Comments
 (0)