def setup_args(self): """Setup args.""" # Add custom args if any. if self.target_args: self.args += ' %s' % self.target_args # --disable-gl-drawing-for-tests does not draw gl content on screen. # When running in regular mode, user would want to see screen, so # remove this argument. if (self.disable_xvfb and DISABLE_GL_DRAW_ARG in self.args): self.args = self.args.replace(' %s' % DISABLE_GL_DRAW_ARG, '') self.args = self.args.replace(DISABLE_GL_DRAW_ARG, '') # Replace build directory environment variable. self.args = self.args.replace('%APP_DIR%', self.build_directory) # Use %TESTCASE% argument if available. Otherwise append testcase path. if '%TESTCASE%' in self.args: self.args = self.args.replace('%TESTCASE%', self.testcase_path) else: self.args += ' %s' % self.testcase_path if self.edit_mode: self.args = editor.edit( self.args, prefix='edit-args-', comment='Edit arguments before running %s' % self.binary_path)
def edit_if_needed(content, should_edit): """Edit content in an editor if should_edit is true.""" if not should_edit: return content return editor.edit(content, prefix='edit-args-gn-', comment='Edit args.gn before building.')
def test_edit(self): """Test edit.""" self.saved_filepath = '' def modify_file(cmd): _, self.saved_filepath = cmd.split(' ') with open(self.saved_filepath, 'a') as f: f.write('\nAdded content') self.mock.system.side_effect = modify_file self.mock.get_full_path.return_value = 'test-binary' self.assertEqual( 'Test\nAdded content', editor.edit('Test', comment='comment')) self.mock.system.assert_called_once_with( 'test-binary %s' % self.saved_filepath) self.mock.get_full_path.assert_called_once_with('vi')
def setup_gn_args(self): """Ensures that args.gn is set up properly.""" # Remove existing gn file from build directory. args_gn_path = os.path.join(self.build_directory, 'args.gn') if os.path.isfile(args_gn_path): os.remove(args_gn_path) # Create build directory if it does not already exist. if not os.path.exists(self.build_directory): os.makedirs(self.build_directory) # If no args.gn file is found, get it from downloaded build. if self.gn_args: gn_args = self.gn_args else: args_gn_downloaded_build_path = os.path.join( self.build_dir_name(), 'args.gn') with open(args_gn_downloaded_build_path, 'r') as f: gn_args = f.read() # Add additional options to existing gn args. args_hash = self.deserialize_gn_args(gn_args) args_hash = self.setup_gn_goma_params(args_hash) if self.gn_args_options: for k, v in self.gn_args_options.iteritems(): args_hash[k] = v # Let users edit the current args. content = self.serialize_gn_args(args_hash) if self.edit_mode: content = editor.edit( content, prefix='edit-args-gn-', comment='Edit args.gn before building.') # Write args to file and store. with open(args_gn_path, 'w') as f: f.write(content) self.gn_args = content common.execute('gn', 'gen %s %s' % (self.gn_flags, self.build_directory), self.source_directory)
def edit_if_needed(content, prefix, comment, should_edit): """Edit content in an editor if should_edit is true.""" if not should_edit: return content return editor.edit(content, prefix=prefix, comment=comment)