Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Commit

Permalink
Add support for Swift 5.1
Browse files Browse the repository at this point in the history
Run CI on Swift 5.1 and 5.2
  • Loading branch information
mattt committed Mar 27, 2020
1 parent 2c2e1ec commit 9a429d0
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 38 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,37 @@ jobs:
macos:
runs-on: macOS-latest

strategy:
matrix:
xcode: ["11.4", "11.3"]

steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install System Dependencies
if: matrix.xcode == '11.3'
run: brew bundle
- name: Build and Test
run: swift test
env:
DEVELOPER_DIR: /Applications/Xcode_11.4.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer

linux:
runs-on: ubuntu-latest

strategy:
matrix:
swift: ["5.2"]
swift: ["5.2", "5.1"]

container:
image: swift:${{ matrix.swift }}

steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install System Dependencies
run: |
apt-get update
apt-get install -y libxml2-dev
- name: Build and Test
run: swift test
run: swift test --enable-test-discovery
28 changes: 28 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Documentation

on:
push:
branches:
- master
paths:
- .github/workflows/documentation.yml
- Sources/**.swift

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1
- name: Generate Documentation
uses: SwiftDocOrg/swift-doc@master
with:
inputs: "Sources"
output: "Documentation"
- name: Upload Documentation to Wiki
uses: SwiftDocOrg/github-wiki-publish-action@master
with:
path: "Documentation"
env:
GITHUB_PERSONAL_ACCESS_TOKEN: ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN }}
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brew "libxml2", link: true
13 changes: 13 additions & 0 deletions Modules/libxml2-markup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef LIBXML2_MARKUP_H
#define LIBXML2_MARKUP_H
#import <libxml2/libxml/tree.h>
#import <libxml2/libxml/xmlreader.h>
#import <libxml2/libxml/xpath.h>
#import <libxml2/libxml/xpathInternals.h>
#import <libxml2/libxml/HTMLtree.h>
#import <libxml2/libxml/HTMLparser.h>
#import <libxml2/libxml/parser.h>
#import <libxml2/libxml/entities.h>
#import <libxml2/libxml/SAX.h>
#import <libxml2/libxml/SAX2.h>
#endif /* LIBXML2_MARKUP_H */
6 changes: 6 additions & 0 deletions Modules/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module libxml2 [system] {
link "xml2"
umbrella header "libxml2-markup.h"
export *
module * { export * }
}
31 changes: 18 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// swift-tools-version:5.2
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

var providers: [SystemPackageProvider] = [.apt(["libxml2-dev"])]
#if swift(<5.2)
providers += [.brew(["libxml2"])]
#endif

let package = Package(
name: "Markup",
products: [
Expand All @@ -18,30 +23,30 @@ let package = Package(
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.systemLibrary(
name: "libxml2",
path: "Modules",
pkgConfig: "libxml-2.0",
providers: providers
),
.target(
name: "DOM",
dependencies: [],
linkerSettings: [.linkedLibrary("xml2")]),
dependencies: ["libxml2"]),
.target(
name: "HTML",
dependencies: ["DOM", "XPath"],
linkerSettings: [.linkedLibrary("xml2")]),
dependencies: ["DOM", "XPath", "libxml2"]),
.target(
name: "XML",
dependencies: ["DOM", "XPath"],
linkerSettings: [.linkedLibrary("xml2")]),
dependencies: ["DOM", "XPath", "libxml2"]),
.target(
name: "XPath",
dependencies: ["DOM"],
linkerSettings: [.linkedLibrary("xml2")]),
dependencies: ["DOM", "libxml2"]),
.target(
name: "XInclude",
dependencies: [],
linkerSettings: [.linkedLibrary("xml2")]),
dependencies: ["libxml2"]),
.target(
name: "XSLT",
dependencies: [],
linkerSettings: [.linkedLibrary("xml2")]),
dependencies: ["libxml2"]),
.testTarget(
name: "HTMLTests",
dependencies: ["HTML"]),
Expand Down
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Markup

<!--
Pending Swift 5.2 support
![CI][ci badge]
[![Documentation][documentation badge]][documentation]
-->

A Swift package for working with HTML, XML, and other markup languages,
based on [libxml2][libxml2].
Expand All @@ -29,7 +26,8 @@ based on [libxml2][libxml2].
## Requirements

- Swift 5.2+ 👈❗️
- Swift 5.1+
- [libxml2][libxml2] _(except for macOS with Xcode 11.4 or later)_

## Usage

Expand Down Expand Up @@ -139,7 +137,19 @@ document.body?.description // =>

### Swift Package Manager

First, add the Markup package to your target dependencies in `Package.swift`:
If you're on Linux or if you're on macOS and using Xcode < 11.4,
install the [libxml2][libxml2] system library:

```terminal
# macOS for Xcode 11.3 and earlier
$ brew install libxml2
$ brew link --force libxml2
# Linux (Ubuntu)
$ sudo apt-get install libxml2-dev
```

Add the Markup package to your target dependencies in `Package.swift`:

```swift
import PackageDescription
Expand All @@ -155,7 +165,7 @@ let package = Package(
)
```

Next, add `Markup` as a dependency to your target(s):
Add `Markup` as a dependency to your target(s):

```swift
targets: [
Expand All @@ -164,8 +174,6 @@ targets: [
dependencies: ["Markup"]),
```

Finally, run the `swift build` command to build your project.

## License

MIT
Expand Down
2 changes: 1 addition & 1 deletion Sources/DOM/Comment.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import libxml2.tree
import libxml2

public final class Comment: Node {
public func remove() {
Expand Down
8 changes: 3 additions & 5 deletions Sources/DOM/Document.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import libxml2.tree
import libxml2
import Foundation

open class Document: Node {
Expand All @@ -18,10 +18,8 @@ open class Document: Node {
}

public var encoding: String.Encoding {
let encodingName = String(cString: xmlDoc.pointee.encoding)
let encoding = CFStringConvertIANACharSetNameToEncoding(encodingName as CFString?)
guard encoding != kCFStringEncodingInvalidId else { return .utf8 }
return String.Encoding(rawValue: UInt(CFStringConvertEncodingToNSStringEncoding(encoding)))
let ianaCharacterSetName = String(cString: xmlDoc.pointee.encoding)
return String.Encoding(ianaCharacterSetName: ianaCharacterSetName)
}

public var root: Element? {
Expand Down
2 changes: 1 addition & 1 deletion Sources/DOM/DocumentFragment.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import libxml2.tree
import libxml2
import Foundation

public final class DocumentFragment: Node {
Expand Down
2 changes: 1 addition & 1 deletion Sources/DOM/DocumentType.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import libxml2.tree
import libxml2

public final class DocumentType: Node {
public var name: String {
Expand Down
2 changes: 1 addition & 1 deletion Sources/DOM/Element.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import libxml2.tree
import libxml2

public final class Element: Node {
public enum CloningBehavior: Int32 {
Expand Down
30 changes: 30 additions & 0 deletions Sources/DOM/Extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,33 @@ extension String {
self.init(cString: xmlString)
}
}

// MARK: -

extension String.Encoding {
init(ianaCharacterSetName: String) {
switch ianaCharacterSetName {
case "us-ascii": self = .ascii
case "iso-2022-jp": self = .iso2022JP
case "iso-8859-1": self = .isoLatin1
case "iso-8859-2": self = .isoLatin2
case "euc-jp": self = .japaneseEUC
case "macintosh": self = .macOSRoman
case "x-nextstep": self = .nextstep
case "cp932": self = .shiftJIS
case "x-mac-symbol": self = .symbol
case "utf-8": self = .utf8
case "utf-16": self = .utf16
case "utf-16be": self = .utf16BigEndian
case "utf-32": self = .utf32
case "utf-32be": self = .utf32BigEndian
case "utf-32le": self = .utf32LittleEndian
case "windows-1250": self = .windowsCP1250
case "windows-1251": self = .windowsCP1251
case "windows-1252": self = .windowsCP1252
case "windows-1253": self = .windowsCP1253
case "windows-1254": self = .windowsCP1254
default: self = .utf8
}
}
}
2 changes: 1 addition & 1 deletion Sources/XML/Parser.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

import libxml2.parser
import libxml2

public enum Parser {
public struct Options: OptionSet {
Expand Down
2 changes: 1 addition & 1 deletion Sources/XPath/Expression.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import libxml2.xpath
import libxml2

public final class Expression: RawRepresentable {
public var rawValue: xmlXPathCompExprPtr
Expand Down
2 changes: 1 addition & 1 deletion Sources/XPath/NodeSet.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import libxml2.xpath
import libxml2

import DOM

Expand Down
2 changes: 1 addition & 1 deletion Sources/XPath/Object.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import libxml2.xpath
import libxml2

public enum Object: Hashable {
case nodeSet(NodeSet)
Expand Down
2 changes: 1 addition & 1 deletion Sources/XPath/XPath.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import libxml2.xpath
import libxml2

fileprivate var initialization: Void = { xmlXPathInit() }()

Expand Down

0 comments on commit 9a429d0

Please sign in to comment.