From 6b05e61567cbd16e024170e2d3635516e7b7d8fb Mon Sep 17 00:00:00 2001 From: Jerome Carretero Date: Sat, 2 Jun 2012 19:47:11 -0400 Subject: [PATCH] Add example for cleaning when top==out. --- playground/top_eq_out/.gitignore | 4 ++ playground/top_eq_out/a.cpp | 2 + playground/top_eq_out/wscript | 71 ++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 playground/top_eq_out/.gitignore create mode 100644 playground/top_eq_out/a.cpp create mode 100644 playground/top_eq_out/wscript diff --git a/playground/top_eq_out/.gitignore b/playground/top_eq_out/.gitignore new file mode 100644 index 00000000..60dcc425 --- /dev/null +++ b/playground/top_eq_out/.gitignore @@ -0,0 +1,4 @@ +.lock-w* +.conf_check_* +config.log +c4che diff --git a/playground/top_eq_out/a.cpp b/playground/top_eq_out/a.cpp new file mode 100644 index 00000000..c78837c7 --- /dev/null +++ b/playground/top_eq_out/a.cpp @@ -0,0 +1,2 @@ +int truc=5; + diff --git a/playground/top_eq_out/wscript b/playground/top_eq_out/wscript new file mode 100644 index 00000000..4fc5ea5f --- /dev/null +++ b/playground/top_eq_out/wscript @@ -0,0 +1,71 @@ +#! /usr/bin/env python +# encoding: utf-8 + +""" +Example providing a clean context for when top==out. + +When top==out, waf will not do anything by default +in the clean context, because it could be dangerous. +You need to do something for your particular use case. +This example will remove all the generated files that +will appear under out. + +The distclean operation, which normally removes the build folder +completely plus some files, is also modified to remove +the rest of waf-generated files. + +Notes: + +- this example won't work when using dynamic builds. + + This is because it uses the tasks output files, which + are known in advance. + + For it to work, you would need to store the outputs of + dynamic builds somewhere. + + But top == out is a rare case, so why bother. + + + +""" + +VERSION='0.0.1' +APPNAME='clean_test' + +top = '.' +out = '.' + +def options(opt): + opt.load('compiler_cxx') + +def configure(conf): + conf.load('compiler_cxx') + conf.check(header_name='stdio.h', features='cxx cxxprogram', mandatory=False) + +def build(bld): + bld(features='cxx', source='a.cpp', target='pouet') + + if bld.cmd == 'clean': + for tgen in bld.get_all_task_gen(): + tgen.post() + for t in tgen.tasks: + for n in t.outputs: + if n.is_child_of(bld.bldnode): + n.delete() + + +def distclean(ctx): + import os, shutil + from waflib import Context + + for fn in os.listdir('.'): + if fn.startswith('.conf_check_') or fn.startswith(".lock-w") \ + or fn in (Context.DBFILE, 'config.log') \ + or fn == 'c4che': + if os.path.isdir(fn): + shutil.rmtree(fn) + else: + os.unlink(fn) + +