Skip to content

Commit 9a5d60a

Browse files
mstachniukrudy-regazzoni-sonarsourceclaude
authored andcommitted
SONARGO-584 Add build on Windows in CI (#666)
Co-authored-by: Rudy Regazzoni <rudy.regazzoni@sonarsource.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> GitOrigin-RevId: 64cf20986da00de90b993ed4b63c50db166e344b
1 parent fd5484b commit 9a5d60a

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

sonar-go-commons/src/main/java/org/sonar/go/converter/DefaultCommand.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ public String executeCommand(Map<String, String> filenameToContentMap) throws IO
9393
}
9494
return output;
9595
} finally {
96+
// On Windows, the process handle must be explicitly closed to release the file lock on the executable.
97+
// Without this, the .exe file remains locked and cannot be deleted during test cleanup.
98+
process.destroyForcibly();
99+
try {
100+
process.waitFor();
101+
} catch (InterruptedException e) {
102+
Thread.currentThread().interrupt();
103+
}
96104
errorConsumer.shutdown();
97105
}
98106
}

sonar-go-to-slang/make.bat

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ EXIT /B %ERRORLEVEL%
1010
SET GOOS=windows
1111
SET GOARCH=amd64
1212
SET CGO_ENABLED=0
13-
CALL go build -buildmode=exe -o build/executable/sonar-go-to-slang-amd64 ./src
14-
15-
EXIT /B 0
13+
IF NOT EXIST "build\executable" MKDIR "build\executable"
14+
CALL go run generate_source.go
15+
IF ERRORLEVEL 1 EXIT /B 1
16+
CALL go build -ldflags="-s -w" -buildmode=exe -o build\executable\sonar-go-to-slang-windows-amd64.exe .
17+
EXIT /B %ERRORLEVEL%
1618

1719
:generate_test_report
1820
SET CGO_ENABLED=0
19-
CALL go test -timeout 5s -json > build/test-report.json
21+
CALL go test -timeout 5s -json > build\test-report.json
2022
EXIT /B 0
2123

2224
:go_install_check
2325
WHERE /q go
2426
IF ERRORLEVEL 1 (
2527
ECHO go is not installed
26-
EXIT "1"
28+
EXIT /B 1
2729
)
2830
EXIT /B
2931

@@ -32,25 +34,24 @@ set argC=0
3234
for %%x in (%*) do Set /A argC+=1
3335
IF %argC% NEQ 1 (
3436
echo "Usage: %~0 build | clean | test"
35-
exit "0"
37+
EXIT /B 0
3638
)
3739

38-
IF "%~1%" == "build" (
40+
IF "%~1" == "build" (
3941
CALL :compile_binaries
40-
) ELSE IF "%~1%"=="test" (
42+
) ELSE IF "%~1"=="test" (
4143
CALL :generate_test_report
42-
) ELSE IF "%~1%"=="clean" (
44+
) ELSE IF "%~1"=="clean" (
4345
DEL "goparser_generated.go"
4446
DEL "build\test-report.json"
4547
DEL "build\executable\*"
46-
DEL "build/test-coverage.out"
47-
DEL "build/main_test"
48-
DEL "build/cross-file-tests"
48+
DEL "build\test-coverage.out"
49+
DEL "build\main_test"
50+
DEL "build\cross-file-tests"
4951
) ELSE (
50-
echo "Unrecognized command %~1%"
51-
exit "1"
52+
echo "Unrecognized command %~1"
53+
EXIT /B 1
5254
)
53-
exit "0"
5455
EXIT /B 0
5556

5657

0 commit comments

Comments
 (0)