2022-05-06 09:36:47 +08:00
import { Inputs , Opts } from "./main"
2022-05-26 06:45:24 +08:00
// passing "" to a tool installed by a package manager (apt, brew, choco) will result in the default version of that package manager.
// the directly downloaded tools require a given version ("" doesn't work).
2021-09-16 19:36:35 +08:00
const DefaultVersions : Record < string , string > = {
2022-04-28 03:41:21 +08:00
llvm : "13.0.0" , // https://github.com/llvm/llvm-project/releases
clangtidy : "13.0.0" ,
clangformat : "13.0.0" ,
2022-03-02 06:01:08 +08:00
ninja : "1.10.2" , // https://github.com/ninja-build/ninja/releases
2022-04-16 15:49:19 +08:00
cmake : "3.23.1" , // https://github.com/Kitware/CMake/releases
2022-05-15 18:58:11 +08:00
gcovr : "5.1" , // https://pypi.org/project/gcovr/
conan : "1.48.0" , // https://github.com/conan-io/conan/releases
meson : "0.62.1" , // https://github.com/mesonbuild/meson/releases
2022-05-26 06:45:24 +08:00
python : "3.8.10" , // semver
2022-04-16 17:25:25 +08:00
kcov : "40" , // https://github.com/SimonKagstrom/kcov/releases
2022-05-15 18:58:11 +08:00
task : "3.12.1" , // https://github.com/go-task/task/releases
2022-05-06 11:21:32 +08:00
doxygen : process.platform === "darwin" ? "1.9.3" : "1.9.4" , // https://www.doxygen.nl/download.html // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=doxygen
2022-05-21 06:58:11 +08:00
gcc : "11" , // https://github.com/brechtsanders/winlibs_mingw/releases and // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=gcc
2021-09-16 19:36:35 +08:00
}
2022-05-21 11:00:30 +08:00
/// If an ubuntu versions is not in this map:
// - the newer ubuntu versions use the first entry (e.g. v20),
// - the older ones use ""
const DefaultUbuntuVersion : Record < string , Record < number , string > > = {
llvm : {
20 : "13.0.0-ubuntu-20.04" ,
18 : "13.0.1-ubuntu-18.04" ,
16 : "13.0.0-ubuntu-16.04" ,
2022-05-26 06:45:24 +08:00
14 : "13.0.0-ubuntu-16.04" ,
2022-05-21 11:00:30 +08:00
} ,
clangtidy : {
20 : "13.0.0-ubuntu-20.04" ,
18 : "13.0.1-ubuntu-18.04" ,
16 : "13.0.0-ubuntu-16.04" ,
2022-05-26 06:45:24 +08:00
14 : "13.0.0-ubuntu-16.04" ,
2022-05-21 11:00:30 +08:00
} ,
clangformat : {
20 : "13.0.0-ubuntu-20.04" ,
18 : "13.0.1-ubuntu-18.04" ,
16 : "13.0.0-ubuntu-16.04" ,
2022-05-26 06:45:24 +08:00
14 : "13.0.0-ubuntu-16.04" ,
2022-05-21 11:00:30 +08:00
} ,
gcovr : {
20 : "5.1" ,
18 : "5.0" ,
} ,
meson : {
20 : "0.62.1" ,
18 : "0.61.4" ,
} ,
doxygen : {
20 : "1.9.4" ,
} ,
}
2021-09-16 19:36:35 +08:00
/** Get the default version if passed true or undefined, otherwise return the version itself */
2022-05-06 08:11:42 +08:00
export function getVersion ( name : string , version : string | undefined , osVersion : number [ ] | null = null ) {
2022-05-06 09:36:47 +08:00
if ( useDefault ( version , name ) ) {
2022-05-21 09:51:32 +08:00
// choose the default linux version based on ubuntu version
2022-05-21 11:00:30 +08:00
if ( process . platform === "linux" && osVersion !== null && name in DefaultUbuntuVersion ) {
const osVersionMaj = osVersion [ 0 ]
const newest = parseInt ( Object . keys ( DefaultUbuntuVersion [ name ] ) [ 0 ] , 10 ) // newest version with the default
if ( osVersionMaj >= newest ) {
return DefaultUbuntuVersion [ name ] [ osVersionMaj ]
2022-05-21 10:16:58 +08:00
} else {
2022-05-21 11:00:30 +08:00
return ""
2022-05-21 09:51:32 +08:00
}
2022-05-03 14:32:01 +08:00
}
2022-05-03 15:46:03 +08:00
// anything else
return DefaultVersions [ name ]
} else {
return version ? ? ""
2022-05-03 14:32:01 +08:00
}
}
2022-05-06 09:36:47 +08:00
function useDefault ( version : string | undefined , name : string ) {
return version === "true" || ( version === undefined && name in DefaultVersions )
}
export function syncVersions ( opts : Opts , tools : Inputs [ ] ) : boolean {
for ( let i = 0 ; i < tools . length ; i ++ ) {
// tools excluding i_tool
const otherTools = tools . slice ( 0 , i ) . concat ( tools . slice ( i + 1 ) )
const tool = tools [ i ]
if ( ! useDefault ( opts [ tool ] , tool ) ) {
for ( let i_other = 0 ; i_other < otherTools . length ; i_other ++ ) {
const otherTool = otherTools [ i_other ]
const useDefaultOtherTool = useDefault ( opts [ otherTool ] , otherTools [ i_other ] )
if ( useDefaultOtherTool ) {
// use the same version if the other tool was requested with the default
opts [ otherTool ] = opts [ tool ]
} else if ( opts [ tool ] !== opts [ otherTools [ i_other ] ] ) {
// error if different from the other given versions
return false
}
}
}
}
return true
}