diff options
| author | ruki <[email protected]> | 2018-10-30 22:41:00 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-10-30 10:06:00 +0800 |
| commit | f38a530bb04fd2e62a944b2bcc658e723d62b94c (patch) | |
| tree | 1b26fd9e1b9f6afb2c655fb924d67fcee1580fed | |
| parent | cc7757e02250fc919ded9ce9d0c171fa1ce97d0f (diff) | |
support to extract *.xz
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_xz.lua | 58 | ||||
| -rw-r--r-- | xmake/modules/utils/archive/extract.lua | 60 |
3 files changed, 120 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ff25aed0a..be81d7293 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * [#229](https://github.com/tboox/xmake/issues/229): Improve to select toolset for vcproj plugin * Improve compilation dependences +* Support *.xz for extractor ## v2.2.2 @@ -507,6 +508,7 @@ * [#229](https://github.com/tboox/xmake/issues/229): 改进vs toolset选择已经vcproj工程文件生成 * 改进编译依赖,对源文件列表的改动进行依赖判断 +* 支持解压*.xz文件 ## v2.2.2 diff --git a/xmake/modules/detect/tools/find_xz.lua b/xmake/modules/detect/tools/find_xz.lua new file mode 100644 index 000000000..65177ed87 --- /dev/null +++ b/xmake/modules/detect/tools/find_xz.lua @@ -0,0 +1,58 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_xz.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find xz +-- +-- @param opt the argument options, .e.g {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local xz = find_xz() +-- local xz, version = find_xz({version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "xz", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + + -- ok? + return program, version +end diff --git a/xmake/modules/utils/archive/extract.lua b/xmake/modules/utils/archive/extract.lua index 90efe06db..2b826efba 100644 --- a/xmake/modules/utils/archive/extract.lua +++ b/xmake/modules/utils/archive/extract.lua @@ -25,6 +25,7 @@ -- imports import("core.base.option") import("lib.detect.find_file") +import("detect.tools.find_xz") import("detect.tools.find_7z") import("detect.tools.find_tar") import("detect.tools.find_gzip") @@ -183,6 +184,63 @@ function _extract_using_gzip(archivefile, outputdir, extension, opt) return true end +-- extract archivefile using xz +function _extract_using_xz(archivefile, outputdir, extension, opt) + + -- find xz + local program = find_xz() + if not program then + return false + end + + -- extract to *.tar file first + local outputdir_old = nil + if extension:startswith(".tar.") then + outputdir_old = outputdir + outputdir = os.tmpfile() .. ".tar" + end + + -- init temporary archivefile + local tmpfile = path.join(outputdir, path.filename(archivefile)) + + -- init argv + local argv = {"-d", "-f"} + if not option.get("verbose") then + table.insert(argv, "-q") + end + table.insert(argv, tmpfile) + + -- ensure output directory + if not os.isdir(outputdir) then + os.mkdir(outputdir) + end + + -- copy archivefile to outputdir first + if path.absolute(archivefile) ~= path.absolute(tmpfile) then + os.cp(archivefile, tmpfile) + end + + -- enter outputdir + local oldir = os.cd(outputdir) + + -- extract it + os.vrunv(program, argv) + + -- leave outputdir + os.cd(oldir) + + -- continue to extract *.tar file + if outputdir_old then + local tarfile = find_file("*.tar", outputdir) + if tarfile and os.isfile(tarfile) then + return _extract(tarfile, outputdir_old, ".tar", {_extract_using_tar, _extract_using_7z}, opt) + end + end + + -- ok + return true +end + -- extract archivefile using unzip function _extract_using_unzip(archivefile, outputdir, extension, opt) @@ -295,10 +353,12 @@ function main(archivefile, outputdir, opt) [".zip"] = {_extract_using_unzip, _extract_using_tar, _extract_using_7z} , [".7z"] = {_extract_using_7z} , [".gz"] = {_extract_using_gzip, _extract_using_tar, _extract_using_7z} + , [".xz"] = {_extract_using_xz, _extract_using_tar, _extract_using_7z} , [".tgz"] = {_extract_using_tar, _extract_using_7z} , [".bz2"] = {_extract_using_tar, _extract_using_7z} , [".tar"] = {_extract_using_tar, _extract_using_7z} , [".tar.gz"] = {_extract_using_tar, _extract_using_gzip, _extract_using_7z} + , [".tar.xz"] = {_extract_using_tar, _extract_using_xz, _extract_using_7z} , [".tar.bz2"] = {_extract_using_tar, _extract_using_7z} } |
