[][opewnrt-24][common][bsp][Unified autobuild framework update]

[Description]
Add support to sync .config before menuconfig

[Release-log]
N/A

Change-Id: I325eb4c857dc12a2ac4f913e0ae8acc4ae43211b
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/9686866
diff --git a/autobuild/unified/autobuild.sh b/autobuild/unified/autobuild.sh
index 9dae891..76f7e9b 100755
--- a/autobuild/unified/autobuild.sh
+++ b/autobuild/unified/autobuild.sh
@@ -294,6 +294,8 @@
 help_add_line "  debug - Enable debug log output."
 help_add_line "  release_dir=<dir> - Override default release directory."
 help_add_line "    Default directory is 'autobuild_release' under OpenWrt's source directory."
+help_add_line "  sync_config - When used with menuconfig, .config will be updated with"
+help_add_line "    current branch defconfigs before starting menuconfig"
 
 # Include branch rules (the rule is child level overriding parent level)
 . "${ab_root}/rules"
diff --git a/autobuild/unified/rules b/autobuild/unified/rules
index d6a2735..8dbff95 100755
--- a/autobuild/unified/rules
+++ b/autobuild/unified/rules
@@ -535,11 +535,8 @@
 
 	openwrt_config_file="${openwrt_root}/.config"
 
-	exec_log "make -C \"${openwrt_root}\" menuconfig scripts/config/aconf"
-
 	if test ${ab_branch_level} -eq 1; then
-		exec_log "STAGING_DIR_HOST=\"${openwrt_root}/staging_dir/host\" \"${openwrt_root}/scripts/config/aconf\" -m -M -o \"${ab_platform_dir}/${openwrt_branch}/defconfig\" -k \"${openwrt_root}/Config.in\" \"${openwrt_config_file}\""
-		return
+		final_file="${ab_platform_dir}/${openwrt_branch}/defconfig"
 	fi
 
 	if test ${ab_branch_level} -ge 2; then
@@ -557,5 +554,17 @@
 		final_file="${ab_variant_dir}/${openwrt_branch}/defconfig"
 	fi
 
+	if test x"${sync_config_set}" == x"yes"; then
+		exec_log "rm -f \"${openwrt_config_file}.old\""
+		exec_log "STAGING_DIR_HOST=\"${openwrt_root}/staging_dir/host\" \"${openwrt_root}/scripts/config/aconf\" -m -o \"${openwrt_config_file}\" -k \"${openwrt_root}/Config.in\" ${kconfig_files} \"${final_file}\""
+	fi
+
+	exec_log "make -C \"${openwrt_root}\" menuconfig scripts/config/aconf"
+
+	if test ${ab_branch_level} -eq 1; then
+		exec_log "STAGING_DIR_HOST=\"${openwrt_root}/staging_dir/host\" \"${openwrt_root}/scripts/config/aconf\" -m -M -o \"${ab_platform_dir}/${openwrt_branch}/defconfig\" -k \"${openwrt_root}/Config.in\" \"${openwrt_config_file}\""
+		return
+	fi
+
 	exec_log "STAGING_DIR_HOST=\"${openwrt_root}/staging_dir/host\" \"${openwrt_root}/scripts/config/aconf\" -d -o \"${final_file}\" -k \"${openwrt_root}/Config.in\" -n \"${openwrt_config_file}\" ${kconfig_files}"
 }