Skip to content

Commit d5a37cd

Browse files
committed
Merge branch 'topic/ci/formatting_check' into 'master'
Rework the sources format checking pipeline Closes #485 See merge request eng/libadalang/langkit-query-language!499
2 parents 5e186ed + 2c71cf7 commit d5a37cd

File tree

5 files changed

+120
-11
lines changed

5 files changed

+120
-11
lines changed

.gitlab-ci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,52 @@
1+
include:
2+
- component: $CI_SERVER_FQDN/eng/gitlab-templates/check-issue@~latest
3+
inputs:
4+
stage: checkstyle
5+
- component: $CI_SERVER_FQDN/eng/gitlab-templates/pre-commit@~latest
6+
inputs:
7+
stage: checkstyle
8+
19
stages:
10+
- checkstyle
211
- test
312

13+
pre-commit:
14+
services:
15+
- image:pe-base
16+
- cpu:8
17+
- mem:32
18+
- disk:50
19+
before_script:
20+
# Create a sandbox and install needed dependencies
21+
- generic_anod_ci
22+
- . /tmp/ci_env.sh
23+
# Define working variables
24+
- npm_cache=$PWD/npm_cache
25+
- npm_cache_install=$npm_cache/spotless-prettier-node-modules-fbb3f0657a1374078dbfdc0a3df68734
26+
- maven_local_repo=$(anod info maven-repo-pull -Qclient=lkql --show working_dir)/install
27+
- npmrc_file=$PWD/.npmrc
28+
29+
# Echo vars to log information about the run
30+
- echo $npm_cache
31+
- echo $npm_cache_install
32+
- echo $maven_local_repo
33+
34+
# Install all pre-commit dependencies
35+
- anod install gnatformat
36+
- anod build java -Q version=17,vendor=graalvm
37+
- anod build maven -Q version=3.6.3
38+
- anod build nodejs -Q version=16.19.1
39+
- anod build maven-repo-pull -Q client=lkql
40+
- eval $(anod printenv gnatformat)
41+
- eval $(anod printenv java -Q version=17,vendor=graalvm)
42+
- eval $(anod printenv maven -Q version=3.6.3)
43+
- eval $(anod printenv nodejs -Q version=16.19.1)
44+
- mkdir -p $npm_cache_install
45+
- e3-cathod thirdparty prettier_java-npm_cache-20250203.tar.gz --install $npm_cache_install --delete
46+
- ls $npm_cache_install
47+
- echo "offline=true" > $npmrc_file
48+
- export MAVEN_ARGS="-Dmaven.repo.local=$maven_local_repo -Dconfig.npmInstallCache=$npm_cache -Dconfig.npmrc=$npmrc_file"
49+
450
# Common part for all testing CIs
551
.common-test-part: &common-test-part
652
services:

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: gnatformat
5+
name: Format GNATcheck sources
6+
entry: gnatformat
7+
language: system
8+
files: "^lkql_checker/src/.*\\.ad(b|s)$"
9+
- repo: local
10+
hooks:
11+
- id: maven-spotless
12+
name: Format LKQL JIT sources
13+
entry: python
14+
args:
15+
- utils/maven_wrapper.py
16+
- spotless:apply
17+
language: system
18+
pass_filenames: false
19+
require_serial: true
20+
files: "^lkql_jit/.*\\.java$"

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,9 @@ package body Gnatcheck.Compiler is
15591559
if Gnatcheck_Prj.Tree.Is_Defined
15601560
and then Gnatcheck_Prj.Tree.Has_Explicit_Target
15611561
then
1562-
return Ada.Strings.Unbounded."=" (Target, "codepeer") or else
1563-
Ada.Strings.Unbounded."=" (Target, "gnatsas");
1562+
return
1563+
Ada.Strings.Unbounded."=" (Target, "codepeer")
1564+
or else Ada.Strings.Unbounded."=" (Target, "gnatsas");
15641565
end if;
15651566

15661567
-- If we could find a regular gnatls, it means there is a native

lkql_jit/pom.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,6 @@
122122
<artifactId>spotless-maven-plugin</artifactId>
123123
<version>2.40.0</version>
124124

125-
<executions>
126-
<execution>
127-
<goals>
128-
<goal>check</goal>
129-
</goals>
130-
<phase>validate</phase>
131-
</execution>
132-
</executions>
133-
134125
<configuration>
135126
<java>
136127
<includes>

utils/maven_wrapper.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
This script is a wrapper around the Maven command, it is used by the pre-commit
3+
hooks configuration to simplify the process of running Maven on LKQL JIT
4+
sources.
5+
"""
6+
7+
import os
8+
import subprocess
9+
import sys
10+
11+
if __name__ == '__main__':
12+
# Get the Maven executable
13+
mvn = "mvn.cmd" if os.name == "nt" else "mvn"
14+
15+
# Get the path of the LKQL JIT "pom.xml" file
16+
pom_xml = os.path.abspath(
17+
os.path.join(
18+
os.path.dirname(os.path.realpath(__file__)),
19+
"..",
20+
"lkql_jit",
21+
"pom.xml",
22+
)
23+
)
24+
25+
# Forward script arguments to Maven and ensure 'MAVEN_ARGS' is taken into
26+
# account.
27+
maven_args = sys.argv[1:] + (
28+
os.environ['MAVEN_ARGS'].split(" ")
29+
if os.environ.get('MAVEN_ARGS') else
30+
[]
31+
)
32+
33+
# Set maven to offline mode when running in a Gitlab CI
34+
if "CI_JOB_NAME" in os.environ:
35+
maven_args = [
36+
"-o",
37+
*maven_args,
38+
]
39+
40+
# Run Maven on LKQL JIT project with additional args of this script
41+
try:
42+
subprocess.check_output([
43+
mvn,
44+
"-f",
45+
pom_xml,
46+
"-q",
47+
*maven_args
48+
])
49+
except subprocess.CalledProcessError as e:
50+
print(e.output.decode())
51+
exit(e.returncode)

0 commit comments

Comments
 (0)