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
68 changes: 68 additions & 0 deletions .swift-format-nolint
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentation" : {
"spaces" : 4
},
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 180,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLowerCamelCase" : false,
"AmbiguousTrailingClosureOverload" : false,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : false,
"FileScopedDeclarationPrivacy" : false,
"FullyIndirectEnum" : false,
"GroupNumericLiterals" : false,
"IdentifiersMustBeASCII" : false,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : false,
"NoAssignmentInExpressions" : false,
"NoBlockComments" : false,
"NoCasesWithOnlyFallthrough" : false,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : false,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoPlaygroundLiterals" : false,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : false,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : false,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : false,
"ReturnVoidInsteadOfEmptyTuple" : false,
"TypeNamesShouldBeCapitalized" : false,
"UseEarlyExits" : false,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : true,
"UseSynthesizedInitializer" : false,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
},
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 2,
"version" : 1
}
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ ifeq (,$(wildcard bin/vmlinux))
@cp .local/vmlinux bin/vmlinux
endif

.PHONY: check
check: swift-fmt-check check-licenses

.PHONY: fmt
fmt: swift-fmt update-licenses

Expand All @@ -135,6 +138,10 @@ swift-fmt:
@echo Applying the standard code formatting...
@$(SWIFT) format --recursive --configuration .swift-format -i $(SWIFT_SRC)

swift-fmt-check:
@echo Applying the standard code formatting...
@$(SWIFT) format lint --recursive --strict --configuration .swift-format-nolint $(SWIFT_SRC)

.PHONY: update-licenses
update-licenses:
@echo Updating license headers...
Expand All @@ -147,6 +154,15 @@ check-licenses:
@./scripts/ensure-hawkeye-exists.sh
@.local/bin/hawkeye check --fail-if-unknown

.PHONY: pre-commit
pre-commit:
cp Scripts/pre-commit.fmt .git/hooks
touch .git/hooks/pre-commit
cat .git/hooks/pre-commit | grep -v 'hooks/pre-commit\.fmt' > /tmp/pre-commit.new || true
echo 'PRECOMMIT_NOFMT=$${PRECOMMIT_NOFMT} $$(git rev-parse --show-toplevel)/.git/hooks/pre-commit.fmt' >> /tmp/pre-commit.new
mv /tmp/pre-commit.new .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

.PHONY: serve-docs
serve-docs:
@echo 'to browse: open http://127.0.0.1:8000/containerization/documentation/'
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ make protos

If you'd like to build your own kernel please see the instructions in the [kernel directory](./kernel/README.md).

## Pre-commit hook

Run `make pre-commit` to install a pre-commit hook that ensures that your changes have correct formatting and license headers when you run `git commit`.

## Documentation

Generate the API documentation for local viewing with:
Expand Down
26 changes: 12 additions & 14 deletions Sources/ContainerizationOCI/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,18 @@ public struct Platform: Sendable, Equatable {
}

extension Platform: Hashable {
/**
`~=` compares two platforms to check if **lhs** platform images are compatible with **rhs** platform
This operator can be used to check if an image of **lhs** platform can run on **rhs**:
- `true`: when **rhs**=`arm/v8`, **lhs** is any of `arm/v8`, `arm/v7`, `arm/v6` and `arm/v5`
- `true`: when **rhs**=`arm/v7`, **lhs** is any of `arm/v7`, `arm/v6` and `arm/v5`
- `true`: when **rhs**=`arm/v6`, **lhs** is any of `arm/v6` and `arm/v5`
- `true`: when **rhs**=`amd64`, **lhs** is any of `amd64` and `386`
- `true`: when **rhs**=**lhs**
- `false`: otherwise
- Parameters:
- lhs: platform whose compatibility is being checked
- rhs: platform against which compatibility is being checked
- Returns: `true | false`
*/
/// `~=` compares two platforms to check if **lhs** platform images are compatible with **rhs** platform
/// This operator can be used to check if an image of **lhs** platform can run on **rhs**:
/// - `true`: when **rhs**=`arm/v8`, **lhs** is any of `arm/v8`, `arm/v7`, `arm/v6` and `arm/v5`
/// - `true`: when **rhs**=`arm/v7`, **lhs** is any of `arm/v7`, `arm/v6` and `arm/v5`
/// - `true`: when **rhs**=`arm/v6`, **lhs** is any of `arm/v6` and `arm/v5`
/// - `true`: when **rhs**=`amd64`, **lhs** is any of `amd64` and `386`
/// - `true`: when **rhs**=**lhs**
/// - `false`: otherwise
/// - Parameters:
/// - lhs: platform whose compatibility is being checked
/// - rhs: platform against which compatibility is being checked
/// - Returns: `true | false`
public static func ~= (lhs: Platform, rhs: Platform) -> Bool {
if lhs.os == rhs.os {
if lhs._rawArch == rhs._rawArch {
Expand Down
16 changes: 16 additions & 0 deletions scripts/pre-commit.fmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /bin/bash -e

setup_error() {
echo failed to run: $1 1>&2
echo run '"make pre-commit"' and try again 1>&2
exit 1
}

if [ ! -z "${PRECOMMIT_NOFMT}" ] ; then
exit 0
fi

echo checking formatting and licenses 1>&2
project_pathname=$(git rev-parse --show-toplevel)
cd "${project_pathname}"
make check