@@ -27,6 +27,8 @@ 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.
3032 #
3133 # TODO: The path can be relative to the source_dir if source_dir is specified.
3234 def compile path ,
@@ -37,7 +39,8 @@ def compile path,
3739 make : false ,
3840 debug : false ,
3941 source_dir : nil ,
40- files : nil
42+ files : nil ,
43+ invoker : nil
4144 CONFIG . flush
4245 CONFIG . debug = debug
4346 CONFIG . add_link "m" # link cmath libraries
@@ -54,8 +57,9 @@ def compile path,
5457 elsif test && multi_file
5558 return [ tree , supervisor , ext ]
5659 end
57- write_files target_name , supervisor , ext , target_dir : target_dir , force : force
58- full_path = build_path ( target_dir , target_name )
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 )
5963 load_extconf full_path
6064 run_make full_path if make
6165 end
@@ -120,10 +124,12 @@ def extract_target_name path
120124 # @param directory [String] nil Target directory in which files are to be placed.
121125 # @param force [Boolean] false Recreate the target directory and rewrite the
122126 # files whether they are already present or not.
123- def write_files target_name , supervisor , ext , target_dir : nil , force : false
124- path = build_path ( target_dir , target_name )
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 )
125131 FileUtils . rm_rf ( path ) if force && Dir . exist? ( path )
126- Dir . mkdir ( path ) unless Dir . exist? ( path )
132+ FileUtils . mkdir_p ( path ) unless Dir . exist? ( path )
127133
128134 write_to_file "#{ path } /#{ Rubex ::COMMON_UTILS_FILE } .h" ,
129135 supervisor . header ( Rubex ::COMMON_UTILS_FILE ) . to_s
@@ -147,10 +153,19 @@ def run_make path
147153 end
148154 end
149155
150- def build_path directory , target_name
156+ # Create build path for outputting .c and .h files. Will check whether the calling
157+ # process is a rake task or cmd.
158+ #
159+ # @param directory [String] The directory inside which this build path will exist.
160+ # @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
151163 directory = ( directory ? directory . to_s : Dir . pwd )
152164 unless directory . end_with? ( target_name )
153- directory += "/#{ target_name } "
165+ directory += "/#{ target_name } "
166+ if invoker == :rake
167+ directory += "/build"
168+ end
154169 end
155170 directory
156171 end
0 commit comments