From 29fa1dd52289ea3141c251f66b70bf660c7724e1 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 20 Mar 2015 15:45:32 +0200 Subject: [PATCH] Add support for checking out git repos to subprojects automatically. --- .gitignore | 1 + interpreter.py | 13 +++--- manual tests/1 wrap/subprojects/sqlite.wrap | 2 +- .../2 multiwrap/subprojects/libpng.wrap | 3 +- manual tests/2 multiwrap/subprojects/lua.wrap | 2 +- .../2 multiwrap/subprojects/zlib.wrap | 2 +- manual tests/3 git wrap/meson.build | 8 ++++ manual tests/3 git wrap/prog.c | 6 +++ .../subprojects/samplesubproject.wrap | 4 ++ .../Info.plist | 0 .../build_linux_package.sh | 0 .../build_osx_package.sh | 0 .../linux_bundler.sh | 0 .../meson.build | 0 .../myapp.cpp | 0 .../myapp.icns | Bin .../myapp.sh | 0 .../osx_bundler.sh | 0 .../readme.txt | 0 .../template.dmg.gz | Bin wrap.py | 39 +++++++++++++++--- 21 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 manual tests/3 git wrap/meson.build create mode 100644 manual tests/3 git wrap/prog.c create mode 100644 manual tests/3 git wrap/subprojects/samplesubproject.wrap rename manual tests/{3 standalone binaries => 4 standalone binaries}/Info.plist (100%) rename manual tests/{3 standalone binaries => 4 standalone binaries}/build_linux_package.sh (100%) rename manual tests/{3 standalone binaries => 4 standalone binaries}/build_osx_package.sh (100%) rename manual tests/{3 standalone binaries => 4 standalone binaries}/linux_bundler.sh (100%) rename manual tests/{3 standalone binaries => 4 standalone binaries}/meson.build (100%) rename manual tests/{3 standalone binaries => 4 standalone binaries}/myapp.cpp (100%) rename manual tests/{3 standalone binaries => 4 standalone binaries}/myapp.icns (100%) rename manual tests/{3 standalone binaries => 4 standalone binaries}/myapp.sh (100%) rename manual tests/{3 standalone binaries => 4 standalone binaries}/osx_bundler.sh (100%) rename manual tests/{3 standalone binaries => 4 standalone binaries}/readme.txt (100%) rename manual tests/{3 standalone binaries => 4 standalone binaries}/template.dmg.gz (100%) diff --git a/.gitignore b/.gitignore index 886f7ded1..e09cfa081 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ __pycache__ .DS_Store *~ +packagecache diff --git a/interpreter.py b/interpreter.py index dfb42e6d7..98875ce45 100644 --- a/interpreter.py +++ b/interpreter.py @@ -1015,14 +1015,11 @@ class Interpreter(): if dirname == self.subprojects: return self.subprojects[dirname] subdir = os.path.join('subprojects', dirname) - abs_subdir = os.path.join(self.build.environment.get_source_dir(), subdir) - if not os.path.isdir(abs_subdir): - r = wrap.Resolver(os.path.join(self.build.environment.get_source_dir(), 'subprojects')) - resolved = r.resolve(dirname) - if resolved is None: - raise InterpreterException('Subproject directory does not exist and can not be downloaded.') - subdir = os.path.join('subprojects', resolved) - abs_subdir = os.path.join(self.build.environment.get_source_dir(), 'subprojects', subdir) + r = wrap.Resolver(os.path.join(self.build.environment.get_source_dir(), 'subprojects')) + resolved = r.resolve(dirname) + if resolved is None: + raise InterpreterException('Subproject directory does not exist and can not be downloaded.') + subdir = os.path.join('subprojects', resolved) os.makedirs(os.path.join(self.build.environment.get_build_dir(), subdir), exist_ok=True) self.global_args_frozen = True mlog.log('\nExecuting subproject ', mlog.bold(dirname), '.\n', sep='') diff --git a/manual tests/1 wrap/subprojects/sqlite.wrap b/manual tests/1 wrap/subprojects/sqlite.wrap index 879a170d6..b56e7e27d 100644 --- a/manual tests/1 wrap/subprojects/sqlite.wrap +++ b/manual tests/1 wrap/subprojects/sqlite.wrap @@ -1,4 +1,4 @@ -[mesonwrap] +[wrap-file] directory = sqlite-amalgamation-3080802 source_url = http://sqlite.com/2015/sqlite-amalgamation-3080802.zip diff --git a/manual tests/2 multiwrap/subprojects/libpng.wrap b/manual tests/2 multiwrap/subprojects/libpng.wrap index bd6508040..d7cb93e01 100644 --- a/manual tests/2 multiwrap/subprojects/libpng.wrap +++ b/manual tests/2 multiwrap/subprojects/libpng.wrap @@ -1,5 +1,4 @@ -[mesonwrap] - +[wrap-file] directory = libpng-1.6.16 source_url = ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.16.tar.gz diff --git a/manual tests/2 multiwrap/subprojects/lua.wrap b/manual tests/2 multiwrap/subprojects/lua.wrap index da2ca1468..8f19d151f 100644 --- a/manual tests/2 multiwrap/subprojects/lua.wrap +++ b/manual tests/2 multiwrap/subprojects/lua.wrap @@ -1,4 +1,4 @@ -[mesonwrap] +[wrap-file] directory = lua-5.3.0 source_url = http://www.lua.org/ftp/lua-5.3.0.tar.gz diff --git a/manual tests/2 multiwrap/subprojects/zlib.wrap b/manual tests/2 multiwrap/subprojects/zlib.wrap index 7ea335428..37202f8d4 100644 --- a/manual tests/2 multiwrap/subprojects/zlib.wrap +++ b/manual tests/2 multiwrap/subprojects/zlib.wrap @@ -1,4 +1,4 @@ -[mesonwrap] +[wrap-file] directory = zlib-1.2.8 source_url = http://zlib.net/zlib-1.2.8.tar.gz diff --git a/manual tests/3 git wrap/meson.build b/manual tests/3 git wrap/meson.build new file mode 100644 index 000000000..f3cce0014 --- /dev/null +++ b/manual tests/3 git wrap/meson.build @@ -0,0 +1,8 @@ +project('git outcheckker', 'c') + +sp = subproject('samplesubproject') + +exe = executable('gitprog', 'prog.c', +include_directories : sp.get_variable('subproj_inc'), +link_with : sp.get_variable('subproj_lib'), +) diff --git a/manual tests/3 git wrap/prog.c b/manual tests/3 git wrap/prog.c new file mode 100644 index 000000000..df38000ec --- /dev/null +++ b/manual tests/3 git wrap/prog.c @@ -0,0 +1,6 @@ +#include"subproj.h" + +int main(int argc, char **argv) { + subproj_function(); + return 0; +} diff --git a/manual tests/3 git wrap/subprojects/samplesubproject.wrap b/manual tests/3 git wrap/subprojects/samplesubproject.wrap new file mode 100644 index 000000000..f52190b8f --- /dev/null +++ b/manual tests/3 git wrap/subprojects/samplesubproject.wrap @@ -0,0 +1,4 @@ +[wrap-git] +directory=samplesubproject +url=https://github.com/jpakkane/samplesubproject.git +revision=head diff --git a/manual tests/3 standalone binaries/Info.plist b/manual tests/4 standalone binaries/Info.plist similarity index 100% rename from manual tests/3 standalone binaries/Info.plist rename to manual tests/4 standalone binaries/Info.plist diff --git a/manual tests/3 standalone binaries/build_linux_package.sh b/manual tests/4 standalone binaries/build_linux_package.sh similarity index 100% rename from manual tests/3 standalone binaries/build_linux_package.sh rename to manual tests/4 standalone binaries/build_linux_package.sh diff --git a/manual tests/3 standalone binaries/build_osx_package.sh b/manual tests/4 standalone binaries/build_osx_package.sh similarity index 100% rename from manual tests/3 standalone binaries/build_osx_package.sh rename to manual tests/4 standalone binaries/build_osx_package.sh diff --git a/manual tests/3 standalone binaries/linux_bundler.sh b/manual tests/4 standalone binaries/linux_bundler.sh similarity index 100% rename from manual tests/3 standalone binaries/linux_bundler.sh rename to manual tests/4 standalone binaries/linux_bundler.sh diff --git a/manual tests/3 standalone binaries/meson.build b/manual tests/4 standalone binaries/meson.build similarity index 100% rename from manual tests/3 standalone binaries/meson.build rename to manual tests/4 standalone binaries/meson.build diff --git a/manual tests/3 standalone binaries/myapp.cpp b/manual tests/4 standalone binaries/myapp.cpp similarity index 100% rename from manual tests/3 standalone binaries/myapp.cpp rename to manual tests/4 standalone binaries/myapp.cpp diff --git a/manual tests/3 standalone binaries/myapp.icns b/manual tests/4 standalone binaries/myapp.icns similarity index 100% rename from manual tests/3 standalone binaries/myapp.icns rename to manual tests/4 standalone binaries/myapp.icns diff --git a/manual tests/3 standalone binaries/myapp.sh b/manual tests/4 standalone binaries/myapp.sh similarity index 100% rename from manual tests/3 standalone binaries/myapp.sh rename to manual tests/4 standalone binaries/myapp.sh diff --git a/manual tests/3 standalone binaries/osx_bundler.sh b/manual tests/4 standalone binaries/osx_bundler.sh similarity index 100% rename from manual tests/3 standalone binaries/osx_bundler.sh rename to manual tests/4 standalone binaries/osx_bundler.sh diff --git a/manual tests/3 standalone binaries/readme.txt b/manual tests/4 standalone binaries/readme.txt similarity index 100% rename from manual tests/3 standalone binaries/readme.txt rename to manual tests/4 standalone binaries/readme.txt diff --git a/manual tests/3 standalone binaries/template.dmg.gz b/manual tests/4 standalone binaries/template.dmg.gz similarity index 100% rename from manual tests/3 standalone binaries/template.dmg.gz rename to manual tests/4 standalone binaries/template.dmg.gz diff --git a/wrap.py b/wrap.py index af2b213dd..9c8840306 100644 --- a/wrap.py +++ b/wrap.py @@ -14,13 +14,19 @@ import mlog import urllib.request, os, hashlib, shutil +import subprocess class PackageDefinition: def __init__(self, fname): self.values = {} ifile = open(fname) first = ifile.readline().strip() - if first != '[mesonwrap]': + + if first == '[wrap-file]': + self.type = 'file' + elif first == '[wrap-git]': + self.type = 'git' + else: raise RuntimeError('Invalid format of package file') for line in ifile: line = line.strip() @@ -45,12 +51,35 @@ class Resolver: def resolve(self, packagename): fname = os.path.join(self.subdir_root, packagename + '.wrap') if not os.path.isfile(fname): + if os.path.isdir(dirname): + # No wrap file but dir exists -> user put it there manually. + return packagename return None - if not os.path.isdir(self.cachedir): - os.mkdir(self.cachedir) p = PackageDefinition(fname) - self.download(p, packagename) - self.extract_package(p) + if p.type == 'file': + if not os.path.isdir(self.cachedir): + os.mkdir(self.cachedir) + self.download(p, packagename) + self.extract_package(p) + elif p.type == 'git': + checkoutdir = os.path.join(self.subdir_root, p.get('directory')) + revno = p.get('revision') + is_there = os.path.isdir(checkoutdir) + if is_there: + if revno.lower() == 'head': + subprocess.check_call(['git', 'pull'], cwd=checkoutdir) + else: + subprocess.check_call(['git', 'fetch'], cwd=checkoutdir) + subprocess.check_call(['git', 'checkout', revno], + cwd=checkoutdir) + else: + subprocess.check_call(['git', 'clone', p.get('url'), p.get('directory')], + cwd=self.subdir_root) + if revno.lower() != 'head': + subprocess.check_call(['git', 'checkout', revno], + cwd=checkoutdir) + else: + raise RuntimeError('Unreachable code.') return p.get('directory') def get_data(self, url):