source: trunk/dports/_resources/port1.0/group/github-1.0.tcl

Last change on this file was 129506, checked in by ionic@…, 3 years ago

PortGroup/{github,bitbucket}: rename source archives containing a top level dir of project-name-hash instead of name-version.

This patch enables the post-extract hook for all ports appending some
distfile location to ${master_sites}, as long as the original github or
bitbucket source is left intact within the ${master_sites} list.

Remove workarounds needed in a few ports to achieve exactly this.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.7 KB
RevLine 
[89688]1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
[88927]2# $Id: github-1.0.tcl 129506 2014-12-15 00:11:38Z ryandesign@macports.org $
[96776]3#
[120143]4# Copyright (c) 2012-2014 The MacPorts Project
[88927]5# All rights reserved.
[96776]6#
[88927]7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are
9# met:
[96776]10#
[88927]11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16# 3. Neither the name of The MacPorts Project nor the names of its
17#    contributors may be used to endorse or promote products derived from
18#    this software without specific prior written permission.
[96776]19#
[88927]20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[96776]31#
32#
[120144]33# This PortGroup accommodates projects hosted at github.
[96776]34#
[88927]35# Usage:
[96776]36#
[120144]37# After the PortSystem 1.0 line, put:
38#
39#   PortGroup           github 1.0
40#
41# Then, replace the name and version lines with:
42#
[122343]43#   github.setup        author project version [tag_prefix]
[120144]44#
45# The port's name will be set to the github project name. If that's not correct,
46# override it by setting the port name as usual, for example:
47#
48#   github.setup        someone someproject 1.2.3
49#   name                myportname
50#
51# The tag_prefix is optional, and refers to any characters that may appear
52# before the actual version number when you view the list of tags for this
53# project on github. For example, if the tags are named like "v1.2.3" then
54# tag_prefix should be specified as "v":
55#
56#   github.setup        someone someproject 1.2.3 v
57#
58# Some projects use github's "releases" service to offer distfiles:
59#
60# https://github.com/blog/1547-release-your-software
61#
62# If the project offers a "release", that's probably the best distfile to use
63# for the port. To do this, use:
64#
65#   github.tarball_from releases
66#
67# Github imposes no naming convention for "release" distfiles, so you may need
68# to set distname as you would for other ports.
69#
70# Older projects use the discontinued "downloads" service. New "downloads" can
71# no longer be created, but old ones are still available:
72#
73# https://github.com/blog/1302-goodbye-uploads
74#
75# If the project doesn't have "releases" but does have "downloads", use them
76# this way (and set distname if needed):
77#
78#   github.tarball_from downloads
79#
80# If neither "releases" nor "downloads" are available, github can automatically
81# generate a distfile from a git tag or commit. This is the github portgroup's
82# default behavior; to use this, simply don't set github.tarball_from. The
83# distname is irrelevant when fetching from a tag or commit, so don't set it
84# either.
85#
86# If the project's developers do not tag their releases, encourage them to do
87# so. Until they do, or if you need to use a development version that's not
88# tagged, you can use a git commit hash and set the version field. If the
89# project does not assign version numbers (or for development versions) you can
90# invent one, typically in the YYYYMMDD format corresponding to the date of the
91# commit you picked. For example, if you want to use a commit with the hash
92# 0ff25277c3842598d919cd3c73d60768 that was committed on April 1, 2014, then
93# you would use:
94#
95#   github.setup        someone someproject 0ff25277c3842598d919cd3c73d60768
96#   version             20140401
97#
98# Some projects' tag- or commit-based distfiles will not contain all the
99# necessary files, if the project uses git submodules. If available, use a
100# distfile from "releases" or "downloads" instead, as described above. If the
101# project does not provide those, encourage the project's developers to provide
102# releases. Until they do, fetch from git instead of from a distfile, and add a
103# post-fetch block to fetch the submodules:
104#
105#   fetch.type          git
106#
107#   post-fetch {
108#       system -W ${worksrcpath} "git submodule update --init"
109#   }
[88927]110
[125636]111options github.author github.project github.version github.tag_prefix
[89692]112options github.homepage github.raw github.master_sites github.tarball_from
[88927]113
114default github.homepage {https://github.com/${github.author}/${github.project}}
[123665]115default github.raw {https://raw.githubusercontent.com/${github.author}/${github.project}}
[129506]116
117# Later code assumes that github.master_sites is a simple string, not a list.
[89692]118default github.master_sites {${github.homepage}/tarball/[join ${github.tag_prefix} ""]${github.version}}
[88927]119
[91448]120default master_sites {${github.master_sites}}
121
[100626]122default github.tarball_from {tags}
[89692]123option_proc github.tarball_from handle_tarball_from
124proc handle_tarball_from {option action args} {
[120144]125    global github.author github.project github.master_sites git.branch github.homepage
[112592]126
[120144]127    if {${action} eq "set"} {
[89692]128        github.tarball_from ${args}
[120144]129        switch ${args} {
130            downloads {
131                github.master_sites https://github.com/downloads/${github.author}/${github.project}
132            }
133            releases {
134                github.master_sites ${github.homepage}/releases/download/${git.branch}
135            }
136            tags {
137                github.master_sites ${github.homepage}/tarball/${git.branch}
138            }
139            default {
140                return -code error "invalid value \"${args}\" for github.tarball_from"
141            }
142        }
[89692]143    }
144}
145
[88927]146proc github.setup {gh_author gh_project gh_version {gh_tag_prefix ""}} {
[122343]147    global extract.suffix github.author github.project github.version github.tag_prefix github.homepage github.master_sites PortInfo
[96776]148
[88927]149    github.author           ${gh_author}
150    github.project          ${gh_project}
151    github.version          ${gh_version}
152    github.tag_prefix       ${gh_tag_prefix}
[96776]153
[122343]154    if {!([info exists PortInfo(name)] && (${PortInfo(name)} ne ${github.project}))} {
155        name                ${github.project}
156    }
157
[88927]158    version                 ${github.version}
159    homepage                ${github.homepage}
[88936]160    git.url                 ${github.homepage}.git
[89040]161    git.branch              [join ${github.tag_prefix}]${github.version}
[88927]162    distname                ${github.project}-${github.version}
[89060]163    fetch.ignore_sslcert    yes
[96776]164
[88927]165    post-extract {
[120144]166        # When fetching from a tag, the extracted directory name will contain a
167        # truncated commit hash. So that the port author need not specify what
168        # that hash is every time the version number changes, rename the
169        # directory to the value of distname (not worksrcdir: ports may want to
170        # set worksrcdir to a subdirectory of the extracted directory).
[129506]171        # It is assumed that github.master_sites is a simple string, not a list.
172        # Here be dragons.
[112098]173        if {![file exists ${worksrcpath}] && \
174                ${fetch.type} eq "standard" && \
[129506]175                [lsearch -exact ${master_sites} ${github.master_sites}] != -1 && \
[112098]176                [llength ${distfiles}] > 0 && \
[114592]177                [llength [glob -nocomplain ${workpath}/*]] > 0} {
[114646]178            if {[file exists [glob ${workpath}/${github.author}-${github.project}-*]] && \
179                [file isdirectory [glob ${workpath}/${github.author}-${github.project}-*]]} {
[114702]180                move [glob ${workpath}/${github.author}-${github.project}-*] ${workpath}/${distname}
[114592]181            }
[88927]182        }
183    }
[96776]184
[120143]185    # If the "version" is composed entirely of hex characters, and is at least
186    # nine characters long, and no tag_prefix is provided, then assume we are
187    # using a commit hash and livecheck commits; otherwise livecheck tags.
[112098]188    if {[join ${github.tag_prefix}] eq "" && \
189        [regexp "^\[0-9a-f\]{9,}\$" ${github.version}]} {
[120143]190        livecheck.type      regexm
191        livecheck.url       ${github.homepage}/commits/master.atom
192        livecheck.regex     <id>tag:github.com,2008:Grit::Commit/(\[0-9a-f\]{[string length ${github.version}]})\[0-9a-f\]*</id>
[102489]193    } else {
[120143]194        livecheck.type      regex
195        livecheck.url       ${github.homepage}/tags
196        livecheck.regex     archive/[join ${github.tag_prefix} ""](\[^"\]+)${extract.suffix}
[102489]197    }
[120143]198    livecheck.version       ${github.version}
[88927]199}
Note: See TracBrowser for help on using the repository browser.