Skip to content

Commit

Permalink
Major Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LebJe committed Dec 11, 2023
1 parent cfd9cae commit 29692f4
Show file tree
Hide file tree
Showing 36 changed files with 926 additions and 897 deletions.
100 changes: 2 additions & 98 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,101 +3,5 @@ name: "Build and Test"
on: ["push", "pull_request"]

jobs:
TestOnMacOS-10_15-x86_64:
runs-on: "macos-10.15"
steps:
- uses: "actions/checkout@v2"
- name: "Run tests"
run: "swift test"
# - name: "Test CreateReadWrite"
# run: |
# cd Examples/CreateReadWrite
# swift build
# ./.build/debug/create Package.swift Sources/ Sources/ExtractArchive/ Sources/ExtractArchive/main.swift
# ./.build/debug/read output.cpio
# mkdir outputCPIOExtractFolder
# cd outputCPIOExtractFolder
# ./../.build/debug/extract ../output.cpio
# ls -lahR
TestOnMacOS-11_0-x86_64:
runs-on: "macos-11.0"
steps:
- uses: "actions/checkout@v2"
- name: "Run tests"
run: "swift test"
# - name: "Test CreateReadWrite"
# run: |
# cd Examples/CreateReadWrite
# swift build
# ./.build/debug/create Package.swift Sources/ Sources/ExtractArchive/ Sources/ExtractArchive/main.swift
# ./.build/debug/read output.cpio
# mkdir outputCPIOExtractFolder
# cd outputCPIOExtractFolder
# ./../.build/debug/extract ../output.cpio
# ls -lahR
# TestOnUbuntu-20_04-ARM:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: uraimo/[email protected]
# with:
# arch: aarch64
# distro: ubuntu20.04
# githubToken: ${{ secrets.GITHUB_TOKEN }}
# run: |
# export DEBIAN_FRONTEND=noninteractive
# apt update -q
# apt install -yq curl sudo
# curl -s https://packagecloud.io/install/repositories/swift-arm/release/script.deb.sh | sudo bash
# apt install -yq swiftlang
# apt update -yq
# swift test
TestOnUbuntu-20_04-x86_64:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- name: "Run tests"
run: "swift test"
- name: "Test CreateReadWrite"
run: |
cd Examples/CreateReadWrite
swift build
./.build/debug/create Package.swift Sources/ Sources/ExtractArchive/ Sources/ExtractArchive/main.swift
./.build/debug/read output.cpio
mkdir outputCPIOExtractFolder
cd outputCPIOExtractFolder
./../.build/debug/extract ../output.cpio
ls -lahR
TestOnWindows10-x86_64:
runs-on: "windows-latest"
steps:
- uses: "actions/checkout@v2"
- uses: "seanmiddleditch/gha-setup-vsdevenv@master"
- name: "Install swift-5.4-RELEASE"
run: 'Install-Binary -Url "https://swift.org/builds/swift-5.4.2-release/windows10/swift-5.4.2-RELEASE/swift-5.4.2-RELEASE-windows10.exe" -Name "installer.exe" -ArgumentList ("-q")'
- name: "Set Environment Variables"
run: |
echo "SDKROOT=C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "DEVELOPER_DIR=C:\Library\Developer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: "Adjust Paths"
run: 'echo "C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin;C:\Library\Swift-development\bin;C:\Library\icu-67\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append'
- name: "Install Supporting Files"
shell: "cmd"
run: |
copy "%SDKROOT%\usr\share\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
copy "%SDKROOT%\usr\share\visualc.modulemap" "%VCToolsInstallDir%\include\module.modulemap"
copy "%SDKROOT%\usr\share\visualc.apinotes" "%VCToolsInstallDir%\include\visualc.apinotes"
copy "%SDKROOT%\usr\share\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"
- name: "Build"
run: "swift build"
# - name: "Test CreateReadWrite"
# run: |
# cd Examples/CreateReadWrite
# ls
# swift build
TestBuildingOnMacOS-11_0-ARM64:
runs-on: "macos-11.0"
steps:
- uses: "actions/checkout@v2"
- name: "Test Building For ARM"
run: "swift build --arch arm64 && swift build --package-path Examples/CreateReadWrite --arch arm64"
"BuildAndTest":
uses: LebJe/SwiftWorkflows/.github/workflows/buildAndTest.yml@main
22 changes: 4 additions & 18 deletions .github/workflows/generateDocumentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,7 @@ on:

jobs:
"GenerateDocumentation":
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- name: "Generate Documentation"
uses: "SwiftDocOrg/swift-doc@master"
with:
inputs: "Sources"
module-name: "CPIOArchiveKit"
format: "html"
base-url: "https://lebje.github.io/CPIOArchiveKit/"
output: "./.build/documentation"
- name: "Change Permissions"
run: "sudo chmod o+r -R ./.build/documentation"
- name: "Deploy to GitHub Pages"
uses: "peaceiris/actions-gh-pages@v3"
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: "./.build/documentation"
uses: LebJe/SwiftWorkflows/.github/workflows/generateDocumentation.yml@main
with:
TargetName: "CPIOArchiveKit"
DoccBundlePath: "Sources/CPIOArchiveKit/CPIOArchiveKit.docc"
12 changes: 12 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: "Run Pre-Commit"

on: "pull_request"

jobs:
PreCommit:
runs-on: "macos-latest"
steps:
- uses: "actions/checkout@v4"
- name: "Install Dependencies"
run: "brew bundle"
- uses: "LebJe/[email protected]"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ Package.resolved
Brewfile.lock.json
Examples/CreateReadWrite/.swiftpm
Examples/CreateReadWrite/.build
.vscode
node_modules
docs
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ repos:
- id: "swift-format"
name: "Format Swift"
- repo: "https://github.com/pre-commit/mirrors-prettier"
rev: "4309ae0bc8b9f39c207bca9c5040ec8a35561a41"
rev: "v4.0.0-alpha.4"
hooks:
- id: "prettier"
name: "Format Markdown"
tags: ["md"]
exclude: "Sources/CPIOArchiveKit/CPIOArchiveKit.docc/"
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"singleQuote": false,
"useTabs": true
}
4 changes: 0 additions & 4 deletions .prettierrc.toml

This file was deleted.

4 changes: 4 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: ["CPIOArchiveKit"]
9 changes: 5 additions & 4 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--swiftversion 5.3
--swiftversion 5.5
--binarygrouping none
--decimalgrouping none
--hexgrouping none
Expand All @@ -8,11 +8,12 @@
--octalgrouping none
--self insert
--semicolons never
--stripunusedargs unnamed-only
--stripunusedargs closure-only
--wraparguments before-first
--wrapparameters before-first
--disable trailingClosures, typeSugar
--header "Copyright (c) 2021 Jeff Lebrun \n\n \
--maxwidth 120
--header "Copyright (c) 2023 Jeff Lebrun \n\n \
Licensed under the MIT License. \n\n \
The full text of the license can be found in the file named LICENSE.
"
"
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.0](https://github.com/LebJe/CPIOArchiveKit/releases/tag/0.2.0) - 2023-12-10

### Added

- `CPIOArchiveType.svr4WithCRC`
- `CPIOArchiveError.missingOrInvalidChecksum(CPIOArchive.Header)`
- DocC documentation

### Changed

- Merged `CPIOArchiveReader/Writer` into `CPIOArchive`
- `Header` is nested under `CPIOArchive` (`CPIOArchive.Header`)
- Update to Swift 5.5

#### Renamed

- `FileMode` -> `CPIOFileMode`
- `FileType` -> `CPIOFileType`
- `

## [0.1.0](https://github.com/LebJe/CPIOArchiveKit/releases/tag/0.1.0) - 2021-07-21

### Added
Expand Down
2 changes: 1 addition & 1 deletion Examples/CreateReadWrite/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:5.5

import PackageDescription

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Jeff Lebrun
// Copyright (c) 2023 Jeff Lebrun
//
// Licensed under the MIT License.
//
Expand Down
96 changes: 52 additions & 44 deletions Examples/CreateReadWrite/Sources/CreateArchive/main.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Jeff Lebrun
// Copyright (c) 2023 Jeff Lebrun
//
// Licensed under the MIT License.
//
Expand All @@ -18,18 +18,21 @@ enum ItemType {
case file, dir, symlink
}

let usage = "USAGE: \(CommandLine.arguments[0]) [--help, -h, -?] <files...>\n\nCreate a cpio archive from a list of files and/or directories."
let usage =
"USAGE: \(CommandLine.arguments[0]) [--help, -h, -?] <files...>\n\nCreate a cpio archive from a list of files and/or directories."

if CommandLine.argc == 1 {
print(usage)
exit(1)
} else if CommandLine.arguments.contains("-h") || CommandLine.arguments.contains("-?") || CommandLine.arguments.contains("--help") {
} else if CommandLine.arguments.contains("-h") || CommandLine.arguments.contains("-?") || CommandLine.arguments
.contains("--help")
{
print(usage)
exit(0)
}

let items = Array(CommandLine.arguments.dropFirst())
var writer = CPIOArchiveWriter()
var archive = CPIOArchive()

for item in items {
// Open `item`.
Expand Down Expand Up @@ -88,49 +91,54 @@ for item in items {

switch type {
case .file:
writer.addFile(
header: Header(
name: item,
userID: Int(stat.st_uid),
groupID: Int(stat.st_gid),
mode: FileMode(UInt32(stat.st_mode), modes: [.regular, .setUID, .setGID]),
modificationTime: Int(statTime),
inode: Int(stat.st_ino),
links: Int(stat.st_nlink),
dev: (major: Int(stat.st_dev & 0xFF), minor: Int(stat.st_dev >> 8 & 0xFF)),
rDev: (major: Int(stat.st_rdev & 0xFF), minor: Int(stat.st_rdev >> 8 & 0xFF))
),
contents: bytes
archive.files.append(
.init(
header: CPIOArchive.Header(
name: item,
userID: Int(stat.st_uid),
groupID: Int(stat.st_gid),
mode: CPIOFileMode(UInt32(stat.st_mode), modes: [.regular, .setUID, .setGID]),
modificationTime: Int(statTime),
inode: Int(stat.st_ino),
links: Int(stat.st_nlink),
dev: (major: Int(stat.st_dev & 0xFF), minor: Int(stat.st_dev >> 8 & 0xFF)),
rDev: (major: Int(stat.st_rdev & 0xFF), minor: Int(stat.st_rdev >> 8 & 0xFF))
),
contents: bytes
)
)
case .dir:
writer.addFile(
header: Header(
name: item,
userID: Int(stat.st_uid),
groupID: Int(stat.st_gid),
mode: FileMode(UInt32(stat.st_mode), modes: [.directory, .setUID, .setGID]),
modificationTime: Int(statTime),
inode: Int(stat.st_ino),
links: Int(stat.st_nlink),
dev: (major: Int(stat.st_dev & 0xFF), minor: Int(stat.st_dev >> 8 & 0xFF)),
rDev: (major: Int(stat.st_rdev & 0xFF), minor: Int(stat.st_rdev >> 8 & 0xFF))
),
contents: []
archive.files.append(
.init(
header: CPIOArchive.Header(
name: item,
userID: Int(stat.st_uid),
groupID: Int(stat.st_gid),
mode: CPIOFileMode(UInt32(stat.st_mode), modes: [.directory, .setUID, .setGID]),
modificationTime: Int(statTime),
inode: Int(stat.st_ino),
links: Int(stat.st_nlink),
dev: (major: Int(stat.st_dev & 0xFF), minor: Int(stat.st_dev >> 8 & 0xFF)),
rDev: (major: Int(stat.st_rdev & 0xFF), minor: Int(stat.st_rdev >> 8 & 0xFF))
)
)
)
case .symlink:
writer.addFile(
header: Header(
name: item,
userID: Int(stat.st_uid),
groupID: Int(stat.st_gid),
mode: FileMode(UInt32(stat.st_mode), modes: [.symlink, .setUID, .setGID]),
modificationTime: Int(statTime),
inode: Int(stat.st_ino),
links: Int(stat.st_nlink),
dev: (major: Int(stat.st_dev & 0xFF), minor: Int(stat.st_dev >> 8 & 0xFF)),
rDev: (major: Int(stat.st_rdev & 0xFF), minor: Int(stat.st_rdev >> 8 & 0xFF))
),
contents: bytes
archive.files.append(
.init(
header: CPIOArchive.Header(
name: item,
userID: Int(stat.st_uid),
groupID: Int(stat.st_gid),
mode: CPIOFileMode(UInt32(stat.st_mode), modes: [.symlink, .setUID, .setGID]),
modificationTime: Int(statTime),
inode: Int(stat.st_ino),
links: Int(stat.st_nlink),
dev: (major: Int(stat.st_dev & 0xFF), minor: Int(stat.st_dev >> 8 & 0xFF)),
rDev: (major: Int(stat.st_rdev & 0xFF), minor: Int(stat.st_rdev >> 8 & 0xFF))
),
contents: bytes
)
)
}

Expand All @@ -142,7 +150,7 @@ guard let fp = fopen("output.cpio", "wb") else {
exit(4)
}

let bytes = writer.finalize()
let bytes = archive.serialize()

if bytes.withUnsafeBytes({ write(fileno(fp), $0.baseAddress!, bytes.count) }) != -1 {
print("Successfully wrote output.cpio!")
Expand Down
Loading

0 comments on commit 29692f4

Please sign in to comment.