Skip to content

Commit 35baef8

Browse files
authored
Merge pull request #21 from advanced-security/jsinglet/repo-library-issue
adding ability to filter packs
2 parents 45e0c1d + 1276f89 commit 35baef8

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

Diff for: example/qlt.conf.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
"CodeQLCLIBundle": "codeql-bundle-v2.15.5",
55
"EnableCustomCodeQLBundles": true,
66
"CodeQLStandardLibraryIdent": "codeql-cli_v2.15.5",
7-
"ExportedCustomizationPacks" : [
8-
"qlt/cpp-customizations"
7+
"CustomizationPacks" : [
8+
{
9+
"Name": "qlt/cpp-customizations",
10+
"Export" : true
11+
},
12+
{
13+
"Name": "qlt2/stuff2-tests",
14+
"Export" : false
15+
}
916
]
1017
}

Diff for: src/CodeQLToolkit.Features/CodeQL/Commands/Targets/InstallCommand.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CodeQLToolkit.Shared.CodeQL;
22
using CodeQLToolkit.Shared.Types;
3+
using CodeQLToolkit.Shared.Utils;
34
using Newtonsoft.Json;
45
using System;
56
using System.Collections.Generic;
@@ -26,7 +27,10 @@ public override void Run()
2627
if (Packs!=null && Packs.Length > 0)
2728
{
2829
Log<InstallCommand>.G().LogInformation($"Overriding Packs on the command line. The following Packs will be packaged:");
29-
installation.ExportedCustomizationPacks = Packs;
30+
installation.CustomizationPacks = Packs.Select(p => new QLTCustomizationPack()
31+
{
32+
Name = p
33+
}).ToArray();
3034
}
3135
else
3236
{

Diff for: src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ public override void Run()
4141
Log<InstallQueryPacksCommandTarget>.G().LogInformation("In bundle mode so filtering bundled packs...");
4242

4343

44-
foreach (var pack in config.ExportedCustomizationPacks)
44+
foreach (var pack in config.CustomizationPacks)
4545
{
46-
Log<InstallQueryPacksCommandTarget>.G().LogInformation($"Pack {pack} will NOT installed because it is part of the bundle...");
46+
Log<InstallQueryPacksCommandTarget>.G().LogInformation($"Pack {pack.Name} will NOT installed because it is part of the bundle...");
4747
}
4848

49-
files = files.Where(f => !config.ExportedCustomizationPacks.Any(p => CodeQLPackReader.read(f).Name == p)).ToArray();
49+
files = files.Where(f =>
50+
// all things that are part of the customization pack must be excluded.
51+
// if it is exported is not relevant here.
52+
!config.CustomizationPacks.Any(p => CodeQLPackReader.read(f).Name == p.Name)
53+
).ToArray();
5054

5155
Log<InstallQueryPacksCommandTarget>.G().LogInformation($"Got {files.Length} packs after filtering...");
5256

Diff for: src/CodeQLToolkit.Shared/CodeQL/CodeQLInstallation.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class CodeQLInstallation
1919
public string CLIBundle { get; set; }
2020
public string StandardLibraryIdent { get; set; }
2121
public bool EnableCustomCodeQLBundles { get; set; }
22-
public string[] ExportedCustomizationPacks { get; set; }
22+
public QLTCustomizationPack[] CustomizationPacks { get; set; }
2323
public bool QuickBundle { get; set; }
2424
public string Base { get; set; }
2525

@@ -44,7 +44,7 @@ public static CodeQLInstallation LoadFromConfig(QLTConfig c)
4444
CLIBundle = config.CodeQLCLIBundle,
4545
StandardLibraryIdent = config.CodeQLStandardLibraryIdent,
4646
StandardLibraryVersion = config.CodeQLStandardLibrary,
47-
ExportedCustomizationPacks = config.ExportedCustomizationPacks,
47+
CustomizationPacks = config.CustomizationPacks,
4848
Base = config.Base
4949
};
5050

@@ -53,9 +53,9 @@ public static CodeQLInstallation LoadFromConfig(QLTConfig c)
5353

5454
public void LogPacksToBeBuilt()
5555
{
56-
if(ExportedCustomizationPacks != null)
56+
if(CustomizationPacks != null)
5757
{
58-
foreach(var p in ExportedCustomizationPacks)
58+
foreach(var p in CustomizationPacks)
5959
{
6060
Log<CodeQLInstallation>.G().LogInformation($"Pack: {p}");
6161
}
@@ -274,14 +274,16 @@ private void CustomBundleInstall()
274274

275275
var workingDirectory = Path.GetFullPath(Base);
276276

277-
if(ExportedCustomizationPacks == null || ExportedCustomizationPacks.Length == 0)
277+
if(CustomizationPacks == null || CustomizationPacks.Length == 0)
278278
{
279279
throw new Exception("No packs are set to be exported. Please add at least one pack to export in your `qlt.conf.json` file under the property `ExportedCustomizationPacks`.");
280280
}
281281

282282
Log<CodeQLInstallation>.G().LogInformation($"Building custom bundle. This may take a while...");
283283

284-
var packs = string.Join(" ", ExportedCustomizationPacks);
284+
var packsToExport = CustomizationPacks.Where(p => p.Export == true).Select(p => p.Name).ToArray();
285+
286+
var packs = string.Join(" ", packsToExport);
285287
// next, we run the bundling tool.
286288
// typical command line:
287289
// codeql_bundle -b .\scratch\codeql-bundle-win64.tar.gz -o scratch\out -w .\tests\workspace\ --help

Diff for: src/CodeQLToolkit.Shared/Utils/QLTConfig.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77

88
namespace CodeQLToolkit.Shared.Utils
99
{
10+
public class QLTCustomizationPack
11+
{
12+
public string Name { get; set; }
13+
public bool Export { get; set; }
14+
}
15+
1016
public class QLTConfig
1117
{
1218
public string CodeQLCLI { get; set; }
1319
public string CodeQLStandardLibrary { get; set; }
1420
public string CodeQLCLIBundle { get; set; }
1521

16-
public string[] ExportedCustomizationPacks { get; set; }
22+
public QLTCustomizationPack[] CustomizationPacks { get; set; }
1723

1824
public string CodeQLStandardLibraryIdent {
1925
get {

0 commit comments

Comments
 (0)