Skip to content

Commit

Permalink
Add setup_python3 for gclient
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Feb 16, 2024
1 parent 6759cc6 commit 6ab6bd1
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions 1k/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ $manifest = @{
gcc = '9.0.0+';
cmake = '3.28.1+';
ninja = '1.11.1+';
python = '3.9.0+';
jdk = '17.0.3+';
emsdk = '3.1.51';
cmdlinetools = '7.0+'; # android cmdlinetools
Expand Down Expand Up @@ -305,6 +306,18 @@ function eval($str, $raw = $false) {
}
}

function create_symlink($sourcePath, $destPath) {
# try link ninja exist cmake bin directory
& "$myRoot\fsync.ps1" -s $sourcePath -d $destPath -l $true 2>$null

if (!$? -and $IsWin) {
# try runas admin again
$mklink_args = "-Command ""& ""$myRoot\fsync.ps1"" -s '$sourcePath' -d '$destPath' -l `$true 2>`$null"""
Write-Host "mklink_args={$mklink_args}"
Start-Process powershell -ArgumentList $mklink_args -WindowStyle Hidden -Wait -Verb runas
}
}

$darwin_sim_suffix = ''
if ($TARGET_OS.EndsWith('-sim')) {
$TARGET_OS = $TARGET_OS.TrimEnd('-sim')
Expand Down Expand Up @@ -653,6 +666,25 @@ function setup_nuget() {
return $nuget_prog
}

# setup python3, not install automatically
# ensure python3.exe is python.exe to solve unexpected error, i.e.
# google gclient require python3.exe, on windows 10/11 will locate to
# a dummy C:\Users\halx99\AppData\Local\Microsoft\WindowsApps\python3.exe cause
# shit strange error
function setup_python3() {
if (!$manifest['python']) { return $null }
$python_prog, $python_ver = find_prog -name 'python'
if(!$python_prog) {
throw "python $($manifest['python']) required!"
}

$python3_prog, $_ = find_prog -name 'python' -cmd 'python3' -silent $true
if(!$python3_prog) {
$python3_prog = Join-Path (Split-Path $python_prog -Parent) (Split-Path $python_prog -Leaf).Replace('python', 'python3')
create_symlink $python_prog $python3_prog
}
}

# setup glslcc, not add to path
function setup_glslcc() {
if (!$manifest['glslcc']) { return $null }
Expand Down Expand Up @@ -786,14 +818,7 @@ function ensure_cmake_ninja($cmake_prog, $ninja_prog) {
if (!$cmake_ninja_prog) {
$ninja_symlink_target = Join-Path $cmake_bin (Split-Path $ninja_prog -Leaf)
# try link ninja exist cmake bin directory
& "$myRoot\fsync.ps1" -s $ninja_prog -d $ninja_symlink_target -l $true 2>$null

if (!$? -and $IsWin) {
# try runas admin again
$mklink_args = "-Command ""& ""$myRoot\fsync.ps1"" -s '$ninja_prog' -d '$ninja_symlink_target' -l `$true 2>`$null"""
Write-Host "mklink_args={$mklink_args}"
Start-Process powershell -ArgumentList $mklink_args -WindowStyle Hidden -Wait -Verb runas
}
create_symlink $ninja_prog $ninja_symlink_target
}
return $?
}
Expand Down Expand Up @@ -1158,6 +1183,8 @@ function setup_gclient() {
setup_msvc
}

setup_python3

# setup gclient tool
# download depot_tools
# git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $gclient_dir
Expand Down Expand Up @@ -1737,7 +1764,7 @@ if (!$setupOnly) {

Write-Output ("gn_buildargs_overrides=$gn_buildargs_overrides, Count={0}" -f $gn_buildargs_overrides.Count)

$BUILD_DIR = resolve_out_dir $null 'build'
$BUILD_DIR = resolve_out_dir $null 'out/'

if ($rebuild) {
$b1k.rmdirs($BUILD_DIR)
Expand Down

0 comments on commit 6ab6bd1

Please sign in to comment.