From 8acd532bb3d9542d66df81aa287d26bf24813a72 Mon Sep 17 00:00:00 2001 From: "y0169.zhang" Date: Wed, 10 Jan 2018 10:34:00 +0800 Subject: [PATCH] Add the function to output each package's reverse dependency Change-Id: I0f06ed6c8ab1d60985989e24a7f999d1eee5be45 --- depanneur | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/depanneur b/depanneur index c7a66fd..fe49fe1 100755 --- a/depanneur +++ b/depanneur @@ -115,6 +115,7 @@ my $localrepo = "$build_root/local/repos"; # generated local repo dir my $order_dir = "$build_root/local/order"; # intermediate repo data file, which # contains all information, including # dependency,provides,filepath +my $depends_dir = "$build_root/local/depends"; # package's reverse dependency dir my $cache_dir = "$build_root/local/cache"; # cache binary rpms downloaded from remote repos my $groupfile="$build_root/meta/group.xml";# group information for yum @@ -183,6 +184,7 @@ my $vminitrd = ""; my $vmkernel = ""; my $vmswapsize = ""; my $disable_debuginfo = 0;#disable debuginfo when using build cmd +my $depends = 0; #depends subcommand to put reverse dependency GetOptions ( "repository=s" => \@repos, @@ -238,6 +240,7 @@ GetOptions ( "vm-kernel=s" => \$vmkernel, "vm-swap=s" => \$vmswapsize, "disable-debuginfo" => \$disable_debuginfo, + "depends" => \$depends, ); if ( $help ) { @@ -2354,8 +2357,109 @@ sub get_binary_list() { return @bins; } +sub generate_depends() { + ($_, $start_time) = my_system("date +\"%Y-%m-%d %H:%M %z\""); + ($_, $gbs_version) = my_system("gbs -V"); + $gbs_version =~ s!gbs !!; + + if ($style eq 'git') { + File::Find::find({wanted => \&git_wanted}, $package_path ); + if (@pre_packs > 1 && $commit ne "HEAD"){ + error("--commit option can't be specified with multiple packages"); + } + if (@pre_packs == 0) { + error("No source package found at $package_path"); + } + foreach my $p (@pre_packs) { + my $specs = $p->{"filename"}; + my $new_p; + $new_p->{"project_base_path"} = $p->{"project_base_path"}; + $new_p->{"packaging_dir"} = $p->{"packaging_dir"}; + $new_p->{"upstream_branch"} = $p->{"upstream_branch"}; + $new_p->{"upstream_tag"} = $p->{"upstream_tag"}; + my @spec_list = split(",", $specs); + foreach my $spec (@spec_list) { + $new_p->{"filename"} = $spec; + push @packs, $new_p; + } + } + } else { + @packs = @ARGV; + if (@packs == 0) { + File::Find::find({wanted => \&obs_wanted}, $package_path ); + } + } + + info("retrieving repo metadata..."); + my $repos_setup = 1; + my_system("> $order_dir/.repo.cache.local"); + if (-d "$rpm_repo_path") { + my_system("$build_dir/createdirdeps $rpm_repo_path >> $order_dir/.repo.cache.local"); + my_system("echo D: >> $order_dir/.repo.cache.local"); + } + my_system("> $order_dir/.repo.cache.remote"); + foreach my $repo (@package_repos) { + my $cmd = ""; + if ($repo =~ /^\// && ! -e "$repo/repodata/repomd.xml") { + $cmd = "$build_dir/createdirdeps $repo >> $order_dir/.repo.cache.remote "; + } else { + $cmd = "$build_dir/createrepomddeps --cachedir=$cache_dir $repo >> $order_dir/.repo.cache.remote "; + } + debug($cmd); + if ( my_system($cmd) == 0 ) { + my_system("echo D: >> $order_dir/.repo.cache.remote"); + } else { + $repos_setup = 0; + } + } + # Merge local repo cache and remote repo cache + my_system("cat $order_dir/.repo.cache.local $order_dir/.repo.cache.remote >$order_dir/.repo.cache"); + + if ($repos_setup == 0 ) { + error("repo cache creation failed..."); + } + + info("parsing package data..."); + my %packs = parse_packs($config, @packs); + %to_build = %packs; + + # Create & Update package dependency + info("building repo metadata ..."); + refresh_repo(); + + info("package dependency resolving ..."); + update_pkgdeps(); + update_pkgddeps(); + + if (scalar (keys %to_build) == 0) { + warning("no available packages to generate depends."); + return; + } + + my $out = "$depends_dir/$dist/$arch/"; + mkdir_p($out); + + my $total = scalar (keys %to_build); + my $index = 1; + foreach my $p (keys %to_build) { + info("[$index/$total] generating $p.full_edges.vis_input.js..."); + open(my $f, '>', "$out/$p.full_edges.vis_input.js") or die "Could not open file '$out/$p.full_edges.vis_input.js' $!"; + print $f "label: '$p'\n"; + foreach my $dep (@{$pkgrdeps{$p}}) { + print $f "label: '$dep'\n"; + } + close $f; + $index++; + } +} # MAIN +if ($depends) { + info("start generate packages depends from: " . $package_path . " ($style)"); + generate_depends(); + exit 0; +} + info("start building packages from: " . $package_path . " ($style)"); ($_, $start_time) = my_system("date +\"%Y-%m-%d %H:%M %z\""); ($_, $gbs_version) = my_system("gbs -V"); -- 2.7.4