Skip to content
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

Add PackageDescription.Context API #3794

Merged
merged 12 commits into from Oct 19, 2021
Merged

Conversation

pcbeard
Copy link
Contributor

@pcbeard pcbeard commented Oct 6, 2021

Create PackageDescription.Context, which encapsulates context information available only at runtime.

Motivation:

This will permit package manifests to access their source files, which supports dependency generation activities such as dynamic creation of exclusion paths.

Modifications:

Adds a new struct Contextwhich provides two static properties: packageDirectory, the path of the root directory of the current package; and environment, a Dictionary<String, String> that contains a snapshot of the build-time environment variables. These properties are backed by an internal struct ContextModel, which is serialized by the manifest loader as JSON, and passed as a command line argument -context to the manifest process.

Result:

Packages will be able to use Context.packageDirectory to determine their package source directory at runtime. Environment variables are accessed using Context.environment.

Package.swift Outdated Show resolved Hide resolved
@pcbeard pcbeard marked this pull request as draft October 7, 2021 17:22
@pcbeard pcbeard changed the title Add PackageDescription.Package.Context API Add PackageDescription.Context API Oct 8, 2021
@pcbeard
Copy link
Contributor Author

pcbeard commented Oct 8, 2021

Added unit test that exercises the serialization of ContextModel and creates a minimal package with a name derived from .packageDirectory. A second test uses FileManager to access the package directory contents, and return all .swift files that have the prefix “Temporary” to prove directory access works.

@pcbeard pcbeard marked this pull request as ready for review October 9, 2021 17:14
@pcbeard
Copy link
Contributor Author

pcbeard commented Oct 9, 2021

I've tested this working on Linux and Windows too. Currently the unit test doesn't work on Windows (times out), but I've tried Context.packageDirectory in some actual packages, and it does work. To fully build SPM on Windows, you'll need the changes from: apple/swift-llbuild#741

@abertelrud
Copy link
Contributor

Thanks for your work on this @pcbeard! This is looking really good, I think, and it's mostly details to discuss.

@abertelrud abertelrud self-requested a review October 12, 2021 17:34
@neonichu
Copy link
Member

@swift-ci please smoke test

4 similar comments
@neonichu
Copy link
Member

@swift-ci please smoke test

@neonichu
Copy link
Member

@swift-ci please smoke test

@neonichu
Copy link
Member

@swift-ci please smoke test

@pcbeard
Copy link
Contributor Author

pcbeard commented Oct 19, 2021

@swift-ci please smoke test

@pcbeard
Copy link
Contributor Author

pcbeard commented Oct 19, 2021

@swift-ci please smoke test

This struct contains context information available to a package manifest
at runtime. Initially, it contains the packageRoot : URL property.
ContextModel is the value type that gets serialized and wrapped by
PackageDescription.Context. ContextModel copied into PackageDescription
by symbolic link PackageModel.PackageContext.

Add .environment property to PackageDescription.Context.
@pcbeard
Copy link
Contributor Author

pcbeard commented Oct 19, 2021

@swift-ci please smoke test

@neonichu
Copy link
Member

Thanks, @pcbeard!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants