Use JSON to save identifiers
This commit is contained in:
parent
86b7f8fad9
commit
d37aaf8e31
77
hererocks.py
77
hererocks.py
@ -6,6 +6,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
@ -194,11 +195,15 @@ def git_clone_command(repo, ref, is_cache):
|
|||||||
else:
|
else:
|
||||||
return ["git", "clone", "--depth=1"], True
|
return ["git", "clone", "--depth=1"], True
|
||||||
|
|
||||||
def escape_identifier(s):
|
important_identifiers = [
|
||||||
|
"name", "source", "version", "repo", "commit", "target", "compat", "cflags", "readline", "location"
|
||||||
|
]
|
||||||
|
|
||||||
|
def escape_path(s):
|
||||||
return re.sub(r"[^\w]", "_", s)
|
return re.sub(r"[^\w]", "_", s)
|
||||||
|
|
||||||
def identifiers_to_string(identifiers):
|
def hash_identifiers(identifiers):
|
||||||
return "-".join(identifiers)
|
return "-".join(escape_path(str(identifiers.get(name, ""))) for name in important_identifiers)
|
||||||
|
|
||||||
def copy_files(path, *files):
|
def copy_files(path, *files):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
@ -357,19 +362,23 @@ class Program(object):
|
|||||||
self.fetched = True
|
self.fetched = True
|
||||||
|
|
||||||
def set_identifiers(self):
|
def set_identifiers(self):
|
||||||
|
self.identifiers = {
|
||||||
|
"name": self.name,
|
||||||
|
"source": self.source
|
||||||
|
}
|
||||||
|
|
||||||
if self.source == "release":
|
if self.source == "release":
|
||||||
self.identifiers = [self.name, escape_identifier(self.version)]
|
self.identifiers["version"] = self.version
|
||||||
elif self.source == "git":
|
elif self.source == "git":
|
||||||
self.identifiers = [self.name, "git", escape_identifier(self.repo), escape_identifier(self.commit)]
|
self.identifiers["repo"] = self.repo
|
||||||
else:
|
self.identifiers["commit"] = self.commit
|
||||||
self.identifiers = None
|
|
||||||
|
|
||||||
def update_identifiers(self, all_identifiers):
|
def update_identifiers(self, all_identifiers):
|
||||||
installed_identifiers = all_identifiers.get(self.name)
|
installed_identifiers = all_identifiers.get(self.name)
|
||||||
self.set_identifiers()
|
self.set_identifiers()
|
||||||
|
|
||||||
if not opts.ignore_installed:
|
if not opts.ignore_installed and self.source != "local" and installed_identifiers is not None:
|
||||||
if self.identifiers is not None and self.identifiers == installed_identifiers:
|
if hash_identifiers(self.identifiers) == hash_identifiers(installed_identifiers):
|
||||||
print(self.title + self.version_suffix + " already installed")
|
print(self.title + self.version_suffix + " already installed")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -414,10 +423,10 @@ class Lua(Program):
|
|||||||
def set_identifiers(self):
|
def set_identifiers(self):
|
||||||
super(Lua, self).set_identifiers()
|
super(Lua, self).set_identifiers()
|
||||||
|
|
||||||
if self.identifiers is not None:
|
self.identifiers["target"] = opts.target
|
||||||
self.identifiers.extend(map(escape_identifier, [
|
self.identifiers["compat"] = self.compat
|
||||||
opts.target, self.compat, opts.cflags or "", opts.location
|
self.identifiers["cflags"] = opts.cflags or ""
|
||||||
]))
|
self.identifiers["location"] = opts.location
|
||||||
|
|
||||||
def add_options_to_version_suffix(self):
|
def add_options_to_version_suffix(self):
|
||||||
options = []
|
options = []
|
||||||
@ -486,9 +495,9 @@ class Lua(Program):
|
|||||||
luaconf_h.close()
|
luaconf_h.close()
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
if opts.builds and self.identifiers is not None:
|
if opts.builds and self.source != "local":
|
||||||
self.cached_build_path = os.path.join(opts.builds,
|
self.cached_build_path = os.path.join(opts.builds,
|
||||||
identifiers_to_string(self.identifiers))
|
hash_identifiers(self.identifiers))
|
||||||
|
|
||||||
if os.path.exists(self.cached_build_path):
|
if os.path.exists(self.cached_build_path):
|
||||||
print("Building " + self.title + self.version_suffix + " (cached)")
|
print("Building " + self.title + self.version_suffix + " (cached)")
|
||||||
@ -564,8 +573,7 @@ class RioLua(Lua):
|
|||||||
def set_identifiers(self):
|
def set_identifiers(self):
|
||||||
super(RioLua, self).set_identifiers()
|
super(RioLua, self).set_identifiers()
|
||||||
|
|
||||||
if self.identifiers is not None:
|
self.identifiers["readline"] = not opts.no_readline
|
||||||
self.identifiers.append(str(not opts.no_readline))
|
|
||||||
|
|
||||||
def major_version_from_version(self):
|
def major_version_from_version(self):
|
||||||
return self.version[:3]
|
return self.version[:3]
|
||||||
@ -971,26 +979,15 @@ def get_installed_identifiers():
|
|||||||
if not os.path.exists(get_manifest_name()):
|
if not os.path.exists(get_manifest_name()):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
manifest_h = open(get_manifest_name())
|
with open(get_manifest_name()) as manifest_h:
|
||||||
identifiers = {}
|
try:
|
||||||
|
return json.load(manifest_h)
|
||||||
|
except ValueError:
|
||||||
|
return {}
|
||||||
|
|
||||||
for line in manifest_h:
|
def save_installed_identifiers(all_identifiers):
|
||||||
cur_identifiers = line.strip().split("-")
|
with open(get_manifest_name(), "w") as manifest_h:
|
||||||
|
json.dump(all_identifiers, manifest_h)
|
||||||
if cur_identifiers:
|
|
||||||
identifiers[cur_identifiers[0]] = cur_identifiers
|
|
||||||
|
|
||||||
return identifiers
|
|
||||||
|
|
||||||
def save_installed_identifiers(identifiers):
|
|
||||||
manifest_h = open(get_manifest_name(), "w")
|
|
||||||
|
|
||||||
for program in [RioLua, LuaJIT, LuaRocks]:
|
|
||||||
if identifiers.get(program.name) is not None:
|
|
||||||
manifest_h.write(identifiers_to_string(identifiers[program.name]))
|
|
||||||
manifest_h.write("\n")
|
|
||||||
|
|
||||||
manifest_h.close()
|
|
||||||
|
|
||||||
vs_year_to_version = {
|
vs_year_to_version = {
|
||||||
"08": "9.0",
|
"08": "9.0",
|
||||||
@ -1236,12 +1233,16 @@ def main(argv=None):
|
|||||||
os.makedirs(opts.location)
|
os.makedirs(opts.location)
|
||||||
|
|
||||||
if opts.lua:
|
if opts.lua:
|
||||||
identifiers["LuaJIT"] = None
|
if "LuaJIT" in identifiers:
|
||||||
|
del identifiers["LuaJIT"]
|
||||||
|
|
||||||
identifiers_changed = RioLua(opts.lua).update_identifiers(identifiers)
|
identifiers_changed = RioLua(opts.lua).update_identifiers(identifiers)
|
||||||
os.chdir(start_dir)
|
os.chdir(start_dir)
|
||||||
|
|
||||||
if opts.luajit:
|
if opts.luajit:
|
||||||
identifiers["lua"] = None
|
if "lua" in identifiers:
|
||||||
|
del identifiers["lua"]
|
||||||
|
|
||||||
identifiers_changed = LuaJIT(opts.luajit).update_identifiers(identifiers)
|
identifiers_changed = LuaJIT(opts.luajit).update_identifiers(identifiers)
|
||||||
os.chdir(start_dir)
|
os.chdir(start_dir)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user