From 14c27ff3fa58c585129643f6c5edb6c8ec3bfb34 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 22 Nov 2015 23:21:36 +0100 Subject: [PATCH] Preclean only in tix-build when the port is dirty. --- tix/tix-build.cpp | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/tix/tix-build.cpp b/tix/tix-build.cpp index 69b76bd9..9ed5a457 100644 --- a/tix/tix-build.cpp +++ b/tix/tix-build.cpp @@ -74,6 +74,8 @@ enum build_step step_of_step_name(const char* step_name) { if ( !strcmp(step_name, "start") ) return BUILD_STEP_START; + if ( !strcmp(step_name, "clean") ) + return BUILD_STEP_PRE_CLEAN; if ( !strcmp(step_name, "pre-clean") ) return BUILD_STEP_PRE_CLEAN; if ( !strcmp(step_name, "configure") ) @@ -88,8 +90,6 @@ enum build_step step_of_step_name(const char* step_name) return BUILD_STEP_POST_CLEAN; if ( !strcmp(step_name, "package") ) return BUILD_STEP_PACKAGE; - if ( !strcmp(step_name, "clean") ) - return BUILD_STEP_POST_CLEAN; if ( !strcmp(step_name, "end") ) return BUILD_STEP_END; return BUILD_STEP_NO_SUCH_STEP; @@ -398,7 +398,7 @@ void SetNeededVariables(metainfo_t* minfo) SetNeedVariableCrossTool(minfo, "STRIP", "strip"); } -void Configure(metainfo_t* minfo) +void Configure(metainfo_t* minfo, const char* subdir = NULL) { if ( fork_and_wait_or_recovery() ) { @@ -432,6 +432,8 @@ void Configure(metainfo_t* minfo) "false")); if ( chdir(minfo->build_dir) != 0 ) error(1, errno, "chdir: `%s'", minfo->build_dir); + if ( subdir && chdir(subdir) != 0 ) + error(1, errno, "chdir: `%s/%s'", minfo->build_dir, subdir); SetNeededVariables(minfo); string_array_t env_vars = string_array_make(); string_array_append_token_string(&env_vars, conf_extra_vars); @@ -493,6 +495,31 @@ void Configure(metainfo_t* minfo) } } +bool TestDirty(metainfo_t* minfo, + const char* subdir, + const char* candidate) +{ + if ( !subdir ) + subdir = "."; + char* path; + if ( asprintf(&path, "%s/%s/%s", minfo->build_dir, subdir, candidate) < 0 ) + error(1, errno, "asprintf"); + bool result = access(path, F_OK) == 0; + free(path); + return result; +} + +bool IsDirty(metainfo_t* minfo, const char* subdir = NULL) +{ + string_array_t* pkg_info = &minfo->package_info; + const char* dirty_file = dictionary_get(pkg_info, "pkg.dirty-file"); + if ( dirty_file ) + return TestDirty(minfo, subdir, dirty_file); + return TestDirty(minfo, subdir, "config.log") || + TestDirty(minfo, subdir, "Makefile") || + TestDirty(minfo, subdir, "makefile"); +} + void Make(metainfo_t* minfo, const char* make_target, const char* destdir = NULL, bool die_on_error = true, const char* subdir = NULL) @@ -599,19 +626,21 @@ void BuildPackage(metainfo_t* minfo) dictionary_get(pinfo, "pkg.make.ignore-clean-failure", "true"); bool ignore_clean_failure = parse_boolean(ignore_clean_failure_var); - if ( SHOULD_DO_BUILD_STEP(BUILD_STEP_PRE_CLEAN, minfo) && !use_build_dir ) + const char* subdir = dictionary_get(pinfo, "pkg.subdir", NULL); + + if ( SHOULD_DO_BUILD_STEP(BUILD_STEP_PRE_CLEAN, minfo) && + !use_build_dir && + IsDirty(minfo) ) Make(minfo, clean_target, NULL, !ignore_clean_failure); // Configure the build directory if needed. if ( strcmp(build_system, "configure") == 0 && SHOULD_DO_BUILD_STEP(BUILD_STEP_CONFIGURE, minfo) ) - Configure(minfo); + Configure(minfo, subdir); bool location_independent = parse_boolean(dictionary_get(pinfo, "pkg.location-independent", "false")); - const char* subdir = dictionary_get(pinfo, "pkg.subdir", NULL); - const char* build_target = dictionary_get(pinfo, "pkg.make.build-target", "all"); const char* install_target = dictionary_get(pinfo, "pkg.make.install-target", "install");