Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions cbake.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ function Convert-CBakeSymbolicLinks() {
$Target = Join-Path $RootPath $_.LinkTarget.TrimStart('/')
if (Test-Path -LiteralPath $Target) {
$RelativeTarget = [IO.Path]::GetRelativePath($Directory, $Target)
Remove-Item -LiteralPath $Source | Out-Null
if ($IsLinux) {
Invoke-CBakeNativeCommand -FilePath 'rm' -ArgumentList @('-f', '--', $Source)
} else {
Remove-Item -LiteralPath $Source | Out-Null
}
if ($IsDirectory) {
[IO.Directory]::CreateSymbolicLink($Source, $RelativeTarget) | Out-Null
} else {
[IO.File]::CreateSymbolicLink($Source, $RelativeTarget) | Out-Null
}
} else {
Remove-Item -LiteralPath $Source -ErrorAction 'SilentlyContinue' | Out-Null
if ($IsLinux) {
Invoke-CBakeNativeCommand -FilePath 'rm' -ArgumentList @('-f', '--', $Source)
} else {
Remove-Item -LiteralPath $Source -ErrorAction 'SilentlyContinue' | Out-Null
}
}
}
}
Expand Down Expand Up @@ -106,6 +114,9 @@ function Remove-CBakeExcludedFiles() {

$ExcludeDirs | ForEach-Object {
$ExcludeDir = Join-Path $RootPath $_.TrimStart('/', '\')
if ($IsLinux -and (Test-Path -LiteralPath $ExcludeDir)) {
Invoke-CBakeNativeCommand -FilePath 'chmod' -ArgumentList @('-R', 'u+w', '--', $ExcludeDir)
}
Remove-Item -LiteralPath $ExcludeDir -Recurse -Force -ErrorAction 'SilentlyContinue' | Out-Null
}
}
Expand All @@ -117,6 +128,10 @@ function Optimize-CBakeSysroot() {
[string] $RootPath
)

if ($IsLinux) {
Invoke-CBakeNativeCommand -FilePath 'chmod' -ArgumentList @('-R', 'u+w', '--', $RootPath)
}

Convert-CBakeSymbolicLinks $RootPath
Remove-CBakeExcludedFiles $RootPath

Expand Down
7 changes: 5 additions & 2 deletions recipes/debian-10/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ FROM debian:buster-slim

ARG DEBIAN_FRONTEND=noninteractive

RUN sed -i 's/deb.debian.com/debian.mirrors.ovh.net/g' /etc/apt/sources.list
RUN apt-get update -y
RUN printf '%s\n' \
'deb http://archive.debian.org/debian buster main' \
'deb http://archive.debian.org/debian-security buster/updates main' \
> /etc/apt/sources.list
RUN apt-get -o Acquire::Check-Valid-Until=false update -y

RUN apt-get install --no-install-recommends -y \
gcc \
Expand Down
2 changes: 1 addition & 1 deletion recipes/rhel8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN yum update -y

RUN yum install -y \
gcc \
g++ \
gcc-c++ \
zlib-devel \
openssl-devel \
pam \
Expand Down
26 changes: 26 additions & 0 deletions tests/CBake.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ Describe 'Convert-CBakeSymbolicLinks' {
$Link.LinkTarget | Should -Be 'target'
$Link.ResolveLinkTarget($true).FullName | Should -Be $TargetPath
}

It 'converts symlinks from a read-only sysroot on Linux' -Skip:(-not $IsLinux) {
$RootPath = Join-Path $TestDrive 'sysroot'
$TargetPath = Join-Path $RootPath 'target'
$SourcePath = Join-Path $RootPath 'link'
New-Item -Path $TargetPath -ItemType Directory -Force | Out-Null
[IO.Directory]::CreateSymbolicLink($SourcePath, '/target') | Out-Null
& chmod 'a-w' $RootPath

Optimize-CBakeSysroot $RootPath

(Get-Item -LiteralPath $SourcePath).LinkTarget | Should -Be 'target'
}
}

Describe 'Remove-CBakeExcludedFiles' {
Expand All @@ -96,6 +109,19 @@ Describe 'Remove-CBakeExcludedFiles' {

Test-Path -LiteralPath $ExcludedPath | Should -BeFalse
}

It 'removes read-only excluded directories on Linux' -Skip:(-not $IsLinux) {
$RootPath = Join-Path $TestDrive 'sysroot'
$ExcludedPath = Join-Path $RootPath 'usr\bin'
$ExcludedFile = Join-Path $ExcludedPath 'tool'
New-Item -Path $ExcludedPath -ItemType Directory -Force | Out-Null
New-Item -Path $ExcludedFile -ItemType File -Force | Out-Null
& chmod 'a-w' $ExcludedPath

Remove-CBakeExcludedFiles $RootPath

Test-Path -LiteralPath $ExcludedPath | Should -BeFalse
}
}

Describe 'Invoke-CBakeNativeCommand' {
Expand Down
Loading