Skip to content

Commit

Permalink
Reformat Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
elysia-best committed Oct 18, 2024
1 parent 13dd1ee commit 6745db5
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 20 deletions.
6 changes: 0 additions & 6 deletions Configs/lingmo-archive-keyring.json

This file was deleted.

17 changes: 7 additions & 10 deletions Modules/BuildUtils.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Import-Module "$PSScriptRoot/GlobalConfig"
Import-Module "$PSScriptRoot/GitModule"
Import-Module "$PSScriptRoot/SourceRepoTools"
Import-Module "$PSScriptRoot/CommonUtils"

function Get-SudoPrivilege {
Write-Host "Now checking for root privileges."
Expand All @@ -28,22 +29,17 @@ function Get-SudoPrivilege {
function Install-GlobalDepends {
Write-Host "Installing Common build dependencies"

$Env:LC_ALL="C.UTF-8"
$env:LC_ALL="C.UTF-8"

sudo apt-get --yes install git devscripts equivs | Out-Null

# Assuming Windows has "LingmoOSBuildDeps" directory support
$repoPath = Import-LingmoRepo "https://github.com/LingmoOS/LingmoOSBuildDeps.git" "LingmoOSBuildDeps" $true
Set-Location $repoPath
sudo mk-build-deps -i -t "apt-get -y" -r | Out-Null
Start-ShellProcess "sudo" @("apt-get", "--yes", "install", "git devscripts equivs")
}

function Install-RepoDepends($repoPath) {
$Env:LC_ALL="C.UTF-8"
$env:LC_ALL="C.UTF-8"

# Assuming Windows has "LingmoOSBuildDeps" directory support
Set-Location $repoPath
sudo mk-build-deps -i -t "apt-get -y" -r | Out-Null
Start-ShellProcess "sudo" @("mk-build-deps", "-i -t", "`"apt-get -y`"", "-r")
}

function Start-CompileDeb($repo) {
Expand All @@ -55,7 +51,8 @@ function Start-CompileDeb($repo) {
Install-RepoDepends $repo.m_repoPath

Write-Host "Build $($repo.repoName) ..."
dpkg-buildpackage -b -uc -us -tc -j"$(nproc)" | Out-Null
$totalCPUS = (nproc).ToString()
Start-ShellProcess "dpkg-buildpackage" @("-b", "-uc", "-us", "-tc", "-j$($totalCPUS)")

Write-Host "$($repo.repoName) Complete!"

Expand Down
28 changes: 28 additions & 0 deletions Modules/CommonUtils.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<#
.DESCRIPTION
Contain commonly used funcions.
#>

<#
.DESCRIPTION
Execute a process and throw an error if not exit correctly
.OUTPUTS
True if sucess. Throw error if failed
#>
function Start-ShellProcess {
param (
[Parameter(Mandatory)]
[string] $execName,
[System.Collections.ArrayList] $params
)

$proc = Start-Process $execName -ArgumentList $params -Wait -PassThru

if ($proc.ExitCode -ne 0) {
# 如果非正常结束,就会报错
throw "Error executing $($repoURL) with param: $($cloneDst)"
}

return $true
}
Export-ModuleMember -Function Start-ShellProcess
7 changes: 5 additions & 2 deletions Modules/GitModule.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#>

Import-Module "$PSScriptRoot/GlobalConfig"
Import-Module "$PSScriptRoot/CommonUtils"

<#
.DESCRIPTION
Expand Down Expand Up @@ -44,9 +45,11 @@ function Import-LingmoRepo {
Remove-DirIfExist $cloneDst

if ($cloneDevGit -eq $true) {
git clone $repoURL $cloneDst | Out-Null
$params = @("clone", "$($repoURL)", "$($cloneDst)")
$ret = Start-ShellProcess "git" $params
} else {
git clone -b $Tag $repoURL $cloneDst | Out-Null
$params = @("clone", "-b", "$($Tag)", "$($repoURL)", "$($cloneDst)")
$ret = Start-ShellProcess "git" $params
}

return $cloneDst
Expand Down
4 changes: 2 additions & 2 deletions Modules/SourceRepoTools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ function Get-AllRepoConfigs {
$fullPath = "$(Get-ConfigPath)/$name"
$item = Get-ConfigFromFile $fullPath $cloneDevGit
if ($clone) {
$item.CloneRepo() | Out-Null
$item.CloneRepo()
}
$results.Add($item) | Out-Null
$results.Add($item)
}

return $results
Expand Down
1 change: 1 addition & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $LingMainScriptPath = $MyInvocation.MyCommand.Definition
$LingMainScriptDirectory = Split-Path $LingMainScriptPath -Parent

# Import modules
Import-Module (Join-Path $LingMainScriptDirectory "/Modules/CommonUtils")
Import-Module (Join-Path $LingMainScriptDirectory "/Modules/GlobalConfig")
Import-Module (Join-Path $LingMainScriptDirectory "/Modules/GitModule")
Import-Module (Join-Path $LingMainScriptDirectory "/Modules/SourceRepoTools")
Expand Down

0 comments on commit 6745db5

Please sign in to comment.