Check-in [01f616a04b]
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Separate phar plugin from php generation template, prepare for classmap building. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
01f616a04b9808c4517b9ee705054d8d |
User & Date: | mario 2015-01-21 12:28:32 |
Context
2015-01-21
| ||
13:10 | Implement classmap builder directly in -t phar plugin. (Original implementation and tokenizer alternative in Canonic_Autoloader.) check-in: 5c62338e56 user: mario tags: trunk | |
12:28 | Separate phar plugin from php generation template, prepare for classmap building. check-in: 01f616a04b user: mario tags: trunk | |
2015-01-20
| ||
00:01 | Handle tilde, caret and asterisk specifiers more concretely. Downcase version suffixes in version_rewrite(). And abstract mapping for @dependencies, @provides, @conflicts, @replaces. Debian @suggests not yet populated. (And RPM target doesn't have it.) Composer dependency version alternatives "|" get ignored. Introduce --composer-no-alt flag to disable phar-|php- alternative lists for :debs too. check-in: 593dc02107 user: mario tags: trunk | |
Changes
Changes to lib/fpm/package/composer.rb.
︙ | ︙ | |||
234 235 236 237 238 239 240 | when "self.version" # pseudo JSOX " = " + @version when /^ (=|==|>=|>|>>|<<|<|<=) (#{rx}) $/x # >= 2.0.x " #{$1} #{$2}" when /^ (!=|<>) (#{rx}) $/x # conflicts attrs[:composer]["conflict"][k] = $1 when /^ ([\d.]+) \.[\*x] ([~-]*.*)? $/x # Asterisk 1.0.* and 1.0.x | < | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | when "self.version" # pseudo JSOX " = " + @version when /^ (=|==|>=|>|>>|<<|<|<=) (#{rx}) $/x # >= 2.0.x " #{$1} #{$2}" when /^ (!=|<>) (#{rx}) $/x # conflicts attrs[:composer]["conflict"][k] = $1 when /^ ([\d.]+) \.[\*x] ([~-]*.*)? $/x # Asterisk 1.0.* and 1.0.x [" >= #{$1}.0#{$2}", " << #{next_major_ver($1+'.0')}"] when /^ \~ (#{rx}) $/x # Tilde ~2.0 [" >= #{$1}", " << #{next_major_ver($1)}"] when /^ \^ (#{rx}) $/x # Caret ^1.2.3 [" >= #{$1}", " << #{next_major_ver($1, 0)}"] when /^ #{rx} $/x # literal 1.0.1 " = #{v}" |
︙ | ︙ |
Changes to lib/fpm/package/phar.rb.
︙ | ︙ | |||
23 24 25 26 27 28 29 | # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ # β phar β Phar β - β - β β # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ # β phar.gz β Phar β gzip β - β general β # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ # β pharΒ·bz2 β Phar β bzip2 β - β β # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ | | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ # β phar β Phar β - β - β β # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ # β phar.gz β Phar β gzip β - β general β # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ # β pharΒ·bz2 β Phar β bzip2 β - β β # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ # β phaZ β Phar β - β gzip β β # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ # β phaZ.gz β Phar β gzip β gzip β (eschew) β # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ # β zip β Zip β - β - β β # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ # β zip.gz β Zip β gzip β - β distribution β # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ # β zipβ¦bz2 β Zip β bzip2 β - β β # βββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββ€ |
︙ | ︙ | |||
47 48 49 50 51 52 53 54 55 56 57 58 59 60 | # ZIPs and TARs can be read by other languages, but contain PHP/phar-specific # additions (.phar/stub and a signature). # require "fpm/package" require "fpm/util" require "fileutils" require "json" # Phar creation (output only) class FPM::Package::Phar < FPM::Package option "--format", "PHAR.gz/TGZ/ZIP", "Phar package type and compression (append .gz/.bz2 for method)", :default=>"PHAR.GZ" option "--stub", "STUB.php", "Apply initialization/stub file", :default=>"" | > | > | > > > | | | | > | | | | | | | < < | < < < | < < < < < | < < | < < < | < < < < < < | < < | < < < | | < < < < < < < | < < | < < < < < | | | | 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 | # ZIPs and TARs can be read by other languages, but contain PHP/phar-specific # additions (.phar/stub and a signature). # require "fpm/package" require "fpm/util" require "fileutils" require "tempfile" require "json" # Phar creation (output only) class FPM::Package::Phar < FPM::Package option "--format", "PHAR.gz/TGZ/ZIP", "Phar package type and compression (append .gz/.bz2 for method)", :default=>"PHAR.GZ" option "--stub", "STUB.php", "Apply initialization/stub file", :default=>"" #option "--nocase", :flag, "Lowercase filenames / implicit `-u lcase=*`", :default=>false option "--sign", "PEM_FILE", "Sign package with OpenSSL and key from .pem file", :default=>"" # Invoke PHP for actual packaging process def output(output_path) output_check(output_path) # Build flags p = { :name => name, :srcdir => staging_path, #:nocase => attributes[:phar_nocase], :stub => attributes[:phar_stub_given?] ? staging_path + "/" + attributes[:phar_stub] : "", :sign => attributes[:phar_sign], } # Retain package meta information, either from fpm attributes, or collected :attr hash (src module, formerly :meta) p[:meta] = attrs.merge({ "id" => @name, "version" => @version.to_s, "epoch" => @epoch.to_s, "iteration" => @iteration.to_s, "architecture" => @architecture, "category" => @category == "none" ? nil : @category, "author" => @maintainer, "url" => @url, "license" => @license, }).delete_if{ |k,v| v.nil? || v==""} # Match format specifier/extension onto type/settings fmt = (attributes[:phar_format] + output_path).downcase fmt, enc = fmt.match(/zip|phaz|tar|t[gb]z|pz/).to_s||"phar", fmt.match(/gz|bz2/).to_s map_keys = [:stdext, :format, :filegz, :extout, :hullgz] map = { # fmt, enc extension format per-file-gz extns β archive-compr ["phar", "" ] => [ ".phar", "Phar::PHAR", "Phar::NONE", "", "" ], ["phar", "gz" ] => [ ".phar", "Phar::PHAR", "Phar::GZ", "", "" ], ["phar", "bz2"] => [ ".phar", "Phar::PHAR", "Phar::BZ2", "", "" ], ["zip", "" ] => [ ".phar.zip", "Phar::ZIP", "Phar::NONE", "", "" ], ["zip", "gz" ] => [ ".phar.zip", "Phar::ZIP", "Phar::GZ", "", "" ], ["zip", "bz2" ] => [ ".phar.zip", "Phar::ZIP", "Phar::BZ2", "", "" ], ["tar", "" ] => [ ".phar.tar", "Phar::TAR", "Phar::NONE", "", "" ], ["tar", "gz" ] => [ ".phar.tar", "Phar::TAR", "Phar::GZ", ".gz", "Phar::GZ" ], ["tar", "bz2" ] => [ ".phar.tar", "Phar::TAR", "Phar::BZ2", ".bz2", "Phar::BZ2"], ["phaz", "" ] => [ ".phar", "Phar::PHAR", "Phar::GZ", ".gz", "Phar::GZ" ], ["phaz", "gz" ] => [ ".phar", "Phar::PHAR", "Phar::GZ", ".gz", "Phar::GZ" ], ["phaz", "bz2"] => [ ".phar", "Phar::PHAR", "Phar::GZ", ".bz2", "Phar::BZ2"], } ext2map = { # map file extensions "tgz" => ["tar", "gz"], "tbz" => ["tar", "bz2"], "pz" => ["phaz", ""] } opt = map[[fmt,enc]] || map[ext2map[fmt]] || map[["phar", ""]] p.merge! Hash[map_keys.zip opt] # Have PHP generate the package p[:tmpf] = ::Dir::Tmpname.create(['_\$fpm_phar_', p[:stdext]]) {} phargen = template_dir + "/phar.php" safesystem("php", "-dphar.readonly=0", "-derror_reporing=~0", "-ddisplay_errors=1", phargen, JSON.generate(p)) #-- but might end up with suffix, for whole-archive ->compress()ion FileUtils.mv(p[:tmpf] + p[:extout], output_path) File.unlink(p[:tmpf]) if File.exists?(p[:tmpf]) end end # class FPM::Package::Phar |
Added templates/phar.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | <?php /** * api: php * title: Phar generation * description: PHP script template to get Phar assembled * * Used as template php script for -t phar building. * Extracts passed Ruby variables as PHP strings, so some * need constant(), strlen() or boolean interpretation. * */ #-- Parameters from phar.rb passed as JSON in argv[1] extract(json_decode($_SERVER["argv"][1], TRUE)); /** * Create phar * Β· Tempoarary filename. * Β· FPM package name as Phar name. * Β· Read complete staging dir. */ $p = new Phar($tmpf, 0, $name); $p->startBuffering(); $p->buildFromDirectory($srcdir); /** * Add stub * Β· Use given file * Β· Default init+index.php for native Phars. * Β· Stub for zip/tar archive. */ if (strlen($stub) && file_exists($stub)) { $p->setStub(file_get_contents($stub)); } elseif (constant($format) == Phar::PHAR) { $p->setDefaultStub("__init__.php", "index.php"); } else { $p->setDefaultStub(); } /** * Phar meta data * Β· Use injected JSON blob. * Β· Contains at least fpm package infos, * Β· May contain additional fields - attrs{} from `-s src` or `composer` module * Β· Build and include a classmap. */ if ($meta) { $p->setMetadata($meta); } /** * Complete packaging * Β· Set per-file compression * Β· Add signature, if any. * Β· Compressed outer archive hull (tar or phar). */ if (constant($filegz)) { $p->compressFiles(constant($filegz)); } if (strlen($sign)) { $p->setSignatureAlgorithm(Phar::OPENSSL, file_get_contents($sign)); } else { $p->setSignatureAlgorithm(Phar::SHA256); } // Whole-archive compression; output goes to a different filename. (Cleaned up in Ruby...) $p->stopBuffering(); if (strlen($extout)) { $p->compress(constant($hullgz)); } |