From 722206ebac5cd90bd463ce1711b0ae649f85714b Mon Sep 17 00:00:00 2001 From: Luis Padron Date: Thu, 6 Jan 2022 03:10:27 -0500 Subject: [PATCH] Feat: Update fourier to use system tuist whenever possible (#3950) --- hooks/pre-commit | 3 +-- projects/fourier/lib/fourier.rb | 6 +++--- .../lib/fourier/services/build/tuist/all.rb | 1 - projects/fourier/lib/fourier/services/focus.rb | 9 ++++----- .../lib/fourier/services/test/tuist/unit.rb | 1 - projects/fourier/lib/fourier/services/tuist.rb | 2 +- projects/fourier/lib/fourier/utilities/system.rb | 15 ++++++++++----- .../fourier/test/fourier/services/focus_test.rb | 6 +++--- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/hooks/pre-commit b/hooks/pre-commit index 8cdc7b2b0..da1a40241 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -1,4 +1,3 @@ #!/bin/bash -./fourier lint swift -./fourier lint ruby \ No newline at end of file +./fourier lint all \ No newline at end of file diff --git a/projects/fourier/lib/fourier.rb b/projects/fourier/lib/fourier.rb index c6205c377..3ef90c143 100644 --- a/projects/fourier/lib/fourier.rb +++ b/projects/fourier/lib/fourier.rb @@ -46,9 +46,9 @@ module Fourier desc "encrypt", "Encrypt content in the repository" subcommand "encrypt", Commands::Encrypt - desc "focus TARGET", "Generate Tuist's project focusing on the target TARGET" - def focus(target = nil) - Services::Focus.call(target: target) + desc "focus TARGETS", "Generate Tuist's project focusing on the target TARGET" + def focus(*targets) + Services::Focus.call(targets: targets) end desc "tuist", "Runs Tuist" diff --git a/projects/fourier/lib/fourier/services/build/tuist/all.rb b/projects/fourier/lib/fourier/services/build/tuist/all.rb index 26625aaf6..7200fea06 100644 --- a/projects/fourier/lib/fourier/services/build/tuist/all.rb +++ b/projects/fourier/lib/fourier/services/build/tuist/all.rb @@ -8,7 +8,6 @@ module Fourier def call dependencies = ["dependencies", "fetch"] Utilities::System.tuist(*dependencies) - Utilities::System.tuist("build", "--generate") end end diff --git a/projects/fourier/lib/fourier/services/focus.rb b/projects/fourier/lib/fourier/services/focus.rb index cb990f1ff..b5bcdc173 100644 --- a/projects/fourier/lib/fourier/services/focus.rb +++ b/projects/fourier/lib/fourier/services/focus.rb @@ -3,10 +3,10 @@ module Fourier module Services class Focus < Base - attr_reader :target + attr_reader :targets - def initialize(target:) - @target = target + def initialize(targets:) + @targets = targets end def call @@ -16,8 +16,7 @@ module Fourier cache_warm = ["cache", "warm", "--dependencies-only"] Utilities::System.tuist(*cache_warm) - focus = ["focus"] - focus << "#{target}" if target != nil + focus = ["focus"] + targets Utilities::System.tuist(*focus) end end diff --git a/projects/fourier/lib/fourier/services/test/tuist/unit.rb b/projects/fourier/lib/fourier/services/test/tuist/unit.rb index 125bb4f16..41d8a0bd5 100644 --- a/projects/fourier/lib/fourier/services/test/tuist/unit.rb +++ b/projects/fourier/lib/fourier/services/test/tuist/unit.rb @@ -8,7 +8,6 @@ module Fourier def call dependencies = ["dependencies", "fetch"] Utilities::System.tuist(*dependencies) - Utilities::System.tuist("test") Dir.chdir(Constants::TUIST_DIRECTORY) do Utilities::System.system("swift", "test") diff --git a/projects/fourier/lib/fourier/services/tuist.rb b/projects/fourier/lib/fourier/services/tuist.rb index adf5437b7..6d319b366 100644 --- a/projects/fourier/lib/fourier/services/tuist.rb +++ b/projects/fourier/lib/fourier/services/tuist.rb @@ -12,7 +12,7 @@ module Fourier def call Utilities::SwiftPackageManager.build_product("ProjectAutomation") Utilities::SwiftPackageManager.build_product("ProjectDescription") - Utilities::System.tuist(*arguments) + Utilities::System.tuist(*arguments, from_source: true) end end end diff --git a/projects/fourier/lib/fourier/utilities/system.rb b/projects/fourier/lib/fourier/utilities/system.rb index 630001133..2423d8706 100644 --- a/projects/fourier/lib/fourier/utilities/system.rb +++ b/projects/fourier/lib/fourier/utilities/system.rb @@ -9,12 +9,17 @@ module Fourier Kernel.system(*args) || exit(1) end - def self.tuist(*args) - Dir.chdir(Constants::TUIST_DIRECTORY) do - self.system("swift", "build") - @tuist = ".build/debug/tuist" - self.system(@tuist, *args) + def self.tuist(*args, **kwargs) + @tuist = "/usr/local/bin/tuist" + + if kwargs[:from_source] || !File.exist?(@tuist) + Dir.chdir(Constants::TUIST_DIRECTORY) do + self.system("swift", "build") + @tuist = ".build/debug/tuist" + end end + + self.system(@tuist, *args) end def self.fixturegen(*args) diff --git a/projects/fourier/test/fourier/services/focus_test.rb b/projects/fourier/test/fourier/services/focus_test.rb index 963813371..91fde67cb 100644 --- a/projects/fourier/test/fourier/services/focus_test.rb +++ b/projects/fourier/test/fourier/services/focus_test.rb @@ -13,13 +13,13 @@ module Fourier Utilities::System .expects(:tuist) .with("dependencies", "fetch") - target = "TuistSupport" + targets = ["TuistSupport", "TuistSupportTests"] Utilities::System .expects(:tuist) - .with("focus", target) + .with("focus", *targets) # Then - Services::Focus.call(target: target) + Services::Focus.call(targets: targets) end end end