当一个项目有很多需求时,很有必要做一个工程管理,试想,有十个客户,每个客户又有多个品牌,每个品牌又有不同的市场,要是每个对应的需求都去开个单独的工程代码,这样不仅不利于资源共享,而且难以维护。做程序员就要有一种“懒”的意识,把繁琐的事情简单化,把复杂的事情明了化。这样维护方便快捷,即便你哪天要走了,交接也相当的方便,不必去写长长的文档,接收人还看的云里雾里。当然,我也十分佩服那些没做工程管理但是发布的软件版本不出错的。
以下是我在MTK项目中做的一个工程拷贝。目录结构如下:
根目录为project,二级目录为工程名,三级目录为客户,四级目录为市场。在四级目录里面放置了各个工程所需的文件,编译时会拷贝到对应的路径。
运行需要有Perl解析器,我安装的是ActivePerl-5.8.8.822-MSWin32-x86-280952.msi
运行效果如下:
代码如下:
#!/usr/local/bin/perl
use Cwd;
#******************************************************************************#
# File created for select project
# Author: Jerome
# Date: 2012-09-11
#******************************************************************************#
#------------------------ prject file name param --------------------------------------------------#
# If configure new release code from MTK, please remember modify $mak_type and $network_type !
my $mak_type = "MAUI_KHAN50V11_12864_11B";
my $network_type = "GPRS";
my $LCD_SIZE;
my $theme_type;
#--------------------------------------------------------------------------------------------------#
my $curr_dir = getcwd;
my $project_root = "project";
my $project_dir;
my $customer_dir;
my $market_dir;
my $filter_char;
my $input_hint;
my $TBL_PROJECT = "PROJECT";
my $TBL_CUSTOMER = "CUSTOMER";
my $TBL_MARKET = "MARKET";
my %type_tbl =
(
$TBL_PROJECT => 0,
$TBL_CUSTOMER => 1,
$TBL_MARKET => 2,
);
ListAllType2Select("$project_root", $type_tbl{$TBL_PROJECT});
ListAllType2Select("$project_root\\$project_dir", $type_tbl{$TBL_CUSTOMER});
ListAllType2Select("$project_root\\$project_dir\\$customer_dir", $type_tbl{$TBL_MARKET});
CopyFiles2UpdateProject("$project_root\\$project_dir\\$customer_dir\\$market_dir");
SaveCurrProjectInfo2Log("$project_dir", "$customer_dir", "$market_dir");
#------------------------------------------------------------------------------------#
sub SaveCurrProjectInfo2Log
{
my $log_file = $curr_dir."\\project_info.log";
my ($proj, $customer, $market) = @_;
GetTypeInfo($type_tbl{$TBL_PROJECT});
$proj =~ s/$filter_char//g;
GetTypeInfo($type_tbl{$TBL_CUSTOMER});
$customer =~s/$filter_char//g;
GetTypeInfo($type_tbl{$TBL_MARKET});
$market =~ s/$filter_char//g;
open(FILE, ">$log_file");
print FILE "\n";
print FILE "configure project success !\n\n";
print FILE "project: $proj \n\n";
print FILE "customer: $customer \n\n";
print FILE "market: $market \n\n";
close(FILE);
}
#------------------------------------------------------------------------------------#
sub CopyFiles2UpdateProject
{
my ($proj_dir) = @_;
GetProjectIniFileInfo("$proj_dir");
my $codegen = "codegen.dws";
my $codegen_dir = "custom\\codegen\\".$mak_type."_BB\\$codegen";
my $memorydevice = "custom_memorydevice.h";
my $memorydevice_dir = "custom\\system\\".$mak_type."_BB\\$memorydevice";
my $mak_option = $mak_type."_".$network_type.".mak";
my $mak_option_dir = "make\\".$mak_option;
my $customer_define = "customer_define.mak";
my $customer_define_dir = "make\\$customer_define";
my $version = "Verno_".$mak_type.".bld";
my $version_dir = "make\\".$version;
my $feature_config = "MMI_features_switch$mak_type.h";
my $feature_config_dir = "plutommi\\Customer\\CustResource\\".$mak_type."_MMI\\".$feature_config;
my $theme = "Themecomponents.h";
my $theme_dir = "plutommi\\Customer\\LcdResource\\MainLcd$LCD_SIZE\\$theme_type\\$theme";
my $nvram_audio = "nvram_default_audio.c";
my $nvram_audio_dir = "custom\\audio\\".$mak_type."_BB\\".$nvram_audio;
(-e "$proj_dir\\$codegen") ? system("copy /y $proj_dir\\$codegen $codegen_dir") : print "$codegen is not exist !\n";
(-e "$proj_dir\\$memorydevice") ? system("copy /y $proj_dir\\$memorydevice $memorydevice_dir") : print "$memorydevice is not exist !\n";
(-e "$proj_dir\\$mak_option") ? system("copy /y $proj_dir\\$mak_option $mak_option_dir") : print "$mak_option is not exist !\n";
(-e "$proj_dir\\$customer_define") ? system("copy /y $proj_dir\\$customer_define $customer_define_dir") : print "$customer_define is not exist !\n";
(-e "$proj_dir\\$version") ? system("copy /y $proj_dir\\$version $version_dir") : print "$version is not exist !\n";
(-e "$proj_dir\\$feature_config") ? system("copy /y $proj_dir\\$feature_config $feature_config_dir") : print "$feature_config is not exist !\n";
(-e "$proj_dir\\$theme") ? system("copy /y $proj_dir\\$theme $theme_dir") : print "$theme is not exist !\n";
(-e "$proj_dir\\$nvram_audio") ? system("copy /y $proj_dir\\$nvram_audio $nvram_audio_dir") : print "$nvram_audio is not exist !\n";
}
#------------------------------------------------------------------------------------#
sub GetProjectIniFileInfo
{
my @MakContent;
my @ConfigIniContent;
my ($file_dir) = @_;
my $ConfigIni = $file_dir."\\configure.ini";
my $mak = $file_dir."\\".$mak_type."_".$network_type.".mak";
open(MAK, "< $mak") or die "cannot read \"$mak\" file, check please !\n";
@MakContent=<MAK>;
close(MAK);
for my $line (@MakContent)
{
$line =~ s/\s//g;
if ($line =~ /^MAIN_LCD_SIZE\s*=\s*(.*)/)
{
$LCD_SIZE = $1;
last;
}
}
open(CONFIG, "< $ConfigIni") or die "cannot read \"$ConfigIni\" file, check please !\n";
@ConfigIniContent=<CONFIG>;
close(CONFIG);
for my $line (@ConfigIniContent)
{
$line =~ s/\s//g;
if ($line =~ /^THEME_TYPE\s*=\s*(.*)/)
{
$theme_type = $1;
last;
}
}
}
#------------------------------------------------------------------------------------#
sub ListAllType2Select
{
my $dir;
my $list_type;
my @list;
my @name;
my $num = 0;
my $sel_index = 0;
my $sel_content;
my ($dir, $list_type) = @_;
GetTypeInfo($list_type);
opendir(LIST, $dir) or die "Cannot open $dir! \n";
@list = readdir(LIST);
foreach (@list)
{
if ($_ =~ /$filter_char(.*)/)
{
push @name, $_;
print " $num ";
$_ =~ s/$filter_char//g;
print " - ", $_, "\n";
$num++;
}
}
closedir(LIST);
if($num <= 0)
{
print "$input_hint is not exist, please check ! \n";
exit(0);
}
print "$input_hint:";
chomp($sel_index = <STDIN>);
CheckInputIndexValid($sel_index, $num);
$sel_content = @name[$sel_index];
UpdateCurrSelDir($sel_content, $list_type);
}
#------------------------------------------------------------------------------------#
sub UpdateCurrSelDir
{
my ($content, $type) = @_;
if($type == $type_tbl{$TBL_PROJECT})
{
$project_dir = $content;
}
elsif($type == $type_tbl{$TBL_CUSTOMER})
{
$customer_dir = $content;
}
elsif($type == $type_tbl{$TBL_MARKET})
{
$market_dir = $content;
}
}
#------------------------------------------------------------------------------------#
sub GetTypeInfo
{
$filter_tmp;
$hint;
my ($type) = @_;
if($type == $type_tbl{$TBL_PROJECT})
{
$filter_tmp = "project_";
$hint = "project";
}
elsif($type == $type_tbl{$TBL_CUSTOMER})
{
$filter_tmp = "customer_";
$hint = "customer";
}
elsif($type == $type_tbl{$TBL_MARKET})
{
$filter_tmp = "market_";
$hint = "market";
}
else
{
print "Function:ListAllType, error param ! \n";
exit(0);
}
$filter_char = $filter_tmp;
$input_hint = $hint;
}
#------------------------------------------------------------------------------------#
sub CheckInputIndexValid
{
my $error_flag = 0;
my ($sel_index, $max_index) = @_;
if ( ($sel_index ne "") && ($sel_index !~ /[A-Za-z]/) )
{
if($sel_index =~ /^[0-9][0-9]*$/ && $sel_index >= 0 && $sel_index < $max_index)
{
# do nothing
}
else
{
$error_flag = 1;
}
}
else
{
$error_flag = 1;
}
if($error_flag > 0)
{
print "Error input, please configure again ! \n";
exit(0);
}
}
#------------------------------------------------------------------------------------#
整个工程可以到我的资源中下载http://download.csdn.net/detail/jerome_home/4918560