/**
  * Create a tree of self-sustainable files and return the topmost LESS file, ready for passing to 3rd party library
  *
  * @param Chain $chain
  * @return string Absolute path of generated LESS file
  */
 public function generateFileTree(Chain $chain)
 {
     /**
      * @bug This logic is duplicated at \Magento\Framework\View\Asset\PreProcessor\Pool
      * If you need to extend or modify behavior of LESS preprocessing, you must account for both places
      */
     /**
      * wait if generation process has already started
      */
     while ($this->isProcessLocked()) {
         sleep(1);
     }
     $lockFilePath = $this->config->getLessMaterializationRelativePath() . '/' . self::LOCK_FILE;
     $this->tmpDirectory->writeFile($lockFilePath, time());
     $this->magentoImportProcessor->process($chain);
     $this->importProcessor->process($chain);
     $this->relatedGenerator->generate($this->importProcessor);
     $lessRelativePath = preg_replace('#\\.css$#', '.less', $chain->getAsset()->getPath());
     $tmpFilePath = $this->temporaryFile->createFile($lessRelativePath, $chain->getContent());
     $this->tmpDirectory->delete($lockFilePath);
     return $tmpFilePath;
 }
 /**
  * Create file, referenced relatively to an asset
  *
  * @param string $relatedFileId
  * @param LocalInterface $asset
  * @return \Magento\Framework\View\Asset\File
  */
 protected function generateRelatedFile($relatedFileId, LocalInterface $asset)
 {
     $relatedAsset = $this->assetRepo->createRelated($relatedFileId, $asset);
     $this->temporaryFile->createFile($relatedAsset->getPath(), $relatedAsset->getContent());
     return $relatedAsset;
 }