Skip to content

Commit 5ab9441

Browse files
authored
Merge pull request #2983 from abertelrud/eng/define-libswiftpmdatamodel-product
Define libSwiftPMDataModel for clients that want the libSwiftPM data model but not the build system
2 parents 8047543 + 1a34791 commit 5ab9441

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

Documentation/libSwiftPM.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ SwiftPM has a library based architecture and the top-level library product is
66
called `libSwiftPM`. Other packages can add SwiftPM as a package dependency and
77
create powerful custom build tools on top of `libSwiftPM`.
88

9+
A subset of `libSwiftPM` that includes only the data model (without SwiftPM's
10+
build system) is available as `libSwiftPMDataModel`. Any one client should
11+
depend on one or the other, but not both.
12+
913
The SwiftPM repository contains an [example](https://github.com/apple/swift-package-manager/tree/master/Examples/package-info) that demonstrates the use of
1014
`libSwiftPM` in a Swift package. Use the following commands to run the example
1115
package:

Package.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
This source file is part of the Swift.org open source project
55

6-
Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
77
Licensed under Apache License v2.0 with Runtime Library Exception
88

99
See http://swift.org/LICENSE.txt for license information
@@ -28,7 +28,8 @@ let package = Package(
2828
platforms: [macOSPlatform],
2929
products: [
3030
// The `libSwiftPM` set of interfaces to programatically work with Swift
31-
// packages.
31+
// packages. `libSwiftPM` includes all of the SwiftPM code except the
32+
// command line tools, while `libSwiftPM` includes only the data model.
3233
//
3334
// NOTE: This API is *unstable* and may change at any time.
3435
.library(
@@ -60,6 +61,18 @@ let package = Package(
6061
"Workspace"
6162
]
6263
),
64+
.library(
65+
name: "SwiftPMDataModel",
66+
type: .dynamic,
67+
targets: [
68+
"SourceControl",
69+
"PackageModel",
70+
"PackageLoading",
71+
"PackageGraph",
72+
"Xcodeproj",
73+
"Workspace"
74+
]
75+
),
6376

6477
.library(
6578
name: "XCBuildSupport",

Utilities/bootstrap

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ def add_build_args(parser):
123123
"--libswiftpm-install-dir",
124124
metavar='PATH',
125125
help="where to install libSwiftPM")
126+
parser.add_argument(
127+
"--libswiftpmdatamodel-install-dir",
128+
metavar='PATH',
129+
help="where to install libSwiftPMDataModel")
126130
parser.add_argument(
127131
"--prefix",
128132
dest="install_prefixes",
@@ -344,11 +348,6 @@ def install(args):
344348

345349
# Install libSwiftPM if an install directory was provided.
346350
if args.libswiftpm_install_dir:
347-
dest = args.libswiftpm_install_dir
348-
349-
# FIXME: Don't hardcode the suffix.
350-
install_binary(args, "libSwiftPM.dylib", dest)
351-
352351
libswiftpm_modules = [
353352
"TSCLibc", "TSCBasic",
354353
"TSCUtility", "SourceControl",
@@ -357,17 +356,18 @@ def install(args):
357356
"PackageGraph", "SPMBuildCore", "Build",
358357
"Xcodeproj", "Workspace"
359358
]
359+
install_libswiftpm_dylib(args, "SwiftPM", args.libswiftpm_install_dir, libswiftpm_modules)
360360

361-
# Install the swiftmodule and swiftdoc files.
362-
for module in libswiftpm_modules:
363-
install_binary(args, module + ".swiftmodule", dest)
364-
if not args.cross_compile_hosts: # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
365-
install_binary(args, module + ".swiftdoc", dest)
366-
367-
# Install the C headers.
368-
tscclibc_include_dir = os.path.join(args.tsc_source_dir, "Sources/TSCclibc/include")
369-
tscclibc_include_dir_dest = os.path.join(dest, "TSCclibc")
370-
dir_util.copy_tree(tscclibc_include_dir, tscclibc_include_dir_dest)
361+
# Install libSwiftPMDataModel if an install directory was provided.
362+
if args.libswiftpmdatamodel_install_dir:
363+
libswiftpmdatamodel_modules = [
364+
"TSCLibc", "TSCBasic",
365+
"TSCUtility", "SourceControl",
366+
"PackageModel", "PackageLoading",
367+
"PackageGraph", "SPMBuildCore",
368+
"Xcodeproj", "Workspace"
369+
]
370+
install_libswiftpm_dylib(args, "SwiftPMDataModel", args.libswiftpmdatamodel_install_dir, libswiftpmdatamodel_modules)
371371

372372
def install_swiftpm(prefix, args):
373373
# Install swiftpm binaries.
@@ -401,6 +401,22 @@ def install_swiftpm(prefix, args):
401401
file_util.copy_file(src, dest, update=1)
402402

403403

404+
def install_libswiftpm_dylib(args, library_name, install_dir, module_names):
405+
# FIXME: Don't hardcode the prefix and suffix.
406+
install_binary(args, "lib" + library_name + ".dylib", install_dir)
407+
408+
# Install the swiftmodule and swiftdoc files.
409+
for module in module_names:
410+
install_binary(args, module + ".swiftmodule", install_dir)
411+
if not args.cross_compile_hosts: # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
412+
install_binary(args, module + ".swiftdoc", install_dir)
413+
414+
# Install the C headers.
415+
tscclibc_include_dir = os.path.join(args.tsc_source_dir, "Sources/TSCclibc/include")
416+
tscclibc_include_dir_dest = os.path.join(install_dir, "TSCclibc")
417+
dir_util.copy_tree(tscclibc_include_dir, tscclibc_include_dir_dest)
418+
419+
404420
def install_binary(args, binary, dest_dir):
405421
src = os.path.join(args.bin_dir, binary)
406422
dest = os.path.join(dest_dir, binary)

0 commit comments

Comments
 (0)