WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/24/2018 01:28:22 PM (15 months ago)
Author:
atimmer
Message:

Build tools: Allow building WordPress to src.

After the JavaScript reorganization in [43309], it was no longer possible to test WordPress from the src folder. That meant a build step was required to test PHP modifications. That is suboptimal as even a simple copy is slower than a web server just serving the new file.

We achieve building to src by setting a WORKING_DIR constant in the Gruntfile that is build by default, but changes to src when the --dev flag is present on any Grunt command. We provide sensible defaults so some commands, such as copying version.php, always build to build.

Because testing from build is no longer required, we change the messages present in index.php and wp-admin/index.php to be more broadly about building WordPress.

We also change the webpack config to have more straightforward behavior based on the buildTarget argument. It only determines the build target now and has no implicit behavior anymore. grunt build still works as it worked before, to make sure that the build server produces the same wordpress.zip we are used to.

We do all this instead of a symlink setup because symlinks don't work on every platform.

Props omarreiss, netweb, flixos90, SergeyBiryukov.
Fixes #44492.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-parser.php

    r44281 r44359  
    6464
    6565    function __construct( $name, $attrs, $innerBlocks, $innerHTML, $innerContent ) {
    66         $this->blockName    = $name;
    67         $this->attrs        = $attrs;
    68         $this->innerBlocks  = $innerBlocks;
    69         $this->innerHTML    = $innerHTML;
     66        $this->blockName   = $name;
     67        $this->attrs       = $attrs;
     68        $this->innerBlocks = $innerBlocks;
     69        $this->innerHTML   = $innerHTML;
    7070        $this->innerContent = $innerContent;
    7171    }
     
    270270                if ( 0 === $stack_depth ) {
    271271                    if ( isset( $leading_html_start ) ) {
    272                         $this->output[] = (array) self::freeform(
    273                             substr(
    274                                 $this->document,
    275                                 $leading_html_start,
    276                                 $start_offset - $leading_html_start
    277                             )
    278                         );
     272                        $this->output[] = (array) self::freeform( substr(
     273                            $this->document,
     274                            $leading_html_start,
     275                            $start_offset - $leading_html_start
     276                        ) );
    279277                    }
    280278
    281279                    $this->output[] = (array) new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() );
    282                     $this->offset   = $start_offset + $token_length;
     280                    $this->offset = $start_offset + $token_length;
    283281                    return true;
    284282                }
     
    295293            case 'block-opener':
    296294                // track all newly-opened blocks on the stack
    297                 array_push(
    298                     $this->stack,
    299                     new WP_Block_Parser_Frame(
    300                         new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ),
    301                         $start_offset,
    302                         $token_length,
    303                         $start_offset + $token_length,
    304                         $leading_html_start
    305                     )
    306                 );
     295                array_push( $this->stack, new WP_Block_Parser_Frame(
     296                    new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ),
     297                    $start_offset,
     298                    $token_length,
     299                    $start_offset + $token_length,
     300                    $leading_html_start
     301                ) );
    307302                $this->offset = $start_offset + $token_length;
    308303                return true;
     
    335330                 * block and add it as a new innerBlock to the parent
    336331                 */
    337                 $stack_top                        = array_pop( $this->stack );
    338                 $html                             = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
    339                 $stack_top->block->innerHTML     .= $html;
     332                $stack_top = array_pop( $this->stack );
     333                $html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
     334                $stack_top->block->innerHTML .= $html;
    340335                $stack_top->block->innerContent[] = $html;
    341                 $stack_top->prev_offset           = $start_offset + $token_length;
     336                $stack_top->prev_offset = $start_offset + $token_length;
    342337
    343338                $this->add_inner_block(
     
    397392        }
    398393
    399         list( $match, $started_at ) = $matches[0];
     394        list( $match, $started_at ) = $matches[ 0 ];
    400395
    401396        $length    = strlen( $match );
    402         $is_closer = isset( $matches['closer'] ) && -1 !== $matches['closer'][1];
    403         $is_void   = isset( $matches['void'] ) && -1 !== $matches['void'][1];
    404         $namespace = $matches['namespace'];
    405         $namespace = ( isset( $namespace ) && -1 !== $namespace[1] ) ? $namespace[0] : 'core/';
    406         $name      = $namespace . $matches['name'][0];
    407         $has_attrs = isset( $matches['attrs'] ) && -1 !== $matches['attrs'][1];
     397        $is_closer = isset( $matches[ 'closer' ] ) && -1 !== $matches[ 'closer' ][ 1 ];
     398        $is_void   = isset( $matches[ 'void' ] ) && -1 !== $matches[ 'void' ][ 1 ];
     399        $namespace = $matches[ 'namespace' ];
     400        $namespace = ( isset( $namespace ) && -1 !== $namespace[ 1 ] ) ? $namespace[ 0 ] : 'core/';
     401        $name      = $namespace . $matches[ 'name' ][ 0 ];
     402        $has_attrs = isset( $matches[ 'attrs' ] ) && -1 !== $matches[ 'attrs' ][ 1 ];
    408403
    409404        /*
     
    412407         */
    413408        $attrs = $has_attrs
    414             ? json_decode( $matches['attrs'][0], /* as-associative */ true )
     409            ? json_decode( $matches[ 'attrs' ][ 0 ], /* as-associative */ true )
    415410            : $this->empty_attrs;
    416411
     
    477472     */
    478473    function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) {
    479         $parent                       = $this->stack[ count( $this->stack ) - 1 ];
     474        $parent = $this->stack[ count( $this->stack ) - 1 ];
    480475        $parent->block->innerBlocks[] = (array) $block;
    481         $html                         = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );
     476        $html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );
    482477
    483478        if ( ! empty( $html ) ) {
    484             $parent->block->innerHTML     .= $html;
     479            $parent->block->innerHTML .= $html;
    485480            $parent->block->innerContent[] = $html;
    486481        }
    487482
    488483        $parent->block->innerContent[] = null;
    489         $parent->prev_offset           = $last_offset ? $last_offset : $token_start + $token_length;
     484        $parent->prev_offset = $last_offset ? $last_offset : $token_start + $token_length;
    490485    }
    491486
     
    506501
    507502        if ( ! empty( $html ) ) {
    508             $stack_top->block->innerHTML     .= $html;
     503            $stack_top->block->innerHTML .= $html;
    509504            $stack_top->block->innerContent[] = $html;
    510505        }
    511506
    512507        if ( isset( $stack_top->leading_html_start ) ) {
    513             $this->output[] = (array) self::freeform(
    514                 substr(
    515                     $this->document,
    516                     $stack_top->leading_html_start,
    517                     $stack_top->token_start - $stack_top->leading_html_start
    518                 )
    519             );
     508            $this->output[] = (array) self::freeform( substr(
     509                $this->document,
     510                $stack_top->leading_html_start,
     511                $stack_top->token_start - $stack_top->leading_html_start
     512            ) );
    520513        }
    521514
Note: See TracChangeset for help on using the changeset viewer.