summaryrefslogtreecommitdiff
path: root/build.hy
diff options
context:
space:
mode:
Diffstat (limited to 'build.hy')
-rw-r--r--build.hy78
1 files changed, 78 insertions, 0 deletions
diff --git a/build.hy b/build.hy
new file mode 100644
index 0000000..1737d98
--- /dev/null
+++ b/build.hy
@@ -0,0 +1,78 @@
+#!/usr/bin/env hy
+
+;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org>
+;;;
+;;; This program is free software; you can redistribute it and/or
+;;; modify it under the terms of the GNU General Public License as
+;;; published by the Free Software Foundation; either version 3 of the
+;;; License, or (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;; General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see
+;;; <http://www.gnu.org/licenses/>.
+
+(require [hy.contrib.walk [let]])
+
+(import [ast [parse Return]])
+(import [copy [deepcopy]])
+(import [os [getenv]])
+(import [os.path [splitext]])
+(import [sys [argv exit]])
+
+(import [hy.compiler [hy-compile]])
+(import [hy.lex [hy-parse]])
+
+(import DUCK.Serpentine.visitor)
+(import [DUCK.Tools [buildhelper]])
+
+(defn walk-ast [node]
+ (when (and (isinstance node Return)
+ (= node.value.id "None"))
+ (setv node.value.id None))
+ (when (hasattr node "body")
+ (for [child node.body]
+ (walk-ast child))))
+
+(defn my-hy-compile [source]
+ (let [ast (hy-compile (hy-parse source) "<unknown>")]
+ (walk-ast ast)
+ ast))
+
+(defclass HyVisitor [DUCK.Serpentine.visitor.Visitor]
+ (defn load [self file-name &optional [imports None]]
+ (let [imports (or imports {})]
+ (setv self.imports imports)
+ (setv self.file-name- file-name)
+ (try
+ (with [source (open file-name :encoding (.get-coding self file-name))]
+ (setv self.root (if (.endswith file-name ".hy")
+ (my-hy-compile (.read source))
+ (parse (.read source)))))
+ (except [err SyntaxError]
+ (.write stderr (.format "In '{}': " file-name))
+ (raise err)))
+ (let [module (.visit self self.root)]
+ (assoc self.imports (first (splitext file-name)) module)
+ (return module)))))
+
+(setv DUCK.Serpentine.visitor.Visitor HyVisitor)
+
+(when (= __name__ "__main__")
+ (let [app-name "HelloHy"
+ package-name "com.example.hellohy"
+ res-files {"drawable" {"ic_launcher" "icon.svg"}}
+ code-file "hello.hy"
+ include-paths []
+ layout None
+ features []
+ permissions []
+ docs-dir (getenv "DOCS_DIR")
+ args (deepcopy argv)]
+ (exit (.main buildhelper __file__ app-name package-name
+ res-files layout code-file include-paths
+ features permissions args :docs-dir docs-dir))))