Support autoclose at build level

Please review my changes

Thanks!