Skip to content

Commit

Permalink
Improving/refactoring code.
Browse files Browse the repository at this point in the history
* Fix ARGV handling, pass it via environment.
* Generate initial .gitignore file when generating project.
* Fetch now using Rugged in places rather than invoking git.
* Remove old depreated code paths, move text processing to `build-text` gem.
* Remove generators.
  • Loading branch information
ioquatix committed Jul 6, 2017
1 parent cb6f4d6 commit 5217c1f
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 1,040 deletions.
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--color
--format documentation
--backtrace
--warnings
Expand Down
2 changes: 1 addition & 1 deletion bin/teapot
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rescue Teapot::IncompatibleTeapotError => error
rescue Teapot::Dependency::UnresolvedDependencyError => error
$stderr.puts "Unresolved dependencies:"

error.chain.unresolved.each do |(name, parent)|
error.chain.unresolved.each do |name, parent|
$stderr.puts "#{parent} depends on #{name.inspect}".color(:red)

conflicts = error.chain.conflicts[name]
Expand Down
4 changes: 1 addition & 3 deletions lib/teapot/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
require_relative 'command/clean'
require_relative 'command/create'
require_relative 'command/fetch'
require_relative 'command/generate'
require_relative 'command/list'
require_relative 'command/status'
require_relative 'command/visualize'
Expand All @@ -51,15 +50,14 @@ class Top < Samovar::Command

options do
option '-c/--configuration <name>', "Specify a specific build configuration.", default: ENV['TEAPOT_CONFIGURATION']
option '-i/--in/--root <path>', "Work in the given root directory."
option '--root <path>', "Work in the given root directory."
option '--verbose | --quiet', "Verbosity of output for debugging.", key: :logging
option '-h/--help', "Print out help information."
option '-v/--version', "Print out the application version."
end

nested '<command>',
'create' => Create,
'generate' => Generate,
'fetch' => Fetch,
'list' => List,
'status' => Status,
Expand Down
7 changes: 2 additions & 5 deletions lib/teapot/command/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class Build < Samovar::Command
def invoke(parent)
context = parent.context

# TODO: This is a bit of a hack, figure out a way to pass it directly through to build subsystem.
ARGV.replace(@argv) if @argv

chain = context.dependency_chain(@targets, context.configuration)

ordered = chain.ordered
Expand All @@ -57,9 +54,9 @@ def invoke(parent)
ordered.each do |resolution|
target = resolution.provider

environment = target.environment(context.configuration, chain)

if target.build
environment = target.environment(context.configuration, chain, @argv)

controller.add_target(target, environment.flatten)
end
end
Expand Down
16 changes: 10 additions & 6 deletions lib/teapot/command/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class Create < Samovar::Command
self.description = "Create a new teapot package using the specified repository."

options do
option "-g/--generator-name <name>", "The generator to use to create the project", default: 'project'
option "-t/--target-name <name>", "The target to use to create the project", default: 'project'
end

one :project_name, "The name of the new project in title-case, e.g. 'My Project'."
one :source, "The source repository to use for fetching packages, e.g. https://github.com/kurocha."
many :packages, "Any additional packages you'd like to include in the project."

def generator_name
@options[:generator_name]
def target_name
@options[:target_name]
end

def invoke(parent)
Expand All @@ -65,8 +65,8 @@ def invoke(parent)
context = nested.context

# Generate the default project if it is possible to do so:
if context.generators.include?(generator_name)
Generate['--force', generator_name, project_name].invoke(nested)
if context.targets.include?(target_name)
Build[target_name, '--', project_name].invoke(nested)

# Fetch any additional packages:
Fetch[].invoke(nested)
Expand All @@ -76,7 +76,7 @@ def invoke(parent)

Rugged::Commit.create(repository,
tree: index.write_tree(repository),
message: "Generating ",
message: "Initial project files.",
parents: repository.empty? ? [] : [repository.head.target].compact,
update_ref: 'HEAD'
)
Expand All @@ -86,6 +86,10 @@ def invoke(parent)
def generate_project(root, project_name, source, packages)
name = ::Build::Name.new(project_name)

File.open(root + ".gitignore", "w") do |output|
output.puts "teapot/"
end

File.open(root + TEAPOT_FILE, "w") do |output|
output.puts "\# Teapot v#{VERSION} configuration generated at #{Time.now.to_s}", ''

Expand Down
11 changes: 7 additions & 4 deletions lib/teapot/command/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# THE SOFTWARE.

require 'samovar'
require_relative '../repository'
require 'rugged'

module Teapot
module Command
Expand Down Expand Up @@ -140,8 +140,10 @@ def clone_or_pull_package(context, configuration, package, package_lock, logger)

begin
external_url = package.external_url(context.root)

Repository.new(destination_path).clone!(external_url, branch, commit)

repository = Rugged::Repository.clone_at(external_url.to_s, destination_path.to_s, checkout_branch: branch)
repository.checkout(commit) if commit
# Repository.new().clone!(external_url, branch, commit)
rescue
logger.info "Failed to clone #{external_url}...".color(:red)

Expand All @@ -151,7 +153,8 @@ def clone_or_pull_package(context, configuration, package, package_lock, logger)
logger.info "Updating package at path #{destination_path} ...".color(:cyan)

commit = package_lock ? package_lock[:commit] : nil
Repository.new(destination_path).update(branch, commit)
Rugged::Repository.new(destination_path.to_s).checkout(commit)
# Repository.new(destination_path).update(branch, commit)
end
end

Expand Down
61 changes: 0 additions & 61 deletions lib/teapot/command/generate.rb

This file was deleted.

28 changes: 21 additions & 7 deletions lib/teapot/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require_relative 'package'

require 'build/rulebook'
require 'build/text/substitutions'

module Teapot
TEAPOT_FILE = 'teapot.rb'.freeze
Expand All @@ -47,7 +48,6 @@ def initialize(root, options = {})
@options = options

@targets = {}
@generators = {}
@configurations = {}
@projects = {}
@rules = Build::Rulebook.new
Expand All @@ -66,7 +66,6 @@ def initialize(root, options = {})
attr :options

attr :targets
attr :generators
attr :projects

# Context metadata
Expand All @@ -90,6 +89,25 @@ def repository
@repository ||= Rugged::Repository.new(@root.to_s)
end

def substitutions
substitutions = Build::Text::Substitutions.new

if @project
substitutions['PROJECT_NAME'] = @project.name
substitutions['LICENSE'] = @project.license
end

# The user's current name:
substitutions['AUTHOR_NAME'] = repository.config['user.name']
substitutions['AUTHOR_EMAIL'] = repository.config['user.email']

current_date = Time.new
substitutions['DATE'] = current_date.strftime("%-d/%-m/%Y")
substitutions['YEAR'] = current_date.strftime("%Y")

return substitutions
end

def select(names)
names.each do |name|
if @targets.key? name
Expand All @@ -105,7 +123,7 @@ def dependency_chain(dependency_names, configuration = @configuration)

select(dependency_names)

Dependency::Chain.expand(@dependencies, @targets.values, @selection)
Build::Dependency::Chain.expand(@dependencies, @targets.values, @selection)
end

def direct_targets(ordered)
Expand All @@ -121,10 +139,6 @@ def << definition
AlreadyDefinedError.check(definition, @targets)

@targets[definition.name] = definition
when Generator
AlreadyDefinedError.check(definition, @generators)

@generators[definition.name] = definition
when Configuration
# We define configurations in two cases, if they are public, or if they are part of the root package of this context.
if definition.public? or definition.package == @root_package
Expand Down
25 changes: 0 additions & 25 deletions lib/teapot/dependency.rb

This file was deleted.

Loading

0 comments on commit 5217c1f

Please sign in to comment.