Tuesday, February 19. 2013Technical Reference – Intel® HTML5 App Porter Tool - BETAVia Intel Software -----
IntroductionThe Intel® HTML5 App Porter Tool - BETA is an application that helps mobile application developers to port native iOS* code into HTML5, by automatically translating portions of the original code into HTML5. This tool is not a complete solution to automatically port 100% of iOS* applications, but instead it speeds up the porting process by translating as much code and artifacts as possible. It helps in the translation of the following artifacts:
This document provides a high-level explanation about how the tool works and some details about supported features. This overview will help you determine how to process the different parts of your project and take the best advantage from the current capabilities. How does it work?The Intel® HTML5 App Porter Tool - BETA is essentially a source-to-source translator that can handle a number of conversions from Objective-C* into JavaScript/HTML5 including the translation of APIs calls. A number of open source projects are used as foundation for the conversion including a modified version of Clang front-end, LayerD framework and jQuery Mobile for widgets rendering in the translated source code. Translation of Objective-C into JavaScriptAt a high level, the transformation pipeline looks like this: This pipeline follows the following stages:
About coverage of API mappingsMapping APIs from iOS* SDK into JavaScript is a task that involves a good deal of effort. The iOS* APIs have thousands of methods and hundreds of types. Fortunately, a rather small amount of those APIs are in fact heavily used by most applications. The graph below conceptually shows how many APIs need to be mapped in order to have certain level of translation for API calls . Currently, the Intel® HTML5 App Porter Tool - BETA supports the most used types and methods from:
Additionally, it supports a few classes of other frameworks such as CoreGraphics. For further information on supported APIs refer to the list of supported APIs. Generation of placeholder definitions and TODO JavaScript filesFor the APIs that the Intel® HTML5 App Porter Tool - BETA cannot translate, the tool generates placeholder functions in "TODO" files. In the translated application, you will find one TODO file for each type that is used in the original application and which has API methods not supported by the current version. For example, in the following portion of code:
If property setter for
These placeholders are created for methods, constants, and types that the tool does not support. Additionally, these placeholders may be generated for APIs other than the iOS* SDK APIs. If some files from the original application (containing class or function definitions) are not included in the translation process, the tool may also generate placeholders for the definitions in those missing files. In each TODO file, you will find details about where those types, methods, or constants are used in the original code. Moreover, for each function or method the TODO file includes information about the type of the arguments that were inferred by the tool. Using these TODO files, you can complete the translation process by the providing the placeholders with your own implementation for that API. Translation of XIB files into HTML/CSS codeThe Intel® HTML5 App Porter Tool - BETA translates most of the definitions in the Xcode* Interface Builder files (i.e.,
XIB files) into equivalent HTML/CSS code. These HTML files use JQuery*
markup to define layouts equivalent to the views in the original XIB
files. That markup is defined based on the translated version of the
view classes and can be accessed programmatically. The figure below shows how the different components of each XIB file are translated. This is a summary of the artifacts generated from XIB files:
For further information on supported widgets and properties refer to the Supported .XIB file featuressection. Architecture of translated applicationsThe translated application keeps the very same high level structure as the original one. Constructs such as Objective-C* interfaces, categories, C structs, functions, variables, and statements are kept without significant changes in the translated code but expressed in JavaScript. The execution of the Intel® HTML5 App Porter Tool – BETA produces a set of files that can be divided in four groups:
The generated JavaScript files have names which are practically the
same as the original ones. For example, if you have a file called In short, the high level structure of the translated application is practically the same as the original one. Therefore, the design and structure of the original application will remain the same in the translated version. About target HTML5 APIs and librariesThe Intel® HTML5 App Porter Tool - BETA both translates the syntax and semantics of the source language (Objective-C*) into JavaScript and maps the iOS* SDK API calls into an equivalent functionality in HTML5. In order to map iOS* API types and calls into HTML5, we use the following libraries and APIs:
You should expect that future versions of the tool will incrementally add more support for API mapping, based on further statistical analysis and user feedback. Translated identifier namesIn Objective-C*, methods names can be composed by several parts
separated with colons (:) and the methods calls interleaved these parts
with the actual arguments. Since that peculiar syntactic construct is
not available in JavaScript, those methods names are translated by
combining all the methods parts replacing the colons (:) with
underscores (_). For example, a function called Identifier names, in general, may also be changed in the translation if there are any conflicts in JavaScript scope. For example, if you have duplicated names for interfaces and protocol, or one instance method and one class method that share the same name in the same interface. Because identifier scoping rules are different in JavaScript, you cannot share names between fields, methods, and interfaces. In any of those cases, the tool renames one of the clashing identifiers by prepending an underscore (_) to the original name. Additional tips to get the most out of the Intel® HTML5 App Porter Tool – BETAHere is a list of recommendations to make the most of the tool.
In conclusion, having a well-designed application in the first place will make your life a lot easier when porting your code, even in a completely manual process. Further technical informationThis section provides additional information for developers and it is not required to effectively use Intel® HTML5 App Porter Tool - BETA. You can skip this section if you are not interested in implementation details of the tool. Implementation of the translation stepsHere, you can find some high level details of how the different processing steps of the Intel® HTML5 App Porter Tool - BETA are implemented. Objective-C* and C files parsingTo parse Objective-C* files, the tool uses a modified version of clang parser. A custom version of the parser is needed because:
The following picture shows the actual detailed process for parsing .m and .c files: Missing iOS* SDK headers are inferred as part of the parsing process. The header inference process is heuristic, so you may get parsing errors, in some cases. Thus, you can help the front-end of the tool by providing forward declaration of types or other definitions in header files that are accessible to the tool. Also, you can try the "Header Generator" module in individual files
by using the command line. In the binary folder of the tool, you will
find an executable Objective-C* language transformation into JavaScriptThe translation of Objective-C* language into JavaScript involves a number of steps. We can divide the process in what happens in the front-end and what is in the back-end. Steps in the front-end:
The output of the front-end is a Zoe program. Zoe is an intermediate abstract language used by LayerD framework; the engine that is used to apply most of the transformations. The back-end is fully implemented in LayerD by using compile time classes of Zoe language that apply a number of transformations in the AST. Steps in the back-end:
iOS* API mapping into JavaScript/HTML5The tool supports a limited subset of iOS* API. That subset is developed following statistical information about usage of each API. Each release of the tool will include support for more APIs. If you miss a particular kind of API your feedback about it will be very valuable in our assessment of API support. For some APIs such as Arrays and Strings the tool provides direct mappings into native HTML5 objects and methods. The following table shows a summary of the approach followed for each kind of currently supported APIs.
Direct mapping implies that the original code will be transformed into plain JavaScript without any type of additional layer. For example,
The entire API mapping happens in the back-end of the tool. This process is implemented using compile time classes and other infrastructure provided by the LayerD framework. XIB files conversion into HTML/CSSXIB files are converted in two steps:
The first step generates one XML file - with extension .gld - for each view inside the XIB file and one additional XML file with information about other objects inside XIB files and connections between objects and views such as outlets and event handling. The second stage runs inside the Zoe compiler of LayerD to convert intermediate XML files into final HTML/CSS and JavaScript boilerplate code to duplicate all the functionality that XIB files provides in the original project. Generated HTML code is as similar as possible to static markup used by jQuery Mobile library or standard HTML5 markup. For widgets that do not have an equivalent in jQuery Mobile, HTML5, or behaves differently, simple markup is generated and handled by classes in APT library. Supported iOS SDK APIs for Translation
The following table details the APIs supported by the current version of the tool. Notes:
Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
No comments
The author does not allow comments to this entry
|
QuicksearchPopular Entries
CategoriesShow tagged entriesSyndicate This BlogCalendar
Blog Administration |