def WorkHorse(cls, rules): """Runs the workhorse for the command. Args: rules: list: List of rules to be handled. Return: (list, list): Returns a tuple of list in the form (successful_rules, failed_rules) specifying rules that succeeded and ones that failed. """ # Create the user friendly link to bin dir if it doesn't already exist. FileUtils.CreateLink(FileUtils.GetEDir(), FileUtils.GetBinDir()) # Create the link to the web test directory if it exists if os.path.exists(FileUtils.GetWebTestHtmlLink()): FileUtils.CreateLink(FileUtils.GetWebTestHtmlLink(), FileUtils.GetWebTestHtmlDir()) gen_makefile = GenMakefile(Flags.ARGS.debug) gen_makefile.GenMainMakeFile() (success_genmake, failed_genmake) = gen_makefile.GenAutoMakeFileFromRules( rules, Flags.ARGS.allowed_rule_types) (success_make, failed_make) = cls._MakeRules(success_genmake, gen_makefile.GetMakeFileName()) return (success_make, failed_genmake + failed_make)
def WriteMakefile(cls, specs, makefile): """Writes the auto make file for the given spec. Args: specs: List of dict of type {target, target_type, src, urls, ...}. Each dict contains everything needed to build 'target' makefile: The (auto) makefile to generate. """ f = open(makefile, 'w') index = 0 for item in specs: index += 1 target = item['_target'] target_bin = FileUtils.GetBinPathForFile(target) f.write('\n# Srcs for %s\n' % target) f.write('NGE2E_SRC_%d = %s\n' % (index, str.join('\\\n ', item.get('src', set())))) hostname = socket.gethostname() # read in the template and insert the proper javascript tmpl_f = open(Flags.ARGS.nge2e_template, 'r') tmpl_js = cls.GenerateTemplateJs(item.get('src'), item.get('deps')) tmpl = tmpl_f.read() test_html_content = tmpl.replace(Flags.ARGS.nge2e_replace_str, tmpl_js) timeout = item.get('timeout', Flags.ARGS.nge2e_timeout) # Write the target. f.write('\n%s' % target) f.write(': $(NGE2E_SRC_%d)\n' % (index)) type = item.get('_type', 'invalid') if type == 'nge2e_test': # test name name = item['name'] # write the test html test_html_fn = os.path.join(FileUtils.GetWebTestHtmlDir(), '%s.html' % name) test_html_f = open(test_html_fn, 'w') test_html_f.write(test_html_content) # the test url test_url = 'https://%s%s/%s.html' % (hostname, FileUtils.GetWebTestHtmlUrlPath(), name) f.write('\t@echo "Creating Test for %s "\n' % target) f.write('\t@mkdir -p $(dir %s)\n' % target_bin) f.write('\t@echo "# ng Unit Test for %s" > %s\n' % (target, target_bin)) f.write('\t@echo \'%s %s "%d" \' >> %s\n' % (cls.PhantomJSCmd(), test_url, timeout, target_bin)) f.write('\tchmod 754 %s\n' % target_bin) f.write('\t@ln -s -f %s $(BINDIR)/$(notdir $@)\n' % target_bin) f.write('\t@mkdir -p $(dir %s)\n' % test_html_fn) f.write('\t@\n') f.write('\t@echo "Created: %s"\n' % target_bin) f.write('\t@echo "Finished: $@"\n\n') f.write('\n\n') f.close()