-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild-package-xml
executable file
·149 lines (132 loc) · 5.16 KB
/
build-package-xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env php
<?php
if ( $argc < 3 or $argc > 5 ) {
fputs(STDERR, "Form: {$argv[0]} input.xml output.xml [version [state]]\n");
fputs(STDERR, "Ex: {$argv[0]} base.xml package.xml 1.0.0 beta\n");
exit(1);
}
@list($program,$input,$output,$version,$state) = $argv;
// Load a list of all of our tagged releases thus far
$prev_versions = array();
foreach (explode("\n",trim(`git for-each-ref --sort='-refname' --sort='-authordate' --format='%(refname:short) %(authordate:short)' refs/tags/v*.*.*`)) as $tag) {
list($tag_name,$tag_date) = explode(" ",$tag);
$tag_version = substr($tag_name,1);
list($tag_major, $tag_minor, $tag_rel) = explode(".",$tag_version);
$prev_versions[] = array(
"name" => $tag_name,
"date" => $tag_date,
"version" => $tag_version,
"major" => $tag_major,
"minor" => $tag_minor,
"rel" => $tag_rel,
);
}
// PEAR can't live with strict, so make sure it's off.
// PEAR also uses features deprecated in 5.3-- unfortunately the deprecated flag only exists in 5.3+ and thus this hack
// Also, under 5.4, there are many strict errors with stock PEAR
$E_DEPRECATED = defined('E_DEPRECATED') ? E_DEPRECATED : 0;
ini_set("error_reporting", E_ALL ^ ($E_DEPRECATED | E_STRICT) );
require_once "PEAR/PackageFileManager2.php";
// Load our template package.xml...
$pfm = new PEAR_PackageFileManager2();
$res = @$pfm->importOptions( $input );
if ( $res instanceof PEAR_Error ) {
fputs(STDERR, $res->message."\n");
exit(1);
}
// If we weren't given a version...
if ( ! isset($version) ) {
// Then this is an alpha (source build) of the next release...
$prev = $prev_versions[0];
$rel = $prev['rel'] + 1;
$version = "{$prev['major']}.{$prev['minor']}.{$rel}";
$state = "alpha";
// Just pull in the commit log as the changelog, no need for this to be edited
$log = trim(`git log --format='* %s (%aN)' {$prev['name']}.. --ancestry-path --no-merges`);
if ( $log == "" ) {
$log = trim(`git log --format='* %s (%aN)' {$prev['name']}.. --topo-order --no-merges`);
}
$res->setNotes( "NOTE: This version was built from source:\n$log" );
}
// If we were given a version...
else {
// We get our notes from the CHANGELOG file, which will be created and edited by release-version
$res->setNotes( file_get_contents('CHANGELOG') );
}
// Update our options...
$options = $res->getOptions();
$options['clearchangelog'] = false;
$options['filelistgenerator'] = 'gitRepoOnly'; // This does a `git ls-files` to determine the file list
$options['baseinstalldir'] = '/';
$options['packagedirectory'] = '.';
$options['packagefile'] = $output;
// Types for various extensions and folders
$options['roles']['md'] = 'doc';
$options['roles']['t'] = 'test';
$options['dir_roles']['testlib'] = 'test';
$options['dir_roles']['test'] = 'test';
// Don't bundle our build files
$options['ignore'][] = 'Makefile';
$options['ignore'][] = 'release-version';
$options['ignore'][] = 'publish-version';
$options['ignore'][] = 'build-package-xml';
$options['ignore'][] = 'build-changelog';
$options['ignore'][] = 'base.xml';
// Don't bundle docs that are in the doc subdir
$options['ignore'][] = 'CHANGELOG';
$options['ignore'][] = 'README.md';
// This includes symlinks, which PHP can't package
$options['ignore'][] = 'test/test_schema/*';
// Build nice, human readable output without MD5s
$options['simpleoutput'] = true;
$res->setOptions($options);
$res->setAPIVersion( $version );
$res->setReleaseVersion( $version );
$res->setAPIStability( $state );
$res->setReleaseStability( $state );
// Add the changelogs for previous releases
foreach ($prev_versions as $index=>$prev) {
$changes = trim(`git show {$prev['name']}:CHANGELOG 2> /dev/null`);
if ( $changes == "" ) {
$changes = "No changelog for this version.";
}
$stability = $prev['major'] > 0 ? "stable" : "beta";
$res->setChangeLogEntry( $prev['version'], array(
"version" => array(
"release" => $prev['version'],
"api" => $prev['version'],
),
"stability" => array(
"release" => $stability,
"api" => $stability,
),
"date" => $prev['date'],
"license" => array(
"attribs" => array(
"uri" => "http://www.opensource.org/licenses/bsd-license.php",
),
"_content" => "BSD Style",
),
"notes" => $changes,
));
}
// These propagate the verison info to the commandline utils
foreach (array("Modyllic/CommandLine.php", "scripts/modyllic") as $file) {
$res->addReplacement( $file, "package-info", "@VERSION@", "version" );
$res->addReplacement( $file, "package-info", "@STATE@", "state" );
}
// This actually produces the file list
$res->generateContents();
// All the docs and scripts should be installed without their folder name...
foreach ( $res->getFilelist() as $name=>$info ) {
if ( preg_match( '{^(?:docs?/|scripts/)(.*)}', $name, $match ) ) {
$res->addInstallAs( $name, $match[1] );
}
}
print "Writing $output\n";
@unlink($output);
$error = $res->writePackageFile();
if ( $error instanceof PEAR_Error ) {
fputs(STDERR, $error->message."\n");
exit(1);
}