summaryrefslogtreecommitdiff
path: root/hscript/meta.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-12-19 17:14:27 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-12-19 17:14:27 -0600
commit2495654ac0b1d9a4002f8d385d10d2afec784dda (patch)
treeda8b25a9bbaa3ab3bc2901398db4a0a3ec74481c /hscript/meta.cc
parent3744e909df78cefebb083e401f6f6378f27d1b1a (diff)
downloadhorizon-2495654ac0b1d9a4002f8d385d10d2afec784dda.tar.gz
horizon-2495654ac0b1d9a4002f8d385d10d2afec784dda.tar.bz2
horizon-2495654ac0b1d9a4002f8d385d10d2afec784dda.tar.xz
horizon-2495654ac0b1d9a4002f8d385d10d2afec784dda.zip
hscript: Add 'arch' key implementation and related tests
Diffstat (limited to 'hscript/meta.cc')
-rw-r--r--hscript/meta.cc58
1 files changed, 56 insertions, 2 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc
index b5309f3..f95e2ad 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -163,11 +163,65 @@ bool Hostname::execute(ScriptOptions opts) const {
}
+static std::set<std::string> valid_arches = {
+ "aarch64", "aarch64_be", "alpha", "armel", "armhf", "armv7",
+ "m68k", "mips", "mips64", "mipsel", "mips64el",
+ "pmmx", "ppc", "ppc64",
+ "riscv", "riscv64",
+ "s390x", "sparc", "sparc64",
+ "x86", "x86_64"
+};
+
+
+Key *Arch::parseFromData(const std::string &data, int lineno, int *errors,
+ int *warnings) {
+ if(data.find_first_not_of("abcdefghijklmnopqrstuvwyxz1234567890") !=
+ std::string::npos) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "arch: expected CPU architecture name",
+ "'" + data + "' is not a valid CPU architecture name");
+ return nullptr;
+ }
+
+ if(valid_arches.find(data) == valid_arches.end()) {
+ if(warnings) *warnings += 1;
+ output_warning("installfile:" + std::to_string(lineno),
+ "arch: unknown CPU architecture '" + data + "'");
+ }
+
+ return new Arch(lineno, data);
+}
+
+bool Arch::execute(ScriptOptions opts) const {
+ output_info("installfile:" + std::to_string(line),
+ "arch: setting system CPU architecture to " + value());
+
+ if(opts.test(Simulate)) {
+ std::cout << "printf '" << this->value() << "\\" << "n'"
+ << " > /target/etc/apk/arch" << std::endl;
+ return true;
+ }
+
+#ifdef HAS_INSTALL_ENV
+ std::ofstream arch_f("/target/etc/apk/arch", std::ios_base::trunc);
+ if(!arch_f) {
+ output_error("installfile:" + std::to_string(line),
+ "arch: cannot write target CPU architecture information");
+ return false;
+ }
+
+ arch_f << this->value() << std::endl;
+#endif
+ return true;
+}
+
+
static std::regex valid_pkg("[0-9A-Za-z+_.-]*((>?<|[<>]?=|[~>])[0-9A-Za-z-_.]+)?");
-Key *PkgInstall::parseFromData(const std::string &data, int lineno, int *errors,
- int *warnings) {
+Key *PkgInstall::parseFromData(const std::string &data, int lineno,
+ int *errors, int *warnings) {
std::string next_pkg;
std::istringstream stream(data);
std::set<std::string> all_pkgs;