def __GetWrapperFileName(cls, src): """Returns the C++ wrapper file name for the src. Args: src: string: The interface file for which the output is generated. Return: string: The output file name. """ return FileUtils.GetBinPathForFile(src).replace('.i', '.swig.cc')
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()
def __GetLibFileName(cls, src, name): """Returns the .so file name for the shared lib the .so file name is determined by the swig module name if the swig file starts with %module my_module, the lib file name will be _my_module.so Args: src: string: The interface file for which the output is generated. Return: string: The output file name. """ bin_path = FileUtils.GetBinPathForFile(src) return os.path.join(os.path.dirname(bin_path), '_%s.so' % name)
def WriteMakefile(cls, specs, makefile): """@override""" # TODO(edelman) modify this script to actually copy the file and simply # do the rsync in the run component. # To add a file to build you need to AT LEAST make the following edits: # create a new *_rules.py files. see pkg_rules.py for an example # edit gen_makefile.py and add the new type to ResetMakeFiles, GenMakeFile, # and GenAutoMakeFileFromRules (at the bottom). Then add the new AUTO_MAKEFILE_* # variable in Makefile.template. # In rules.py, add to the PARSED_RULE_TYPES and at the bottom, register the # global functions to be executed for the rule. # In build.py, edit the rules_map to include the new rule. # If the rule can be run, add to the allowed_rule_types in run.py i = 1 pkg_arg = '' if Flags.ARGS.pkg_version_path: pkg_arg += ' --pkg_version_path=%s ' % Flags.ARGS.pkg_version_path with open(makefile, 'w') as f: for spec in specs: pkg_flags = pkg_arg # check if the version is set. if so verify that it starts with numbers # and an underscore if Flags.ARGS.pkg_version_prefix: if not re.match('^\d+_', Flags.ARGS.pkg_version_prefix): raise Error(('pkg_version_prefix, %s, is invalid! must start with' + ' digits followed by underscore') \ % Flags.ARGS.pkg_version_prefix) pkg_flags += ' --pkg_version_prefix=%s ' % \ (Flags.ARGS.pkg_version_prefix) target = spec['_target'] target_bin = FileUtils.GetBinPathForFile(target) f.write('\n%s:\n' % target) f.write('\t@echo "Creating package name %s"\n' % spec['name']) f.write('\t@mkdir -p $(dir %s)\n' % target_bin) f.write( '\t@echo "$(SRCROOT)/prod/packager/packager.py %s %s" > %s\n' % (target, pkg_flags, 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@echo "Created: %s"\n' % target_bin) i += 1
def _RunSingeRule(cls, rule, pipe_output): """Runs a Single Rule. Args: rule: string: The rule to run. pipe_output: bool: Whether to pipe_output or dump it to STDOUT. Return: (int, string): Returns a tuple of the result status and the rule. The status is '1' for success, '0' for 'ignore', '-1' for fail. """ TermColor.Info('Running %s' % Utils.RuleDisplayName(rule)) start = time.time() bin_file = FileUtils.GetBinPathForFile(rule) (status, out) = ExecUtils.RunCmd('%s %s' % (bin_file, Flags.ARGS.args), Flags.ARGS.timeout, pipe_output) if status: TermColor.Failure('Failed Rule: %s' % Utils.RuleDisplayName(rule)) return (-1, rule) TermColor.Info('Ran %s. Took %.2fs' % (Utils.RuleDisplayName(rule), (time.time() - start))) # Everything done. Mark the rule as successful. return (1, rule)
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. """ url_param = cls.UrlParam() 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('JS_SRC_%d = %s\n' % (index, str.join('\\\n ', item.get('src', set())))) hostname = socket.gethostname() tests = set(item.get('test', set())) urls = [] for test in tests: test_dict = {} test_dict['test'] = test if 'src' in item: test_dict['dep'] = ['/%s' % \ FileUtils.FromAbsoluteToRepoRootPath(src) for src in item['src']] if test in test_dict['dep']: test_dict['dep'].remove(test) for url in item['urls']: components = url.split('#') unit = "&%s" % url_param # if empty string remove the ampersand if len(components) > 0 and not components[0]: unit = "%s" % url_param # if no url param add the question mark if len(url.split('?')) == 1: unit = "?%s" % url_param # equivalent to encodeuricomponent see: # http://stackoverflow.com/questions/946170/equivalent-javascript-functions-for-pythons-urllib-quote-and-urllib-unquote test_json = quote(json.dumps(test_dict), safe='~()*!.\'') # build the urls if len(components) == 1: urls.append('https://%s/%s%s=%s' % (hostname, components[0], unit, test_json)) elif len(components) == 2: urls.append('https://%s/%s%s=%s#%s' % \ (hostname, components[0], unit, test_json, components[1])) else: TermColor.Fatal("Unable to parse URL: %s" % url) timeout = item.get('timeout', cls.GetDefaultTimeout()) # Write the target. f.write('\n%s' % target) f.write(': $(JS_SRC_%d)\n' % (index)) type = item.get('_type', 'invalid') if type == cls.GetTestType(): f.write('\t@echo "Creating Test for %s "\n' % target) f.write('\t@mkdir -p $(dir %s)\n' % target_bin) f.write('\t@echo "# JS Test for %s" > %s\n' % (target, target_bin)) for url in urls: f.write('\t@echo \'%s "%s" "%d" $$@\' >> %s\n' % (cls.PhantomJSCmd(), 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@echo "Created: %s"\n' % target_bin) f.write('\t@echo "Finished: $@"\n\n') f.write('\n\n') f.close()
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, hdr, flag, link, pack}. In each dict, 'src', 'hdr' 'flag' and 'link' contain everything needed to build 'target' makefile: The (auto) makefile to generate. """ f = open(makefile, 'w') f.write('\nCFLAGS = $(DEFAULT_CFLAGS) $(ENV_CFLAGS)\n') f.write('\nCCFLAGS = $(DEFAULT_CCFLAGS) $(ENV_CCFLAGS)\n') index = 0 for item in specs: index += 1 target = item['_target'] target_bin = FileUtils.GetBinPathForFile(target) target_name = os.path.basename(target) target_dep_dir = target_bin + '_deps' f.write('\n# Dep dir for %s\n' % target) f.write('CC_TARGET_DEP_DIR_%d = %s\n' % (index, target_dep_dir)) f.write('\n# Flags for %s\n' % target) f.write('CFLAGS_%d = %s\n' % (index, str.join(' ', item.get('flag', set())))) f.write('\n# Srcs for %s\n' % target) f.write('CC_SRC_%d = %s\n' % (index, str.join('\\\n ', item.get('src', set())))) f.write('\nCC_SRC_C_%d = $(filter %%.c,$(CC_SRC_%d))\n' % (index, index)) f.write('CC_SRC_CC_%d = $(filter %%.cc,$(CC_SRC_%d))\n' % (index, index)) f.write('CC_SRC_CPP_%d = $(filter %%.cpp,$(CC_SRC_%d))\n' % (index, index)) f.write('\n# Hdrs for %s\n' % target) f.write('CC_HDR_%d = %s\n' % (index, str.join('\\\n ', item.get('hdr', set())))) f.write('\n# Libs for %s\n' % target) f.write('CC_LIB_%d = %s\n' % (index, str.join(' ', item.get('link', set())))) f.write('\n# Dependencies for %s\n' % target) f.write('CC_DEPS_FILE_%d = %s\n' % (index, cls.GetDepsFileName(makefile, target, '.auto.cc.'))) f.write('\n# Objs for %s\n' % target) f.write('CC_OBJ_C_%d = $(addprefix $(CC_TARGET_DEP_DIR_%d),$(CC_SRC_C_%d:.c=.o))\n' % (index, index, index)) f.write('CC_OBJ_CC_%d = $(addprefix $(CC_TARGET_DEP_DIR_%d),$(CC_SRC_CC_%d:.cc=.o))\n' % (index, index, index)) f.write('CC_OBJ_CPP_%d = $(addprefix $(CC_TARGET_DEP_DIR_%d),$(CC_SRC_CPP_%d:' '.cpp=.o))\n' % (index, index, index)) f.write('\n$(CC_OBJ_C_%d) : $(CC_TARGET_DEP_DIR_%d)%%.o: %%.c\n' % (index, index)) f.write('\t@mkdir -p $(dir $@)\n') f.write('\t$(C) $(CFLAGS_%d) $(CFLAGS) -o $@ -c $<\n' % index) f.write('\n$(CC_OBJ_CC_%d) : $(CC_TARGET_DEP_DIR_%d)%%.o: %%.cc\n' % (index, index)) f.write('\t@mkdir -p $(dir $@)\n') f.write('\t$(CC) $(CFLAGS_%d) $(CCFLAGS) -o $@ -c $<\n' % index) f.write('\n$(CC_OBJ_CPP_%d) : $(CC_TARGET_DEP_DIR_%d)%%.o: %%.cpp\n' % (index, index)) f.write('\t@mkdir -p $(dir $@)\n') f.write('\t$(CC) $(CFLAGS_%d) $(CCFLAGS) -o $@ -c $<\n' % index) # Write the target. f.write('\n%s : $(CC_OBJ_C_%d) $(CC_OBJ_CC_%d) $(CC_OBJ_CPP_%d) $(CC_HDR_%d)\n' % (target, index, index, index, index)) type = item.get('_type', 'invalid') if type == 'cc_bin' or type == 'cc_test': flags = '$(CFLAGS)' if item.get('bin_type', 'cc') == 'c' else '$(CCFLAGS)' f.write('\t@echo "Linking %s "\n' % target) f.write('\t@mkdir -p $(BINDIR)\n') f.write('\t$(CC) $(CFLAGS_%d) %s -o %s ' '$(filter %%.o, $^) $(DEFAULT_LIBS) $(CC_LIB_%d)\n' % (index, flags, target_bin, index)) f.write('\t@ln -s -f %s $(BINDIR)/$(notdir $@)\n' % target_bin) pack = item.get('pack', 0) if pack == 1: f.write('\t@echo -n "Packing "\n' '\t$(SRCROOT)/public/bin/codebase/package %s\n' % target_bin) elif pack == 2: record_access_file = os.path.join(target_dep_dir, target_name + '.files') f.write('\t@echo -n "Packing "\n') f.write('\t%s --r77_run_main=false --record_file_access ' '--record_file_access_output=%s\n' % (target_bin, record_access_file)) f.write('\t$(SRCROOT)/public/bin/codebase/package %s $(shell cat %s)\n' % (target_bin, record_access_file)) f.write('\t@echo "Created: %s"\n' % target_bin) elif type == 'cc_shared': target_lib_name = '_%s.so' % target_name target_lib = target_bin.replace(target_name, target_lib_name) flags = '$(CFLAGS)' if item.get('bin_type', 'cc') == 'c' else '$(CCFLAGS)' f.write('\t@echo "Linking %s "\n' % target) f.write('\t@mkdir -p $(BINDIR)\n') f.write('\t$(CC) $(CFLAGS_%d) -shared %s -o %s ' '$(filter %%.o, $^) $(DEFAULT_LIBS) $(CC_LIB_%d)\n' % (index, flags, target_lib, index)) f.write('\t@echo "Finished: $@"\n\n') # makedepend rule f.write('%s:\n' '\t@echo "Building dependency files..."\n' '\t@makedepend -p$(CC_TARGET_DEP_DIR_%d) -f$(CC_DEPS_FILE_%d) ' '$(MAKEDEPEND_ARGS) -- $(CFLAGS_%d) -- $(CC_SRC_%d) $(CC_HDR_%d)' % (cls.GetDepsRuleName(target), index, index, index, index, index)) f.write('\n\n') f.close()
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, hdr, flag, link, pack}. In each dict, 'src', 'hdr' 'flag' and 'link' contain 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) target_dep_dir = target_bin + '_deps' f.write('\n# Dep dir for %s\n' % target) f.write('PY_TARGET_DEP_DIR_%d = %s\n' % (index, target_dep_dir)) f.write('\n# Srcs for %s\n' % target) main = str.join('\\\n ', item.get('main', set())) srcs = str.join('\\\n ', item.get('src', set())) f.write('PY_SRC_%d = %s\n' % (index, str.join('\\\n ', [main, srcs]))) # Write the target. f.write('\n%s' % target) f.write(': $(PY_SRC_%d)\n' % (index)) type = item.get('_type', 'invalid') if type == 'py_bin' or type == 'py_test': f.write('\t@echo "Creating Executable for %s "\n' % target) f.write('\t@mkdir -p $(PY_TARGET_DEP_DIR_%d)\n' % index) if type == 'py_bin': prebuild_commands = item.get('prebuild', []) for prebuild_command in prebuild_commands: f.write( '\t@echo "Running prebuild script %s for %s "\n' % (prebuild_command, target)) f.write('\t@%s\n' % prebuild_command) f.write('\t@pushd $(PY_TARGET_DEP_DIR_%d);' % index) f.write( '\tR77_SRC_ROOT=$(SRCROOT) $(PY) %s --onefile ' '--paths $(PYTHON_PATHS) ' '--out $(PY_TARGET_DEP_DIR_%d) --name=$(notdir $@) ' '--additional-hooks-dir=$(SRCROOT)/pylib/pyinstaller/hooks ' '$(PY_SRC_%d);' % (cls.GetPyInstaller(), index, index)) f.write('\tpopd \n') f.write( '\t@cp $(PY_TARGET_DEP_DIR_%d)/dist/$(notdir $@) %s\n' % (index, target_bin)) if item.get('pack', 0) == 1: f.write('\t@echo -n "Packing "\n' '\t$(SRCROOT)/scripts/package %s\n' % target_bin) elif type == 'py_test': f.write('\t@echo "# Python Test for %s" > %s\n' % (target, target_bin)) f.write( '\t@echo "export PYTHONPATH=$(PYTHON_PATHS)" >> %s\n' % target_bin) f.write('\t@echo \'python %s $$@\' >> %s\n' % (main, 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@echo "Created: %s"\n' % target_bin) f.write('\t@echo "Finished: $@"\n\n') f.write('\n\n') f.close()