Skip to content

[bootstrap] Extract dependency graph from manifest #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2016
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
13 changes: 11 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import PackageDescription

let package = Package(
name: "SwiftPM",

/**
The following is parsed by our bootstrap script, so
if you make changes here please check the boostrap still
succeeds! Thanks.
*/
targets: [
Target(
/** “Swifty” POSIX functions from libc */
Expand All @@ -24,8 +30,8 @@ let package = Package(
Target(
/** Base types for the package-engine */
name: "PackageType",
dependencies: ["PackageDescription", "Utility"]), //FIXME dependency on PackageDescription sucks
Target( //FIXME Utility is too general, we only need `Path`
dependencies: ["PackageDescription", "Utility"]),
Target(
name: "ManifestParser",
dependencies: ["PackageDescription", "PackageType"]),
Target(
Expand All @@ -45,12 +51,15 @@ let package = Package(
name: "Multitool",
dependencies: ["PackageType"]),
Target(
/** Generates Xcode projects */
name: "Xcodeproj",
dependencies: ["PackageType"]),
Target(
/** The main executable provided by SwiftPM */
name: "swift-build",
dependencies: ["ManifestParser", "Get", "Transmute", "Build", "Multitool", "Xcodeproj"]),
Target(
/** Runs package tests */
name: "swift-test",
dependencies: ["Multitool"]),
])
Expand Down
59 changes: 42 additions & 17 deletions Utilities/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ import argparse
import errno
import json
import os
import pipes
import platform
import re
import shlex
import shutil
import subprocess
import sys
import tempfile
import pipes
import shutil

###

Expand Down Expand Up @@ -179,24 +180,48 @@ class Target(object):
str(bool(self.is_library)).lower()), file=output)
print(file=output)

# currently only returns the targets parsed from the manifest
def parse_manifest():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment here that this is actually reading Swift might be nice.

I think a corresponding comment in our Package.swift that we do this here would be good.

# we have a *very* strict format for our manifest to make parsing more robust
pattern = re.compile(r'Target\(.*?name: "(.*?)",\n *dependencies: (\[.*?\])\)', re.DOTALL|re.MULTILINE)
manifest_data = open(os.path.join(g_project_root, "Package.swift")).read()

def convert(match):
name = match.group(1)
deps = eval(match.group(2))
return Target(name, deps)
targets = map(convert, pattern.finditer(manifest_data))

# substitute strings for Target objects
for target in targets:
def convert(targetName):
try:
return next(a for a in targets if a.name == targetName)
except StopIteration:
# this target is not explicit in the manifest: it is an implicit target
b = Target(targetName)
targets.append(b)
return b
target.dependencies = map(convert, target.dependencies)

# fill dependency graph and set dependencies back to strings
def convert(target):
myset = set()
def recurse(root):
deps = []
for dep in root.dependencies:
if dep.name not in myset:
myset.add(dep.name)
deps += recurse(dep) + [dep.name]
return deps
# `reversed` because Linux link order must be reverse-topological
return Target(target.name, reversed(recurse(target)))
return map(convert, targets)

# Hard-coded target definition.
g_project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
g_source_root = os.path.join(g_project_root, "Sources")
targets = [
Target('libc'),
Target('POSIX', dependencies=["libc"]),
Target('Utility', dependencies=["POSIX", "libc"]),
Target('PackageDescription'),
Target('Xcodeproj', dependencies=["PackageType", "Utility", "POSIX", "libc"]),
Target('Multitool', dependencies=["PackageType", "Utility", "POSIX", "libc"]),
Target('PackageType', dependencies=["PackageDescription", "Utility", "POSIX", "libc"]),
Target('Transmute', dependencies=["PackageType", "PackageDescription", "Utility", "POSIX", "libc"]),
Target('ManifestParser', dependencies=["PackageType", "Utility", "PackageDescription", "POSIX", "libc"]),
Target('Get', dependencies=["ManifestParser", "PackageDescription", "PackageType", "Utility", "POSIX", "libc"]),
Target('Build', dependencies=["PackageType", "Utility", "PackageDescription", "POSIX", "libc"]),
Target('swift-build', dependencies=["Xcodeproj", "Transmute", "Multitool", "Build", "Get", "ManifestParser", "PackageDescription", "PackageType", "Utility", "POSIX", "libc"]),
Target('swift-test', dependencies=["Multitool", "PackageType", "PackageDescription", "Utility", "POSIX", "libc"]),
]
targets = parse_manifest()
target_map = dict((t.name, t) for t in targets)

def create_bootstrap_files(sandbox_path, args):
Expand Down