Skip to content

Commit 3868c24

Browse files
committed
Revert changes for putting output in build/ dir as per rake clobber commit.
revert build/ dir change new update up up
1 parent d63dc15 commit 3868c24

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

lib/rubex/compiler.rb

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class << self
2727
# programs.
2828
# @param files [Array[String]] nil An Array specifying the file names to
2929
# compile w.r.t the source_dir directory.
30-
# @param invoker [Symbol] nil Determines whether the invoker is a command line
31-
# program or a rake task. Affect build directory for rake task.
3230
#
3331
# TODO: The path can be relative to the source_dir if source_dir is specified.
3432
def compile path,
@@ -39,8 +37,7 @@ def compile path,
3937
make: false,
4038
debug: false,
4139
source_dir: nil,
42-
files: nil,
43-
invoker: nil
40+
files: nil
4441
CONFIG.flush
4542
CONFIG.debug = debug
4643
CONFIG.add_link "m" # link cmath libraries
@@ -57,9 +54,8 @@ def compile path,
5754
elsif test && multi_file
5855
return [tree, supervisor, ext]
5956
end
60-
write_files target_name, supervisor, ext, target_dir: target_dir, force: force,
61-
invoker: invoker
62-
full_path = build_path(target_dir, target_name, invoker: invoker)
57+
write_files target_name, supervisor, ext, target_dir: target_dir, force: force
58+
full_path = build_path(target_dir, target_name)
6359
load_extconf full_path
6460
run_make full_path if make
6561
end
@@ -124,12 +120,10 @@ def extract_target_name path
124120
# @param directory [String] nil Target directory in which files are to be placed.
125121
# @param force [Boolean] false Recreate the target directory and rewrite the
126122
# files whether they are already present or not.
127-
# @param invoker [Symbol|NilClass] nil Determines the build directory based on whether
128-
# it being invoked by a rake task or cmd.
129-
def write_files target_name, supervisor, ext, target_dir: nil, force: false, invoker: nil
130-
path = build_path(target_dir, target_name, invoker: invoker)
123+
def write_files target_name, supervisor, ext, target_dir: nil, force: false
124+
path = build_path(target_dir, target_name)
131125
FileUtils.rm_rf(path) if force && Dir.exist?(path)
132-
FileUtils.mkdir_p(path) unless Dir.exist?(path)
126+
Dir.mkdir(path) unless Dir.exist?(path)
133127

134128
write_to_file "#{path}/#{Rubex::COMMON_UTILS_FILE}.h",
135129
supervisor.header(Rubex::COMMON_UTILS_FILE).to_s
@@ -158,14 +152,10 @@ def run_make path
158152
#
159153
# @param directory [String] The directory inside which this build path will exist.
160154
# @param target_name [String] Name of the folder inside the directory.
161-
# @param invoker [Symbol|NilClass] nil The calling program. Can be :rake or :cmd.
162-
def build_path directory, target_name, invoker: nil
155+
def build_path directory, target_name
163156
directory = (directory ? directory.to_s : Dir.pwd)
164157
unless directory.end_with?(target_name)
165158
directory += "/#{target_name}"
166-
if invoker == :rake
167-
directory += "/build"
168-
end
169159
end
170160
directory
171161
end

lib/rubex/rake_task.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,28 @@ def define_compile_tasks
4141
desc "Compile a Rubex file into a shared object."
4242
task :compile do
4343
file_name = "#{@ext_dir}/#{@name}#{@source_pattern[1..-1]}"
44-
Rubex::Compiler.compile file_name, target_dir: "#{@ext_dir}", invoker: :rake
44+
Rubex::Compiler.compile file_name, target_dir: "#{@ext_dir}"
4545
end
4646

47-
desc "Delete all generated files inside build/ folder."
47+
desc "Delete all generated files."
4848
task :clobber do
49-
path = "#{@ext_dir}/#{@name}/build"
49+
path = @ext_dir
50+
unless path.end_with?(@name)
51+
path += "/#{@name}"
52+
end
53+
5054
Dir.chdir(path) do
5155
FileUtils.rm(
5256
Dir.glob(
5357
"#{path}/*.{c,h,so,o,bundle,dll}") + ["Makefile", "extconf.rb"], force: true
5458
)
5559
end
56-
FileUtils.rmdir(path)
5760
end
5861
end
5962
Rake::ExtensionTask.new(@name)
6063

6164
desc "Compile Rubex code into a .so file for use in Ruby scripts."
62-
task :compile => "rubex:compile"
65+
task "compile" => "rubex:compile"
6366
end
6467
end # class RakeTask
6568
end # module Rubex

spec/rake_task_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
end
4747
Rake::Task["rubex:compile"].invoke
4848

49-
build_path = "#{ext_path}/#{name}/build"
49+
build_path = "#{ext_path}/#{name}"
5050
expect(File.exist?("#{build_path}/#{name}.c")).to eq(true)
5151
expect(File.exist?("#{build_path}/extconf.rb")).to eq(true)
5252

@@ -69,12 +69,12 @@
6969
end
7070
end
7171

72-
context "rake:clobber" do
72+
context "rake:clobber", focus: :hell do
7373
before do
7474
Rake::Task.clear
7575
end
7676

77-
it "clobbers generated files inside build/ directory." do
77+
it "clobbers generated files." do
7878
ext_path = "#{Dir.pwd}/spec/fixtures/rake_task/single_file"
7979
name = "test"
8080
Rubex::RakeTask.new(name) do
@@ -83,8 +83,8 @@
8383
Rake::Task["rubex:compile"].invoke
8484
Rake::Task["rubex:clobber"].invoke
8585

86-
expect(!File.exist?("#{ext_path}/#{name}/build/#{name}.c")).to eq(true)
87-
expect(!File.exist?("#{ext_path}/#{name}/build/extconf.rb")).to eq(true)
86+
expect(!File.exist?("#{ext_path}/#{name}/#{name}.c")).to eq(true)
87+
expect(!File.exist?("#{ext_path}/#{name}/extconf.rb")).to eq(true)
8888
end
8989
end
9090

0 commit comments

Comments
 (0)