aboutsummaryrefslogtreecommitdiff
path: root/rustrunner.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2014-06-22 19:10:06 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2014-06-22 19:10:06 +0300
commit147e04ac80dccc1a19ec94338472a2cd3989f055 (patch)
tree5e7c8f0b0be62c59d856043a5668336ee4435246 /rustrunner.py
parentcfff45fcdee9d266accbabbedb0a5b50573f873f (diff)
downloadmeson-147e04ac80dccc1a19ec94338472a2cd3989f055.zip
meson-147e04ac80dccc1a19ec94338472a2cd3989f055.tar.gz
meson-147e04ac80dccc1a19ec94338472a2cd3989f055.tar.bz2
Working on a wrapper script to drive Rust compilation.
Diffstat (limited to 'rustrunner.py')
-rwxr-xr-xrustrunner.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/rustrunner.py b/rustrunner.py
new file mode 100755
index 0000000..18700c1
--- /dev/null
+++ b/rustrunner.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+
+# Copyright 2014 Jussi Pakkanen
+
+# Licensed 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.
+
+"""This is a wrapper script to run the Rust compiler. It is needed
+because:
+
+- output file name of Rust compilation is not knowable at command
+ execution time (no, --crate-name can't be used)
+- need to delete old crates so nobody uses them by accident
+"""
+
+import sys, os, subprocess, glob
+
+def delete_old_crates(target_name, target_type):
+ if target_type == 'dylib':
+ (base, suffix) = os.path.splitext(target_name)
+ crates = glob.glob(base + '-*' + suffix)
+ crates = [(os.stat(i).st_ctime, i) for i in crates]
+ [os.unlink(c[1]) for c in sorted(crates)[:-1]]
+
+def invoke_rust(rustc_command):
+ return 0
+ #return subprocess.call(rustc_command, shell=False)
+
+def touch_file(fname):
+ try:
+ os.unlink(fname)
+ except FileNotFoundError:
+ pass
+ open(fname, 'w').close()
+
+if __name__ == '__main__':
+ if len(sys.argv) < 3:
+ print('This script is internal to Meson. Do not run it on its own.')
+ print("%s <target name> <target type> <rustc invokation cmd line>")
+ sys.exit(1)
+ target_name = sys.argv[1]
+ target_type = sys.argv[2]
+ rustc_command = sys.argv[3:]
+ retval = invoke_rust(rustc_command)
+ if retval != 0:
+ sys.exit(retval)
+ delete_old_crates(target_name, target_type)
+ touch_file(target_name)
+