Skip to content

Package version data #122

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 4 commits into from
Apr 14, 2016
Merged

Conversation

kostiakoval
Copy link
Contributor

Work in Progress
This is initial commit for SR-473

We need to generate version data for every package on build.
Now it creates a new folder versionData inside .build dir and creates a swift file for every package.

Could you please provide any feedback for the initial implementation.

  • Should these files be inside .build dir or somewhere else?
  • Should we generate a new .swift file for every Package or place all data in 1 file?
  • Any other suggestion?

ToDo:

@mxcl
Copy link
Contributor

mxcl commented Feb 3, 2016

Ideally these would be targets integrated into the build yaml so they are not generated every time. However not doing it this way at first is acceptable since we don't have a good way to specify the version dependency yet.


try fputs("public let url: String = \"\(package.url)\" \n", file)
let version = package.version
try fputs("public let version: (Int, Int, Int, [String], String?) = " +
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be better if tuple had named values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aciidb0mb3r something like:

 public let version: (major: Int, minor: Int, patch: Int, etc: [String], metadata: String?)

Copy link
Contributor

Choose a reason for hiding this comment

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

yup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think using type inference would be even better:
What do you think @aciidb0mb3r @mxcl ?

public let version: (major: Int, minor: Int, patch: Int, etc: [String], metadata: String?) = (1, 0, 1, [], "")
//vs
public let version = (1, 0, 1, [], "")

😞 Unfortunately it's not possible, not enough info
screen shot 2016-02-04 at 14 33 19 1

Copy link
Contributor

Choose a reason for hiding this comment

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

imo, it would be fine if it was just public let version = (1, 0, 1) as this is guessable but I have no way of knowing what is last two fields in public let version = (1, 0, 1, [], "") without seeing doc (as they'll be empty for most packages)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's Version's properties.

  • prereleaseIdentifiers: [String]
  • buildMetadataIdentifier: String?
    They describe a version tag of a package. So we need them.

@mxcl
Copy link
Contributor

mxcl commented Mar 8, 2016

Let’s resurrect this potentially fabulous addition.

@kostiakoval
Copy link
Contributor Author

I'm sorry for being lazy here. I'm going to update it soon

@mxcl
Copy link
Contributor

mxcl commented Mar 10, 2016

“Lazy” is certainly not the right word. But we owe it to everyone to prod each other and keep momentum up :)

@kostiakoval kostiakoval force-pushed the package-versionData branch from 7894638 to 44a7f4c Compare March 17, 2016 22:18
@kostiakoval
Copy link
Contributor Author

Hi all. I'm back :)

I'm thinking of adding version: Version? property to a Packagetype. It's optional because local package could be missing a git version.
What do you think @mxcl?

@jessesquires
Copy link

@kostiakoval an optional seems like a bad idea to me.

@mxcl isn't this something that SPM intends to enforce?

i'm not sure how effect a package manager could be without version numbers 😄

@kostiakoval
Copy link
Contributor Author

Hi @jessesquires I'm not talking about a Version you specify in your Manifest file when you describe a package, that must be specified and it's not optional.

The Version I described, is a version we get when we fetch a package.

Local packages .Package(url: "../Foo", versions: Version(1,0,0)..<Version(2,0,0))
It could have missing version tag, and that should be fine when you are developing a package (not published yet).
This PR, represents a metadata (url and Version) for every package swiftpm is fetching and building.

Does it make any sense, any suggestion how make it better?

@jessesquires
Copy link

Ah! 😊 I see. In that case, we probably do want an optional.

Maybe we could rename to versionTag or something similar to avoid confusion?

@mxcl
Copy link
Contributor

mxcl commented Mar 18, 2016

No optional, I think in the case of the root package where we can't get a version just go with 0,0,0. It would suck to always check for the optional here and need to code an error path when it is in fact a programmer error,

The other option is Version!

@mxcl
Copy link
Contributor

mxcl commented Mar 18, 2016

Unless this is only being exposed to SwiftPM, which seems likely, so Version? is ok in that case.

@kostiakoval kostiakoval changed the title [WIP] Package version data Package version data Mar 20, 2016
@kostiakoval
Copy link
Contributor Author

Done. Review it please.

On build generate swift file for every package with Version data.
Each file contains:

public let url: String
public let version: (Int, Int, Int, [String], String?)?

@kostiakoval
Copy link
Contributor Author

@mxcl Can you please run CI and merge it?

@kostiakoval kostiakoval force-pushed the package-versionData branch 3 times, most recently from aa193c8 to 9549f1d Compare March 22, 2016 20:22
import func libc.fclose

public func generateVersionData(rootDir: String, packages: [Package]) throws {
let dirPath = rootDir + "/.build/versionData/"
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer Path.join

@kostiakoval kostiakoval force-pushed the package-versionData branch from 9549f1d to e218e21 Compare March 23, 2016 19:09
@kostiakoval
Copy link
Contributor Author

@aciidb0mb3r Thanks for feedback. Your comments are fixed now 👍

@kostiakoval kostiakoval force-pushed the package-versionData branch from e218e21 to 466f603 Compare March 25, 2016 10:08
@mxcl
Copy link
Contributor

mxcl commented Mar 25, 2016

I've changed my view here.

If root package version data cannot be obtained, do not generate the version swift.

If it can be obtained but commits or work has been done since a version, then add a build identifier with the date.

@kostiakoval
Copy link
Contributor Author

@mxcl Can we review and merge this PR? Some parts of it can be reused when implementing PackageVersions.json file

@kostiakoval kostiakoval force-pushed the package-versionData branch from 7773b49 to 4e4bf44 Compare April 7, 2016 19:44
@ddunbar
Copy link
Contributor

ddunbar commented Apr 11, 2016

Maybe I don't understand, how would other code use them if they aren't optional?

@mxcl
Copy link
Contributor

mxcl commented Apr 11, 2016

I think you understand: other code can't use them if they don't exist.

Thus they won't exist:

  1. For new packages not yet ever published
  2. Projects that never intend to have versions

I think it is reasonable for version information to not exist when it literally doesn't exist.

@mxcl
Copy link
Contributor

mxcl commented Apr 11, 2016

K, talked with Daniel and we think:

  1. version should not be optional, if there is no version, don't generate it. We think this is reasonable so that: people don't have to add error handling for when the version doesn't exist considering the times it doesn't exist are very edge case
  2. We agree sha should remain optional and we like how it works
  3. We think the modified string should be changed to a single Bool. Our thinking here is that we don't think the build-time has much utility in the context of this PR and we really don't want people writing code that does things based on this date value.
  4. Let's label all of the tuple values in version.
  5. Let’s add a versionString property that returns a string since mostly this is a feature for logging versions

Additional longer term considerations:

  1. We think that this should only be generated for the root-package, the rationale here is that we don't want packages writing code like if version.major > 2 as this should be a compile time language feature and Swift core are already on board with this idea.
  2. Thus we think we should generate a single module called PackageVersions (depending on the version-pinning proposal’s end name)
  3. And thus we should probably define a struct for each package in that file

I'll let Daniel correct me if he has any corrections. Otherwise, thoughts?

@ddunbar
Copy link
Contributor

ddunbar commented Apr 11, 2016

I thought we agreed for assigning let version = (0,0,0,...) if missing -- I think this is better so that you can test the code which would use it before you have tagged. Otherwise you have to tag, build, test, retag.

Otherwise yup that matches my thoughts.

One thing to note about the implementation is you will need to treat PackageVersions as a dependency of every target in the top-level project (so they can import it, potentially).

@mxcl
Copy link
Contributor

mxcl commented Apr 11, 2016

I thought we agreed for assigning let version = (0,0,0,...) if missing -- I think this is better so that you can test the code which would use it before you have tagged. Otherwise you have to tag, build, test, retag.

Oh yes, sorry. You are right. I agree.

@mxcl
Copy link
Contributor

mxcl commented Apr 11, 2016

One thing to note about the implementation is you will need to treat PackageVersions as a dependency of every target in the top-level project (so they can import it, potentially).

Indeed. Though @kostiakoval it is cool if we do this part of the implementation in a separate PR.

@kostiakoval
Copy link
Contributor Author

We think that this should only be generated for the root-package,

Can you please clarify what you mean by root-package

It's a package with Package.swift file and it's always only 1. For swiftpm it's a package with "SwiftPM" name.
Did I understood it correctly?

We should generate 1 swift file for a root-package. That file will contain version info about root-package and it's dependencies.

@mxcl
Copy link
Contributor

mxcl commented Apr 12, 2016

When we say root package we mean the one swift build is executing against.

@kostiakoval kostiakoval force-pushed the package-versionData branch 2 times, most recently from d93e2d9 to ac83b46 Compare April 13, 2016 18:43
@kostiakoval kostiakoval force-pushed the package-versionData branch from ac83b46 to b2cb148 Compare April 13, 2016 18:49
@kostiakoval kostiakoval force-pushed the package-versionData branch from b2cb148 to db36292 Compare April 13, 2016 19:57
@kostiakoval
Copy link
Contributor Author

I've addressed 5 mentioned points:

  • version should not be optional,
  • keep sha optional
  • modified as a Bool
  • add label to all of the tuple values in version.
  • Let’s add a versionString

Few questions:

  • should we generate the same version data format for root-package and its dependencies?
    now dependency package don't include sha and modified
    I think they should have same format.
  • the url show the local path for a root-package. Should we use git origin if possible
  • if there is no git repo for a root-package, should we still generate PackageVersions.swift file ?
    It is possible since we have local path as url and default version value

@mxcl
Copy link
Contributor

mxcl commented Apr 13, 2016

should we generate the same version data format for root-package and its dependencies? now dependency package don't include sha and modified I think they should have same format.

My perspective is: yes.

the url show the local path for a root-package. Should we use git origin if possible

Yes, use the origin if possible.

if there is no git repo for a root-package, should we still generate PackageVersions.swift file ? It is possible since we have local path as url and default version value

I think we can be consistent and if there is no git data:

  • Version(0,0,0)
  • local path instead of origin

@mxcl
Copy link
Contributor

mxcl commented Apr 14, 2016

I'm happy to merge this if you are.

@mxcl
Copy link
Contributor

mxcl commented Apr 14, 2016

@swift-ci Please test

@kostiakoval
Copy link
Contributor Author

I'm implementing these changes. Will be done in 30 min

@kostiakoval
Copy link
Contributor Author

I don't feel this is optimal solution. I've tried to fix it but found more issue. We can merge it and improve it later if you like

@mxcl
Copy link
Contributor

mxcl commented Apr 14, 2016

We aim for more incremental development. It doesn't need to be perfect to be landed.

@kostiakoval
Copy link
Contributor Author

Agree. Let's wait for tests first

@kostiakoval
Copy link
Contributor Author

@mxcl Test are passing. Can we merge it. It would be easier to do smaller improvements than

@mxcl mxcl merged commit 5389d99 into swiftlang:master Apr 14, 2016
@kostiakoval kostiakoval deleted the package-versionData branch April 15, 2016 05:54
aciidgh pushed a commit to aciidgh/swift-package-manager that referenced this pull request Jan 11, 2019
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.

5 participants