Generate recursive meta language dependencies.
Cargo doesn't scan a directory for changed dependencies recursively, so do that as part of the build.py script.
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import target
|
import target
|
||||||
import gen_instr
|
import gen_instr
|
||||||
|
import gen_build_deps
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Generate sources for Cretonne.')
|
parser = argparse.ArgumentParser(description='Generate sources for Cretonne.')
|
||||||
parser.add_argument('--out-dir', help='set output directory')
|
parser.add_argument('--out-dir', help='set output directory')
|
||||||
@@ -15,3 +16,4 @@ out_dir = args.out_dir
|
|||||||
targets = target.all_targets()
|
targets = target.all_targets()
|
||||||
|
|
||||||
gen_instr.generate(targets, out_dir)
|
gen_instr.generate(targets, out_dir)
|
||||||
|
gen_build_deps.generate()
|
||||||
|
|||||||
36
meta/gen_build_deps.py
Normal file
36
meta/gen_build_deps.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
"""
|
||||||
|
Generate build dependencies for Cargo.
|
||||||
|
|
||||||
|
The `build.py` script is invoked by cargo when building libcretonne to
|
||||||
|
generate Rust code from the instruction descriptions. Cargo needs to know when
|
||||||
|
it is necessary to rerun the build script.
|
||||||
|
|
||||||
|
If the build script outputs lines of the form:
|
||||||
|
|
||||||
|
cargo:rerun-if-changed=/path/to/file
|
||||||
|
|
||||||
|
cargo will rerun the build script when those files have changed since the last
|
||||||
|
build.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
from os.path import dirname, abspath, join
|
||||||
|
|
||||||
|
|
||||||
|
def source_files(top):
|
||||||
|
"""
|
||||||
|
Recursively find all interesting source files and directories in the
|
||||||
|
directory tree starting at top. Yield a path to each file.
|
||||||
|
"""
|
||||||
|
for (dirpath, dirnames, filenames) in os.walk(top):
|
||||||
|
yield dirpath
|
||||||
|
for f in filenames:
|
||||||
|
if f.endswith('.py'):
|
||||||
|
yield join(dirpath, f)
|
||||||
|
|
||||||
|
|
||||||
|
def generate():
|
||||||
|
print "Dependencies from meta language directory:"
|
||||||
|
meta = dirname(abspath(__file__))
|
||||||
|
for path in source_files(meta):
|
||||||
|
print "cargo:rerun-if-changed=" + path
|
||||||
@@ -32,9 +32,6 @@ fn main() {
|
|||||||
let meta_dir = top_dir.join("meta");
|
let meta_dir = top_dir.join("meta");
|
||||||
let build_script = meta_dir.join("build.py");
|
let build_script = meta_dir.join("build.py");
|
||||||
|
|
||||||
// Let Cargo known that this script should be rerun if anything changes in the meta directory.
|
|
||||||
println!("cargo:rerun-if-changed={}", meta_dir.display());
|
|
||||||
|
|
||||||
// Launch build script with Python. We'll just find python in the path.
|
// Launch build script with Python. We'll just find python in the path.
|
||||||
let status = process::Command::new("python")
|
let status = process::Command::new("python")
|
||||||
.current_dir(top_dir)
|
.current_dir(top_dir)
|
||||||
|
|||||||
Reference in New Issue
Block a user