Skip to content

Commit 3e5534f

Browse files
authored
Merge branch 'main' into post-release-prep/codeql-cli-2.12.3
2 parents 8eb8daa + 35a53fa commit 3e5534f

File tree

118 files changed

+5844
-2276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+5844
-2276
lines changed

.github/actions/cache-query-compilation/action.yml

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,83 @@ runs:
4343
codeql-compile-${{ inputs.key }}-${{ github.ref_name }}-
4444
codeql-compile-${{ inputs.key }}-main-
4545
- name: Fill compilation cache directory
46-
id: fill-compilation-dir
47-
shell: bash
48-
run: |
49-
# Move all the existing cache into another folder, so we only preserve the cache for the current queries.
50-
node $GITHUB_WORKSPACE/.github/actions/cache-query-compilation/move-caches.js ${COMBINED_CACHE_DIR}
51-
52-
echo "compdir=${COMBINED_CACHE_DIR}" >> $GITHUB_OUTPUT
53-
env:
46+
uses: actions/github-script@v6
47+
env:
5448
COMBINED_CACHE_DIR: ${{ runner.temp }}/compilation-dir
49+
with:
50+
script: |
51+
// # Move all the existing cache into another folder, so we only preserve the cache for the current queries.
52+
// mkdir -p ${COMBINED_CACHE_DIR}
53+
// rm -f **/.cache/{lock,size} # -f to avoid errors if the cache is empty.
54+
// # copy the contents of the .cache folders into the combined cache folder.
55+
// cp -r **/.cache/* ${COMBINED_CACHE_DIR}/ || : # ignore missing files
56+
// # clean up the .cache folders
57+
// rm -rf **/.cache/*
58+
59+
const fs = require("fs");
60+
const path = require("path");
61+
62+
// the first argv is the cache folder to create.
63+
const COMBINED_CACHE_DIR = process.env.COMBINED_CACHE_DIR;
64+
65+
function* walkCaches(dir) {
66+
const files = fs.readdirSync(dir, { withFileTypes: true });
67+
for (const file of files) {
68+
if (file.isDirectory()) {
69+
const filePath = path.join(dir, file.name);
70+
yield* walkCaches(filePath);
71+
if (file.name === ".cache") {
72+
yield filePath;
73+
}
74+
}
75+
}
76+
}
77+
78+
async function copyDir(src, dest) {
79+
for await (const file of await fs.promises.readdir(src, { withFileTypes: true })) {
80+
const srcPath = path.join(src, file.name);
81+
const destPath = path.join(dest, file.name);
82+
if (file.isDirectory()) {
83+
if (!fs.existsSync(destPath)) {
84+
fs.mkdirSync(destPath);
85+
}
86+
await copyDir(srcPath, destPath);
87+
} else {
88+
await fs.promises.copyFile(srcPath, destPath);
89+
}
90+
}
91+
}
92+
93+
async function main() {
94+
const cacheDirs = [...walkCaches(".")];
95+
96+
for (const dir of cacheDirs) {
97+
console.log(`Found .cache dir at ${dir}`);
98+
}
99+
100+
// mkdir -p ${COMBINED_CACHE_DIR}
101+
fs.mkdirSync(COMBINED_CACHE_DIR, { recursive: true });
102+
103+
// rm -f **/.cache/{lock,size} # -f to avoid errors if the cache is empty.
104+
await Promise.all(
105+
cacheDirs.map((cacheDir) =>
106+
(async function () {
107+
await fs.promises.rm(path.join(cacheDir, "lock"), { force: true });
108+
await fs.promises.rm(path.join(cacheDir, "size"), { force: true });
109+
})()
110+
)
111+
);
112+
113+
// # copy the contents of the .cache folders into the combined cache folder.
114+
// cp -r **/.cache/* ${COMBINED_CACHE_DIR}/ || : # ignore missing files
115+
await Promise.all(
116+
cacheDirs.map((cacheDir) => copyDir(cacheDir, COMBINED_CACHE_DIR))
117+
);
118+
119+
// # clean up the .cache folders
120+
// rm -rf **/.cache/*
121+
await Promise.all(
122+
cacheDirs.map((cacheDir) => fs.promises.rm(cacheDir, { recursive: true }))
123+
);
124+
}
125+
main();

.github/actions/cache-query-compilation/move-caches.js

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

.github/workflows/ql-for-ql-build.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ on:
55
branches: [main]
66
pull_request:
77
branches: [main]
8-
paths:
9-
- "ql/**"
10-
- "**.qll"
11-
- "**.ql"
12-
- "**.dbscheme"
13-
- "**/qlpack.yml"
14-
- ".github/workflows/ql-for-ql-build.yml"
158

169
env:
1710
CARGO_TERM_COLOR: always

cpp/autobuilder/Semmle.Autobuild.Cpp.Tests/BuildScripts.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ IEnumerable<string> IBuildActions.EnumerateDirectories(string dir)
131131

132132
bool IBuildActions.IsWindows() => IsWindows;
133133

134+
public bool IsMacOs { get; set; }
135+
136+
bool IBuildActions.IsMacOs() => IsMacOs;
137+
138+
public bool IsArm { get; set; }
139+
140+
bool IBuildActions.IsArm() => IsArm;
141+
134142
string IBuildActions.PathCombine(params string[] parts)
135143
{
136144
return string.Join(IsWindows ? '\\' : '/', parts.Where(p => !string.IsNullOrWhiteSpace(p)));

csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ IEnumerable<string> IBuildActions.EnumerateDirectories(string dir)
145145

146146
bool IBuildActions.IsWindows() => IsWindows;
147147

148+
public bool IsMacOs { get; set; }
149+
150+
bool IBuildActions.IsMacOs() => IsMacOs;
151+
152+
public bool IsArm { get; set; }
153+
154+
bool IBuildActions.IsArm() => IsArm;
155+
148156
public string PathCombine(params string[] parts)
149157
{
150158
return string.Join(IsWindows ? '\\' : '/', parts.Where(p => !string.IsNullOrWhiteSpace(p)));

csharp/autobuilder/Semmle.Autobuild.Shared/BuildActions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Net.Http;
88
using System.Diagnostics.CodeAnalysis;
99
using System.Threading.Tasks;
10+
using System.Runtime.InteropServices;
1011

1112
namespace Semmle.Autobuild.Shared
1213
{
@@ -98,6 +99,18 @@ public interface IBuildActions
9899
/// </summary>
99100
bool IsWindows();
100101

102+
/// <summary>
103+
/// Gets a value indicating whether we are running on macOS.
104+
/// </summary>
105+
/// <returns>True if we are running on macOS.</returns>
106+
bool IsMacOs();
107+
108+
/// <summary>
109+
/// Gets a value indicating whether we are running on arm.
110+
/// </summary>
111+
/// <returns>True if we are running on arm.</returns>
112+
bool IsArm();
113+
101114
/// <summary>
102115
/// Combine path segments, Path.Combine().
103116
/// </summary>
@@ -203,6 +216,12 @@ int IBuildActions.RunProcess(string cmd, string args, string? workingDirectory,
203216

204217
bool IBuildActions.IsWindows() => Win32.IsWindows();
205218

219+
bool IBuildActions.IsMacOs() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
220+
221+
bool IBuildActions.IsArm() =>
222+
RuntimeInformation.ProcessArchitecture == Architecture.Arm64 ||
223+
RuntimeInformation.ProcessArchitecture == Architecture.Arm;
224+
206225
string IBuildActions.PathCombine(params string[] parts) => Path.Combine(parts);
207226

208227
void IBuildActions.WriteAllText(string filename, string contents) => File.WriteAllText(filename, contents);

csharp/autobuilder/Semmle.Autobuild.Shared/MsBuildRule.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
using Semmle.Util.Logging;
2+
using System;
23
using System.Linq;
4+
using System.Runtime.InteropServices;
35

46
namespace Semmle.Autobuild.Shared
57
{
8+
internal static class MsBuildCommandExtensions
9+
{
10+
/// <summary>
11+
/// Appends a call to msbuild.
12+
/// </summary>
13+
/// <param name="cmdBuilder"></param>
14+
/// <param name="builder"></param>
15+
/// <returns></returns>
16+
public static CommandBuilder MsBuildCommand(this CommandBuilder cmdBuilder, IAutobuilder<AutobuildOptionsShared> builder)
17+
{
18+
var isArmMac = builder.Actions.IsMacOs() && builder.Actions.IsArm();
19+
20+
// mono doesn't ship with `msbuild` on Arm-based Macs, but we can fall back to
21+
// msbuild that ships with `dotnet` which can be invoked with `dotnet msbuild`
22+
// perhaps we should do this on all platforms?
23+
return isArmMac ?
24+
cmdBuilder.RunCommand("dotnet").Argument("msbuild") :
25+
cmdBuilder.RunCommand("msbuild");
26+
}
27+
}
28+
629
/// <summary>
730
/// A build rule using msbuild.
831
/// </summary>
932
public class MsBuildRule : IBuildRule<AutobuildOptionsShared>
1033
{
11-
/// <summary>
12-
/// The name of the msbuild command.
13-
/// </summary>
14-
private const string msBuild = "msbuild";
15-
1634
public BuildScript Analyse(IAutobuilder<AutobuildOptionsShared> builder, bool auto)
1735
{
1836
if (!builder.ProjectsOrSolutionsToBuild.Any())
@@ -57,7 +75,7 @@ BuildScript GetNugetRestoreScript() =>
5775
Script;
5876
var nugetRestore = GetNugetRestoreScript();
5977
var msbuildRestoreCommand = new CommandBuilder(builder.Actions).
60-
RunCommand(msBuild).
78+
MsBuildCommand(builder).
6179
Argument("/t:restore").
6280
QuoteArgument(projectOrSolution.FullPath);
6381

@@ -95,7 +113,7 @@ BuildScript GetNugetRestoreScript() =>
95113
command.RunCommand("set Platform=&& type NUL", quoteExe: false);
96114
}
97115

98-
command.RunCommand(msBuild);
116+
command.MsBuildCommand(builder);
99117
command.QuoteArgument(projectOrSolution.FullPath);
100118

101119
var target = builder.Options.MsBuildTarget ?? "rebuild";

csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifier.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ public static void HasModifier(Context cx, TextWriter trapFile, IEntity target,
6565
trapFile.has_modifiers(target, Modifier.Create(cx, modifier));
6666
}
6767

68+
private static void ExtractFieldModifiers(Context cx, TextWriter trapFile, IEntity key, IFieldSymbol symbol)
69+
{
70+
if (symbol.IsReadOnly)
71+
HasModifier(cx, trapFile, key, Modifiers.Readonly);
72+
73+
if (symbol.IsRequired)
74+
HasModifier(cx, trapFile, key, Modifiers.Required);
75+
}
76+
6877
private static void ExtractNamedTypeModifiers(Context cx, TextWriter trapFile, IEntity key, ISymbol symbol)
6978
{
7079
if (symbol.Kind != SymbolKind.NamedType)
@@ -106,8 +115,11 @@ public static void ExtractModifiers(Context cx, TextWriter trapFile, IEntity key
106115
if (symbol.IsVirtual)
107116
HasModifier(cx, trapFile, key, Modifiers.Virtual);
108117

109-
if (symbol.Kind == SymbolKind.Field && ((IFieldSymbol)symbol).IsReadOnly)
110-
HasModifier(cx, trapFile, key, Modifiers.Readonly);
118+
if (symbol is IFieldSymbol field)
119+
ExtractFieldModifiers(cx, trapFile, key, field);
120+
121+
if (symbol.Kind == SymbolKind.Property && ((IPropertySymbol)symbol).IsRequired)
122+
HasModifier(cx, trapFile, key, Modifiers.Required);
111123

112124
if (symbol.IsOverride)
113125
HasModifier(cx, trapFile, key, Modifiers.Override);

csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifiers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ internal static class Modifiers
1313
public const string Public = "public";
1414
public const string Readonly = "readonly";
1515
public const string Record = "record";
16+
public const string Required = "required";
1617
public const string Ref = "ref";
1718
public const string Sealed = "sealed";
1819
public const string Static = "static";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace Test
4+
{
5+
public class Program
6+
{
7+
public static int Main(string[] args)
8+
{
9+
Console.WriteLine("Hello world!");
10+
return 0;
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)