-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
plans/build_order.rb
which generates a build order for Plans.
The `plans/build_order.rb` is a Ruby program with no external library dependencies, but it may call out to the `plans/build-base-plans.sh` program which is assumed to be in the same directory. The program is fed paths to `plan.sh` files on stdin which are used as the input set of packages and dependencies. For example: find . -name plan.sh | ./plans/build_order.rb Would find all plans in our project and determine the build order for all of them. At the moment, only `core` origin Plans are considered (the rest are ignored). If the base set of packages have been built, as is usually the case, you can add a `--without-base` flag to the program which, after sorting, will remove all package identifers contained in the `plans/build-base-plans.sh` program--which gets called with a `$PRINT_IDENTS_ONLY` environment variable set. For example: find . -name plan.sh | ./plans/build_order.rb --without-base Note that this program can be run on a Mac (which has a version of Ruby already), in the devshell (assuming you install a Ruby package), or in a Studio (assuming you build/install a `core/ruby`). Signed-off-by: Fletcher Nichol <fnichol@nichol.ca> Pull request: #464 Approved by: smith
- Loading branch information
Showing
6 changed files
with
119 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'delegate' | ||
require 'optparse' | ||
require 'tsort' | ||
require 'tempfile' | ||
|
||
# Command line parser | ||
class Cli | ||
def self.parse(argv) # rubocop:disable Metrics/MethodLength | ||
options = { with_base: true } | ||
parser = OptionParser.new do |opts| | ||
opts.banner = "Usage: #{File.basename(__FILE__)} [--without-base]" | ||
opts.on('--without-base', "Don't include base packages in result") do |_| | ||
options[:with_base] = false | ||
end | ||
opts.on('-h', '--help', 'Prints this help') do | ||
puts opts | ||
exit | ||
end | ||
opts.separator '' | ||
opts.separator 'Examples:' | ||
opts.separator " find . -name plan.sh | #{__FILE__}" | ||
opts.separator " find . -name plan.sh | #{__FILE__} --without-base" | ||
end | ||
parser.parse!(argv) | ||
options | ||
end | ||
end | ||
|
||
# Dependency tracker. | ||
class Sortable < SimpleDelegator | ||
include TSort | ||
|
||
def add(ident, deps = []) | ||
__getobj__[ident] = deps | ||
end | ||
|
||
def tsort_each_node(&block) | ||
__getobj__.each_key(&block) | ||
end | ||
|
||
def tsort_each_child(node, &block) | ||
__getobj__.fetch(node).each(&block) | ||
end | ||
end | ||
|
||
options = Cli.parse(ARGV) | ||
|
||
bash_prog = Tempfile.new('print_deps.sh') | ||
bash_prog.write(<<'EOF') | ||
#!/bin/bash | ||
set -e | ||
STUDIO_TYPE=stage1 | ||
FIRST_PASS=true | ||
cd $(dirname $1) | ||
source $(basename $1) | ||
echo "${pkg_origin}/${pkg_name}" | ||
echo "${pkg_build_deps[*]} ${pkg_deps[*]}" | ||
exit 0 | ||
EOF | ||
bash_prog.close | ||
|
||
all_deps = Sortable.new({}) | ||
ARGF.each_line do |file| | ||
raw = `bash #{bash_prog.path} #{file}`.chomp | ||
ident, _, deps_str = raw.partition(/\n/) | ||
if ident.start_with?('core/') | ||
all_deps.add(ident, deps_str.split(' ') | ||
.map { |d| d.split('/').first(2).join('/') }) | ||
end | ||
end | ||
|
||
all_deps.keys.each do |ident| | ||
all_deps[ident].each do |dep| | ||
all_deps.add(dep) unless all_deps.key?(dep) | ||
end | ||
end | ||
|
||
sorted_deps = all_deps.tsort | ||
|
||
unless options[:with_base] | ||
prog = "#{File.dirname(__FILE__)}/build-base-plans.sh" | ||
raw = `env PRINT_IDENTS_ONLY=true #{prog}`.chomp | ||
base_deps = raw.split(/\n/) | ||
sorted_deps.delete_if { |dep| base_deps.include?(dep) } | ||
end | ||
|
||
puts sorted_deps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters